Member-only story
Linked List (Data Structure) core concept and some common question
5 min readSep 26, 2024
1. Definition
A Linked List is a linear data structure where elements, called nodes, are connected via pointers. Each node contains two parts:
- Data: The value or information stored in the node.
- Next: A pointer/reference to the next node in the sequence.
Unlike arrays, linked lists do not store their elements in contiguous memory locations, making them more flexible in terms of size, but more complex to work with.
2. Types of Linked Lists
- Singly Linked List: Each node points to the next node, and the last node points to
null
. - Doubly Linked List: Each node contains an additional pointer to the previous node, allowing traversal in both directions.
- Circular Linked List: The last node points back to the first node, forming a loop.
3. Key Characteristics
- Dynamic size: Unlike arrays, linked lists can grow or shrink dynamically as needed.
- Non-contiguous memory allocation: Nodes are scattered in memory, making linked lists more memory-efficient in certain use cases.
- O(1) insertion/deletion: Adding or removing nodes from the front (head) or back (tail) is efficient in a linked list, compared to the O(n) cost of shifting elements in an array.
- Sequential access…