Linked Lists are dynamic data structures where elements (nodes) are stored in sequence, with each node containing data and a reference to the next node. They provide flexibility in memory allocation and efficient insertion/deletion.
Each node contains data and a pointer to the next node
Size can grow or shrink during runtime
Constant time insertion at the beginning
No memory waste, allocates as needed
Easy insertion and deletion at any position
Operation | Best Case | Average Case | Worst Case |
---|---|---|---|
Access | O(1) | O(n) | O(n) |
Search | O(1) | O(n) | O(n) |
Insertion | O(1) | O(1) | O(1) |
Deletion | O(1) | O(1) | O(1) |
Space Complexity: O(n) where n is the number of elements
Note: Insertion/Deletion is O(1) when you have reference to the node