∑GateAndNet
PlannerSign Up

Data Structure Operations Time Complexity

Data StructureAccess / Search (Avg)Search (Worst)Insert (Worst)Delete (Worst)Space
Sorted ArrayΘ(log⁡n)\Theta(\log n)O(log⁡n)\mathcal{O}(\log n)O(n)\mathcal{O}(n)O(n)\mathcal{O}(n)O(n)\mathcal{O}(n)
Singly Linked ListΘ(n)\Theta(n)O(n)\mathcal{O}(n)O(1)\mathcal{O}(1) (at head)O(n)\mathcal{O}(n)O(n)\mathcal{O}(n)
Binary Search Tree (Unbalanced)Θ(log⁡n)\Theta(\log n)O(n)\mathcal{O}(n) (skewed)O(n)\mathcal{O}(n)O(n)\mathcal{O}(n)O(n)\mathcal{O}(n)
AVL / Red-Black / B+ TreeΘ(log⁡n)\Theta(\log n)O(log⁡n)\mathcal{O}(\log n)O(log⁡n)\mathcal{O}(\log n)O(log⁡n)\mathcal{O}(\log n)O(n)\mathcal{O}(n)
Binary Min-HeapFind-Min: Θ(1)\Theta(1)Max: Θ(n)\Theta(n)O(log⁡n)\mathcal{O}(\log n)Extract-Min: O(log⁡n)\mathcal{O}(\log n)O(n)\mathcal{O}(n)
Hash Table (Chaining)Θ(1+α)\Theta(1 + \alpha)O(n)\mathcal{O}(n)O(1)\mathcal{O}(1)O(n)\mathcal{O}(n)O(n+m)\mathcal{O}(n + m)

Sorting Algorithms Master Comparison

AlgorithmBest TimeAverage TimeWorst TimeAux SpaceStable?In-Place?
Insertion SortΘ(n)\Theta(n) (already sorted!)Θ(n2)\Theta(n^2)Θ(n2)\Theta(n^2)O(1)\mathcal{O}(1)✅ Yes✅ Yes
Selection SortΘ(n2)\Theta(n^2)Θ(n2)\Theta(n^2)Θ(n2)\Theta(n^2)O(1)\mathcal{O}(1) (min swaps O(n)\mathcal{O}(n))❌ No✅ Yes
Merge SortΘ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)O(n)\mathcal{O}(n)✅ Yes❌ No
Quick SortΘ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)Θ(n2)\Theta(n^2)O(log⁡n)\mathcal{O}(\log n) stack❌ No✅ Yes
Heap SortΘ(nlog⁡n)\Theta(n \log n) (or Θ(n)\Theta(n) all equal)Θ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)O(1)\mathcal{O}(1)❌ No✅ Yes
Counting SortΘ(n+k)\Theta(n + k)Θ(n+k)\Theta(n + k)Θ(n+k)\Theta(n + k)O(n+k)\mathcal{O}(n + k)✅ Yes❌ No
Radix Sort (dd digits)Θ(d(n+k))\Theta(d(n + k))Θ(d(n+k))\Theta(d(n + k))Θ(d(n+k))\Theta(d(n + k))O(n+k)\mathcal{O}(n + k)✅ Yes❌ No