Big O notation purpose
Describes upper bound of time/space complexity relative to input size.
O(1) complexity
Constant time (e.g., array index lookup).
O(log n) complexity
Logarithmic (e.g., binary search).
O(n) complexity
Linear (e.g., linear search).
O(n log n) complexity
Log-linear (e.g., merge sort, quick sort average).
O(n²) complexity
Quadratic (e.g., bubble sort, nested loops).
O(2ⁿ) complexity
Exponential (e.g., recursive Fibonacci).
Space complexity
Measures amount of memory an algorithm uses relative to input size.
Depth-first search (DFS)
Explores as far as possible down a branch before backtracking. Uses stack (or recursion).
Breadth-first search (BFS)
Explores all neighbours at current depth before moving deeper. Uses queue.
Dijkstra’s algorithm use
Finds shortest path from source to all nodes in weighted graph (non-negative weights).
A* algorithm difference to Dijkstra
Uses heuristics to estimate distance to target; more efficient.
A* requirement
Requires a heuristic function (e.g., Manhattan distance, Euclidean distance).
Bubble sort complexity
O(n²) worst case; simple but inefficient.
Insertion sort complexity
O(n²) worst case; efficient for small or nearly sorted datasets.
Merge sort complexity
O(n log n); stable; divide and conquer; requires additional memory.
Quick sort complexity
O(n log n) average; O(n²) worst; in-place variant exists.
Binary search requirement
Data must be sorted; O(log n).
Linear search complexity
O(n); works on unsorted data.