Pointer-based sequences with flexible insertion
A linked list is a pointer-based sequence of nodes where each node holds a value and a reference to the next node (and optionally the previous one for doubly linked lists).
Variants: Singly, doubly, circular, sentinel/dummy-headed.
Operations and complexity:
Great for frequent insertions/deletions without shifting elements.
Use linked lists when you need:
Avoid when you need random access or heavy indexing—arrays perform better.
1. Two Pointers (Fast/Slow) Detect cycles (Floyd), find cycle start, middle of list, intersection of two lists.
2. Reverse List Iterative with three pointers (prev, curr, next) or recursive; reverse sublist [m..n] or in k-groups.
3. Dummy/Sentinel Nodes Simplify head/tail edge cases for insert/delete and merging.
4. Merge/Split Merge two sorted lists, split list into halves (for merge sort), partition list by pivot.
5. In-place Rewiring Reorder list, rotate list, remove Nth from end (two pointers offset by N).
next
before rewiring; update pointers in the right order.next
becomes null
where appropriate; handle cycles carefully.