All Data Structures
Linked list
Core Implementation
Singly Linked List
Doubly Linked List
Implementation Variations
1. Circular Linked List
2. Skip List
Time Complexities
Operation | Singly Linked | Doubly Linked | Circular | Skip List |
---|---|---|---|---|
Access | O(n) | O(n) | O(n) | O(log n)* |
Search | O(n) | O(n) | O(n) | O(log n)* |
Insert (beginning) | O(1) | O(1) | O(1) | O(log n) |
Insert (end) | O(n)** | O(1) | O(n) | O(log n) |
Delete (beginning) | O(1) | O(1) | O(1) | O(log n) |
Delete (end) | O(n) | O(1) | O(n) | O(log n) |
Reverse | O(n) | O(n) | O(n) | N/A |
* Average case with balanced skip list ** O(1) if tail pointer is maintained
Space Complexities
Implementation | Space Complexity | Additional Notes |
---|---|---|
Singly Linked | O(n) | One pointer per node |
Doubly Linked | O(n) | Two pointers per node |
Circular | O(n) | Similar to singly/doubly linked |
Skip List | O(n log n) | Extra space for multiple levels |
Common Data Structure Patterns
-
Runner Technique (Fast/Slow Pointers)
- Cycle detection
- Middle element finding
- Nth node from end
-
Multiple Pointers
- Previous, current, next references
- Window sliding
- List manipulation
-
Dummy Head
- Simplify edge cases
- Consistent operations
-
Stack/Queue Implementation
- Implementation base
- List reversal
-
Merge Patterns
- Merge sort
- List combination
-
Recursive Patterns
- Reversal
- Deep copy
- Comparison
Edge Cases to Consider
- Empty List
- Single Node
- Last Node
- Cycle Detection
Optimization Techniques
- Tail Pointer Maintenance
- Length Tracking
- Batch Operations
Memory Management
- Reference Cleanup
- Circular Reference Prevention
- Memory Pool
Performance Considerations
- Cache-Friendly Traversal
- Iterator Implementation
Common Pitfalls
- Lost Head Reference
- Memory Leak in Circular Lists
- Skip List Balancing