Skip to content

Commit 60e905e

Browse files
author
이준헌
authored
Add contents in Korean (#132)
1 parent db8dcbb commit 60e905e

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 단일 연결 리스트
2+
3+
단일 연결 리스트는 선형으로 연결된 데이터 구조로, 노드로 구성되어 있다. 각 노드는 내용이 저장된 `data` 변수와 다음 노드를 가리키는 `pointer`로 구성되어 있다. 연결 리스트는 이런 노드들의 첫 원소를 가리키는 포인터를 가지며, 연산에 걸리는 시간을 훨씬 절약하기 위해 마지막 노드를 가리키는 포인터를 가질 수도 있다. 전체 노드 수를 저장하는 `length` 변수를 추가할 수도 있다.
4+
5+
### 배열보다 우수한 점
6+
7+
- 연결 리스트의 크기는 고정되어 있지 않다. (가변 크기)
8+
- 배열에 비해 원소의 제거와 추가가 쉽다.
9+
10+
### 단점
11+
12+
- 원소에 순차적으로 접근해야 한다. (임의 접근 불가)
13+
- 포인터를 저장하기 위해 추가적인 메모리가 필요하다.
14+
15+
### 시간 복잡도
16+
17+
| 작업 | 평균 | 최악 |
18+
| ---- | ------ | ------ |
19+
| 접근 | $O(n)$ | $O(n)$ |
20+
| 탐색 | $O(n)$ | $O(n)$ |
21+
| 삽입 | $O(1)$ | $O(1)$ |
22+
| 제거 | $O(1)$ | $O(1)$ |
23+
24+
## 예시
25+
26+
```java
27+
class LinkedList {
28+
Node head; // Pointer to the first element
29+
Node tail; // Optional. Points to the last element
30+
31+
int length; // Optional
32+
33+
class Node {
34+
int data; // Node data. Can be int, string, float, templates, etc
35+
Node next; // Pointer to the next node on the list
36+
}
37+
}
38+
```
39+
40+
## 구현
41+
42+
- [Java](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Lists/SinglyLinkedList.java)
43+
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Linked%20List.cpp)
44+
- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/singly_linked_list.py)
45+
- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/single_list.rb)
46+
47+
## 영상 URL
48+
49+
- [CS50](https://www.youtube.com/watch?v=5nsKtQuT6E8)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# 이중 연결 리스트
2+
3+
단일 연결 리스트는 선형으로 연결된 데이터 구조로, 노드로 구성되어 있다. 각 노드는 내용이 저장된 `data` 변수와 다음 노드를 가리키는 `pointer`로 구성되어 있다. 연결 리스트는 이런 노드들의 첫 원소를 가리키는 포인터를 가지며, 연산에 걸리는 시간을 훨씬 절약하기 위해 마지막 노드를 가리키는 포인터를 가질 수도 있다. 전체 노드 수를 저장하는 `length` 변수를 추가할 수도 있다.
4+
5+
**이중 연결 리스트 (DLL)** 는 여기에 더해 이전 노드를 가리키는 `previous pointer`라는 추가적인 포인터도 가진다.
6+
7+
### 단일 연결 리스트보다 우수한 점
8+
9+
- 정방향과 역방향 순회가 가능하다.
10+
- 제거될 노드를 가리키는 포인터가 알려져 있다면, 원소의 제거가 더 효율적이다.
11+
- 특정 노드 앞에 새로운 노드를 빠르게 삽입할 수 있다.
12+
- 단일 연결 리스트에서 노드를 제거하려면 이전 노드의 `pointer`를 알아야 한다. 어쩌면 이 노드를 찾기 위해 리스트를 전부 순회해야 할 수도 있다. 그러나 DLL에서는 `previous pointer`를 이용하여 이전 노드를 찾을 수 있다.
13+
14+
### 단점
15+
16+
- 포인터를 저장하기 위한 메모리가 단일 연결 리스트보다 더 많이 필요하다. 그러나 포인터 하나로 DLL을 구현할 수도 있다.
17+
- 모든 작업에 추가적인 연산이 필요하다. 예를 들어, 삽입 시 `pointer``previous pointer`를 모두 수정해야 한다.
18+
19+
### 시간 복잡도
20+
21+
| 작업 | 평균 | 최악 |
22+
| ---- | ------ | ------ |
23+
| 접근 | $Θ(n)$ | $O(n)$ |
24+
| 탐색 | $Θ(n)$ | $O(n)$ |
25+
| 삽입 | $Θ(1)$ | $O(1)$ |
26+
| 제거 | $Θ(1)$ | $O(1)$ |
27+
28+
## 예시
29+
30+
```java
31+
class LinkedList {
32+
33+
Node head; // Pointer to the first element
34+
Node tail; // Optional. Points to the last element
35+
36+
int length; // Optional
37+
38+
class Node {
39+
int data; // Node data. Can be int, string, float, templates, etc
40+
Node next; // Pointer to the next node on the list
41+
Node prev;
42+
43+
Node(int data) {
44+
this.data = data;
45+
}
46+
}
47+
```
48+
49+
- 맨 앞에 노드 추가하기
50+
![Tracing of algorithm](https://www.geeksforgeeks.org/wp-content/uploads/gq/2014/03/DLL_add_front1.png)
51+
52+
```java
53+
public void push(int new_data) {
54+
55+
/* 1. allocate node
56+
2. put in the data */
57+
Node new_Node = new Node(new_data);
58+
59+
/* 3. Make next of new node as head and previous as NULL */
60+
new_Node.next = head;
61+
new_Node.prev = null;
62+
63+
/* 4. change prev of head node to new node */
64+
if (head != null)
65+
head.prev = new_Node;
66+
67+
/* 5. move the head to point to the new node */
68+
head = new_Node;
69+
}
70+
```
71+
72+
- 주어진 노드 뒤에 노드 추가하기
73+
![Tracing of algorithm](https://www.geeksforgeeks.org/wp-content/uploads/gq/2014/03/DLL_add_middle1.png)
74+
75+
```java
76+
public void InsertAfter(Node prev_Node, int new_data) {
77+
78+
/*1. check if the given prev_node is NULL */
79+
if (prev_Node == null) {
80+
System.out.println("The given previous node cannot be NULL ");
81+
return;
82+
}
83+
84+
/* 2. allocate node
85+
3. put in the data */
86+
Node new_node = new Node(new_data);
87+
88+
/* 4. Make next of new node as next of prev_node */
89+
new_node.next = prev_Node.next;
90+
91+
/* 5. Make the next of prev_node as new_node */
92+
prev_Node.next = new_node;
93+
94+
/* 6. Make prev_node as previous of new_node */
95+
new_node.prev = prev_Node;
96+
97+
/* 7. Change previous of new_node's next node */
98+
if (new_node.next != null)
99+
new_node.next.prev = new_node;
100+
}
101+
}
102+
```
103+
104+
## 구현
105+
106+
- [Java](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Lists/DoublyLinkedList.java)
107+
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Doubly%20Linked%20List.cpp)
108+
- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/doubly_linked_list.py)
109+
- [Go](https://github.com/TheAlgorithms/Go/blob/master/data-structures/linked-list/double-linkedlist.go)
110+
- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/double_list.rb)
111+
112+
## 영상 URL
113+
114+
- [CS50](https://www.youtube.com/watch?v=FHMPswJDCvU)

0 commit comments

Comments
 (0)