This sheet holds the complexity tables, tree formulas and algorithm comparisons behind most Data Structures & Algorithms questions. DSA carries 10% of the NSCT per HEC's Areas of Competencies, and 2026 candidates averaged 40.2% accuracy in it, one of the four weakest areas, per the HEC NSCT report and APP. Print it (or save it as a PDF from your browser) and keep it next to your practice.
Key definitions
Term
One-line meaning
O(g) / Ω(g) / Θ(g)
Upper bound / lower bound / tight bound (both)
Best, worst, average case
Input scenarios; any of them can be stated with O, Ω or Θ
Amortised cost
Average cost per operation over a sequence (doubling-array append O(1))
ADT
What operations do (stack: push, pop), not how
Stable sort
Equal keys keep their original order
In-place
O(1) extra space (some texts allow O(log n) stack)
Height of a tree
Longest root-to-leaf path in edges (CLRS); some texts count nodes
Complete binary tree
All levels full except the last, filled left to right
Load factor α
n ÷ m (keys ÷ slots)
Optimal substructure
An optimal answer contains optimal answers to subproblems
Inorder plus preorder (or postorder) rebuilds a unique binary tree; preorder plus postorder does not.
Graph algorithms
Algorithm
Solves
Negative edges?
Time
BFS
Shortest paths, unweighted
n/a
O(V + E)
DFS
Reachability, cycles, topological order
n/a
O(V + E)
Dijkstra (binary heap)
Single source
No
O((V + E) log V)
Bellman-Ford
Single source, detects negative cycles
Yes
O(VE)
Floyd-Warshall
All pairs
Yes, no negative cycles
O(V³)
Kruskal
MST (sort edges, union-find)
n/a
O(E log E)
Prim (binary heap)
MST (grow one tree)
n/a
O(E log V)
Kahn's topological sort
DAG ordering
n/a
O(V + E)
Recurrences and the master theorem
Recurrence
Solution
Example
T(n) = T(n/2) + 1
Θ(log n)
Binary search
T(n) = 2T(n/2) + n
Θ(n log n)
Merge sort
T(n) = 2T(n/2) + 1
Θ(n)
Tree traversal
T(n) = T(n − 1) + 1
Θ(n)
Linear recursion
T(n) = T(n − 1) + n
Θ(n²)
Worst-case quicksort
T(n) = 2T(n − 1) + 1
Θ(2ⁿ)
Towers of Hanoi
Master theorem for T(n) = aT(n/b) + f(n): compare f(n) with n^(log_b a). Smaller (polynomially) → Θ(n^(log_b a)); equal → multiply by log n; larger (with the regularity condition) → Θ(f(n)). It does not apply to T(n − 1) forms.
Hashing
Method
Clustering
Linear probing
Primary clustering
Quadratic probing
Secondary clustering
Double hashing
Avoids both
Separate chaining
No clustering; α can exceed 1
Use a prime table size not close to a power of 2 for the division method. Deleting under open addressing needs a tombstone.