Time Complexity of Data Structures
Data Structure | Search | Insertion | Deletion | Delete Max | Delete Min |
---|
Array (unsorted) | O(n) | O(1) | O(n) | O(n) | O(n) |
Array (sorted) | O(logn) | O(n) | O(n) | O(1) | O(1) |
Singly Linked List (Unsorted) | O(n) | O(1) | O(n) | O(n) | O(n) |
Singly Linked List (Sorted) | O(n) | O(n) | O(n) | O(n) | O(1) |
Doubly Linked List (Unsorted) | O(n) | O(1) | O(n) | O(n) | O(n) |
Doubly Linked List (Sorted) | O(n) | O(n) | O(n) | O(1) | O(1) |
Stack (LIFO) | O(n) | O(1) | O(1) | O(1) | O(n) |
Queue (FIFO) | O(n) | O(1) | O(1) | O(n) | O(n) |
Deque (Double-Ended Queue) | O(n) | O(1) | O(1) | O(1) | O(1) |
Hash Table | O(1) | O(1) | O(1) | O(n) | O(n) |
Binary Search Tree (BST) | O(logn) | O(logn) | O(logn) | O(logn) | O(logn) |
AVL Tree | O(logn) | O(logn) | O(logn) | O(logn) | O(logn) |
Red-Black Tree | O(logn) | O(logn) | O(logn) | O(logn) | O(logn) |
B-Tree (order m) | O(logmβn) | O(logmβn) | O(logmβn) | O(logmβn) | O(logmβn) |
B+ Tree | O(logmβn) | O(logmβn) | O(logmβn) | O(1) (linked leaf nodes) | O(1) (linked leaf nodes) |
2-3-4 Tree | O(logn) | O(logn) | O(logn) | O(logn) | O(logn) |
Binary Heap | O(n) | O(logn) | O(logn) | O(logn) | O(logn) |
Binomial Heap | O(logn) | O(logn) | O(logn) | O(logn) | O(logn) |
Fibonacci Heap | O(1) | O(1) | O(logn) | O(logn) | O(logn) |
Key Takeaways
- Hash tables are fastest for search, insert, and delete, but have slow min/max operations.
- Balanced trees (AVL, Red-Black, B-Trees) ensure O(logn) performance for all operations.
- Heaps are optimal for priority queues, providing efficient delete max/min.
- B+ Trees are best for range queries, as they store all data in leaf nodes.
- Binomial & Fibonacci Heaps are useful in graph algorithms (Dijkstra, Primβs algorithm).