방문할 맛집을 지도 위에 순서대로 연결한 것처럼, 서로 떨어진 곳에 위치한 데이터를 화살표로 연결해 순서를 표현하는 방식이 단순 연결 리스트입니다.
첫 번째 쪽지를 찾으면 "다음 힌트는 나무 아래"라고 적혀 있고, 그 쪽지를 찾으면 또 다음 위치를 알려줍니다. 위치는 흩어져 있지만 순서대로 따라갈 수 있습니다.
각 역은 실제로 서로 다른 곳에 떨어져 있지만, "다음 역"이라는 연결 정보를 따라가면 순서대로 이동할 수 있습니다.
서로 다른 서버에 저장된 웹 페이지들이 링크로 연결되어 있어, 클릭을 따라가면 순서대로 다음 페이지로 이동합니다.
데이터가 물리적으로 어디에 있는지는 중요하지 않습니다. 화살표(링크)만 따라가면 항상 정해진 순서대로 데이터를 찾을 수 있습니다.
Just like connecting restaurants on a map in the order you plan to visit them, a simple linked list connects scattered data with arrows to express order.
The first note says "the next hint is under the tree." Finding that note reveals the next location. The spots are scattered, but you can follow them in order.
Each station is physically located in a different place, but following the "next station" connection lets you move through them in order.
Web pages stored on different servers are connected by links — clicking through them takes you to the next page in sequence.
It doesn't matter where the data is physically located. Following the arrows (links) always lets you find data in the correct order.
선형 리스트는 중간에 데이터를 삽입하거나 삭제할 때 많은 데이터를 이동시켜야 하는 오버헤드가 발생합니다. 단순 연결 리스트는 해당 노드의 앞뒤 링크만 수정하면 됩니다.
| 구분 | 선형 리스트 | 단순 연결 리스트 |
|---|---|---|
| 삽입/삭제 | 많은 데이터 이동 필요 | 링크만 수정 |
| 메모리 사용 | 데이터만 저장 | 데이터 + 링크 저장 |
| 검색 | 인덱스로 즉시 접근 | 처음부터 순차 탐색 |
In a linear list, inserting or deleting data in the middle requires shifting many elements, creating overhead. In a simple linked list, only the neighboring links need to be modified.
| Aspect | Linear List | Linked List |
|---|---|---|
| Insert/Delete | Requires shifting data | Only modify links |
| Memory usage | Data only | Data + link |
| Search | Instant index access | Sequential traversal |
Node 클래스를 정의하고, 노드 5개를 각각 만들어 link 속성으로 순서대로 연결합니다.
Define the Node class, create 5 nodes, and connect them in order using the link attribute.
current.link가 None이 될 때까지 계속 다음 노드로 이동하며 데이터를 출력합니다. 노드가 몇 개든 동일한 코드로 처리할 수 있습니다.
Code04-01은 노드 개수만큼 .link를 반복해서 써야 하지만, while 순회는 노드 개수가 늘어나도 코드를 바꿀 필요가 없습니다.
Keep moving to the next node until current.link becomes None, printing data along the way. The same code works no matter how many nodes exist.
Code04-01 requires chaining .link once per node, but the while traversal needs no code changes even as the list grows.
선형 리스트와 단순 연결 리스트의 차이점을 메모리 구조 관점에서 설명하시오.
노드의 구성 요소(데이터, 링크)가 각각 어떤 역할을 하는지 설명하시오.
Code04-01.py에서 node3을 삭제하려면 어떤 코드를 추가해야 하는지 작성하시오.
Explain the difference between a linear list and a simple linked list from a memory structure perspective.
Explain the role of each node component (data, link).
What code must be added to Code04-01.py to delete node3?
리스트의 첫 노드를 만들 때는 head가 곧 새 노드가 됩니다. 아직 다음 노드가 없으므로 링크는 자동으로 None입니다.
When creating the first node of the list, head becomes the new node itself. Since there's no next node yet, the link is automatically None.
start로 시작 노드(보통 head)를 받습니다.return합니다.start receives the starting node (usually head).current/pre를 이동시켜 삽입 위치를 찾은 후 링크를 연결합니다.
Move current/pre to find the insertion point, then reconnect the links.
findData를 순회하다 끝까지 못 찾으면 current는 마지막 노드가 되고, 여기에 새 노드를 연결합니다: current.link = node
insertNode("재남", "문별") → 화사 다현 정연 쯔위 솔라 사나 지효 문별
If findData is never found while traversing, current ends up being the last node, and the new node is attached there: current.link = node
insertNode("Jaenam", "Moonbyul") → Hwasa Dahyun Jungyeon Tzuyu Solar Sana Jihyo Moonbyul
사용 예: deleteNode("쯔위") → 정연 사나 지효
Usage: deleteNode("Tzuyu") → Jungyeon Sana Jihyo
head부터 순차적으로 탐색하며 데이터를 비교합니다. 찾으면 해당 노드를, 못 찾으면 빈 Node()를 반환합니다.
1. insertNode() 함수에서 첫 번째 / 중간 / 마지막 삽입을 구분하는 조건을 설명하시오.
2. deleteNode()에서 삭제할 데이터가 리스트에 없을 때 어떤 일이 발생하는지 설명하시오.
3. findNode() 함수를 수정하여 찾은 노드의 위치(인덱스)도 함께 반환하도록 하시오.
Traverses sequentially from head, comparing data. Returns the matching node if found, or an empty Node() otherwise.
1. Explain the conditions that distinguish first / middle / last insertion in insertNode().
2. What happens in deleteNode() when the data to delete doesn't exist in the list?
3. Modify findNode() to also return the index position of the found node.
데이터를 입력할 때마다 알파벳(가나다) 순서를 비교하여 알맞은 위치에 자동으로 삽입되도록 만듭니다.
Each time data is entered, compare it alphabetically (or by Korean order) so it's automatically placed at the correct position.
매번 head.data[0] > namePhone[0] 조건으로 맨 앞 삽입 여부를 판단합니다.
정렬 기준은 이름의 첫 글자가 아니라 전체 값 비교이지만, 여기서는 리스트의 [0]번 요소(이름)를 비교합니다.
Each time, the condition head.data[0] > namePhone[0] decides whether to insert at the front.
The sort key is not just the first character but the entire value — here we compare element [0] (the name) of each list entry.
최종 순서: 뷔 → 슈가 → 정국 → 지민 → 진
중간 삽입과 끝 삽입 모두 current, pre를 이동하며 위치를 찾는 동일한 while 루프 구조를 사용합니다.
Final order: V → Suga → Jungkook → Jimin → Jin
Both middle insertion and end insertion use the same while-loop structure that moves current and pre to find the position.
함수 맨 앞에서 printNodes(head)를 호출하므로, 삽입 직전의 리스트 상태가 매번 출력됩니다.
Because printNodes(head) is called at the top of the function, the list state right before each insertion is printed.
사용자가 이름과 이메일을 입력하면, 이메일 주소를 기준으로 정렬된 위치에 자동 삽입합니다.
When the user enters a name and email, the entry is automatically inserted at the correct sorted position by email address.
1~45 사이 숫자 중 중복 없이 6개를 추첨하여 정렬된 연결 리스트로 관리합니다.
Draw 6 unique numbers between 1 and 45 and manage them in a sorted linked list.
| 구분 | 선형 리스트 | 단순 연결 리스트 |
|---|---|---|
| 저장 방식 | 연속 메모리 | 분산 메모리 |
| 삽입/삭제 | O(n) 이동 필요 | O(1) 링크 변경 |
| 검색 | O(1) 인덱스 접근 | O(n) 순차 탐색 |
| 메모리 | 데이터만 | 데이터 + 링크 |
| Aspect | Linear List | Linked List |
|---|---|---|
| Storage | Contiguous memory | Scattered memory |
| Insert/Delete | O(n) shifting required | O(1) link change |
| Search | O(1) index access | O(n) sequential search |
| Memory | Data only | Data + link |
Code04-09.py에서 이름 대신 전화번호 순으로 정렬하려면 어떻게 수정해야 하는가?
Ex04-02.py의 로또 프로그램에서 findNumber() 함수가 없으면 어떤 문제가 발생하는가?
선형 리스트보다 단순 연결 리스트가 유리한 실생활 예를 2가지 이상 제시하시오.
How would you modify Code04-09.py to sort by phone number instead of name?
What problems occur in Ex04-02.py's lotto program without the findNumber() function?
Give at least 2 real-world examples where a linked list is more advantageous than a linear list.