π PHP Linked List β Topic Index
A linked list is a linear data structure where each element (node) contains a value and a pointer to the next node. Unlike arrays, linked lists offer O(1) insertion/deletion at known positions and dynamic sizing.
Topics Covered
| # | Topic | Key Concepts |
|---|---|---|
| 1 | Basics | Node structure, SLL, DLL, traversal |
| 2 | Operations | Insert, delete, reverse, merge |
| 3 | Interview Questions | 25 classic problems |
Why Linked Lists?
- Dynamic size β no pre-allocation needed
- O(1) insert/delete β at head or with a reference to the node
- Foundation for stacks, queues, graphs, hash chains
Common Patterns
- Two pointers (slow/fast) β cycle detection, middle node, kth from end
- Dummy head β simplifies edge cases on empty or single-node lists
- Reverse in place β prev/curr/next pointer manipulation
- Merge β merge sorted lists like merge sort