Data Structures & Algorithms · Revision notes
Linked Lists
A linked list stores nodes connected by pointers; it gives O(1) insertion/deletion given a node reference but O(n) access. Pointer manipulation (reversal, fast-slow pointers, dummy nodes) is the core skill.
Quick revision
- Singly: insert head O(1), tail O(n) (O(1) with tail ptr), delete tail O(n)
- Doubly: O(1) delete given node; powers LRU (hashmap + doubly list)
- Reverse: nxt=cur.next; cur.next=prev; move prev/cur; O(n) O(1)
- Floyd: speeds 1,2; meet in cycle; reset to head to find entry; L = kC - x
- Use dummy node, compare identity, check None before .next