A Linked List is a dynamic collection of nodes, where each node contains a data field and a pointer (address) to the next node in the sequence.
Unlike arrays, linked lists do not require contiguous memory; nodes can be scattered, and the logical order is maintained entirely by the pointers.
Traversal involves starting at a 'Head' pointer and following each node's pointer until a null value is reached, signifying the end of the list.
Adding or removing elements is highly efficient because it only requires updating the pointers of adjacent nodes rather than shifting data.
| Feature | Stack | Queue | Linked List |
|---|---|---|---|
| Access Logic | LIFO (Last In, First Out) | FIFO (First In, First Out) | Sequential/Pointer-based |
| Primary Pointers | Base, Top | Front, Rear | Head (Start), Next |
| Memory Usage | Usually static array | Static or Circular array | Dynamic (Nodes + Pointers) |
| Best For | Reversing data, Undo functions | Buffering, Print jobs | Frequent insertions/deletions |
Pointer Logic: Always verify if a pointer needs to be incremented or decremented. For example, in a Stack, push increments the top pointer, while pop decrements it.
Boundary Conditions: When writing algorithms for ADTs, always check for 'Empty' or 'Full' states first to prevent errors like underflow or overflow.
Circular Logic: For circular queues, remember that the 'Full' condition is often when the next position of the rear pointer equals the front pointer.
Linked List Deletion: Remember that 'deleting' a node in a linked list usually means changing the previous node's pointer to skip the target node; the data remains in memory until overwritten or garbage collected.