Skip to content

Note

AlgorithmTime Complexity (Best)Time (Average)Time (Worst)SpaceIn-PlaceUse Case / Notes
Insertion SortO(n)O(n²)O(n²)O(1)YesSmall datasets, mostly sorted arrays
Selection SortO(n²)O(n²)O(n²)O(1)YesSimple, not efficient in practice
Bubble SortO(n)O(n²)O(n²)O(1)YesEducational, rarely used in real life
Merge SortO(n log n)O(n log n)O(n log n)O(n)NoLarge datasets, stable sort needed
Quick SortO(n log n)O(n log n)O(n²)O(log n)YesFastest in practice, divide & conquer
Heap SortO(n log n)O(n log n)O(n log n)O(1)YesPriority queues, not stable
  • Pre-order Traversal (Root → Left → Right)
  • In-order Traversal (Left → Root → Right)
  • Post-order Traversal (Left → Right → Root)
  • Depth-First Search (DFS)
  • Breadth-First Search (BFS)
MethodStructureStrategyGood For
DFSStackDeep firstComponents, cycles, topological
BFSQueueLevel-wiseShortest unweighted path