A Singly Linked List is a fundamental linear data structure where elements (called Nodes) are not stored in contiguous memory cells. Instead, each node contains a data payload and a reference pointer (next) to the subsequent node in memory.
Think of a treasure hunt where each clue contains:
| Feature | Array | Singly Linked List |
|---|---|---|
| Memory Allocation | Contiguous chunk of RAM | Scattered nodes anywhere in Heap memory |
Index Access (get(i)) | $O(1)$ (Direct pointer math) | $O(n)$ (Must traverse from Head) |
| Insert/Delete at Beginning | $O(n)$ (Shifting elements) | $O(1)$ (Update Head pointer) |
| Memory Overhead | Low (Only data stored) | High (Each node stores data + 8-byte pointer) |
| Resizing Cost | $O(n)$ reallocation & copy | $O(1)$ dynamic heap allocation per node |
Reversing a linked list is the quintessential technical interview question. You must redirect every node's next pointer to face backwards without allocating new nodes:
1 -> 2 -> 3 -> NULL| Iteration | curr.val | nextTemp.val | New curr.next | prev becomes | curr becomes |
|---|---|---|---|---|---|
| Init | 1 | - | - | NULL | 1 |
| 1 | 1 | 2 | NULL | 1 | 2 |
| 2 | 2 | 3 | 1 | 2 | 3 |
| 3 | 3 | NULL | 2 | 3 | NULL (Loop ends) |
Result: prev points to Node 3 -> 2 -> 1 -> NULL. Reversed in $O(n)$ time with $O(1)$ space!
get(i)) $O(n)$ while in an array it is $O(1)$?curr.next = prev during an in-place list reversal before saving curr.next in a temporary variable?next pointer of the tail node store in a standard non-circular linked list?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.