Data Structures & Algorithms Formula Sheet

Sorting algorithm time/space complexities, Binary Search Tree invariants and traversals, and Dijkstras weighted shortest-path algorithm.

Core Equations & Variable Definitions

Comparison Sort Lower Bound

\Omega(n \log n)

Decision-tree bound for any comparison-based sort (Merge Sort, Heapsort, Timsort).

BST Height Bounds

h_{\text{balanced}} = \lfloor \log_2 n \rfloor, \quad h_{\text{skewed}} = n - 1

Search/insert/delete run in O(h) time.

Dijkstras Priority-Queue Complexity

O\big((V + E)\log V\big)

Requires non-negative edge weights w(u, v) >= 0.

BST In-Order Traversal Property

\text{Left} \to \text{Node} \to \text{Right} \implies \text{Sorted Sequence}

Visits keys in strictly ascending order.

Interactive Data Structures & Algorithms Calculators

Common Exam Questions

Why does Dijkstras algorithm fail on negative edge weights?

Dijkstra greedily finalizes the closest unvisited node assuming no future path can lower its distance; a negative edge later can violate that assumption (use Bellman-Ford instead).

Which sorting algorithms are stable?

Merge Sort, Insertion Sort, and Bubble Sort preserve the relative order of equal keys, whereas standard in-place Quicksort and Heapsort are unstable.

When does Quicksort degrade to O(n^2)?

Quicksort hits O(n^2) when pivot selection repeatedly picks the smallest or largest element, such as naive first-element pivoting on already-sorted arrays.