Linked List
A linked list stores values in nodes. Each node keeps the value plus a reference to the next node, so the elements do not need to live next to each other in memory.
이 멘탈 모델부터 시작하세요
A linked list stores values in nodes. Each node keeps the value plus a reference to the next node, so the elements do not need to live next to each other in memory.
불필요한 전문용어 없이 동작 방식 이해하기
The list starts at a head node. To reach an item, you follow next references one by one.
Insertion at the front is cheap because only a few references change. Random access is expensive because there is no direct index lookup.
알고리즘을 연속된 의사결정으로 읽기
Keep a head reference.
Traverse with current = current.next.
For insertion/deletion, reconnect the surrounding next references carefully.
For 10 → 20 → 30, inserting 15 after 10 only changes the links around 10 and 15.
class Node {
constructor(value, next = null) {
this.value = value;
this.next = next;
}
}
class LinkedList {
head = null;
prepend(value) {
this.head = new Node(value, this.head);
}
}문법을 외우지 마세요. 각 줄에서 바뀌는 상태를 따라가고 위에서 설명한 불변식과 연결하세요.
access O(n), head insert O(1)
Do not quote this complexity mechanically. Ask which operation or input dimension it describes, then derive the cost from the loops, recursion depth, data-structure operations and any preprocessing assumptions.
적합한 경우
- Choose it when its dominant operations match your workload.
- Compare memory overhead as well as Big-O.
보통 어디에서 문제가 생기는가
- Memorizing complexity without understanding representation.
- Ignoring worst-case shape or resizing/rebalancing costs.
전문적인 답변 구조
Contrast it with arrays: linked lists give flexible local insertion/deletion, but lose O(1) index access and usually have worse cache locality.
What problem does Linked List solve?
A linked list stores values in nodes. Each node keeps the value plus a reference to the next node, so the elements do not need to live next to each other in memory.
복잡도에 대해 무엇을 언급해야 하나요?
Its typical cost here is access O(n), head insert O(1), but a complete answer should connect that cost to the representation, input constraints and the dominant operations.
가장 흔한 실수는 무엇인가요?
Memorizing complexity without understanding representation.