Data Structures: Linked list, stack, queue, priority queues, hashing, binary trees, tree traversal, AVL trees, graphs — shortest paths, minimum spanning trees, sorting algorithms.
Programming in C: Operators and expressions, control statements, storage types, functions, arrays and strings, structures, pointers and dynamic memory management, file handling.
Growth-rate order
1 < log n < √n < n < n log n < n² < n³ < 2ⁿ < n! < nⁿ
Master theorem
T(n) = aT(n/b) + f(n): compare f(n) with n^(log_b a); the larger wins, a tie adds a log factor
P, NP, NP-complete, NP-hard
P ⊆ NP · NP-complete = NP ∩ NP-hard · SAT first (Cook–Levin 1971) · any NP-complete problem in P ⇒ P = NP · halting problem: undecidable, NP-hard
Classic recurrences
T(n/2)+1 → log n · 2T(n/2)+n → n log n · T(n−1)+n → n² · 2T(n−1)+1 → 2ⁿ − 1 (Hanoi)
Searching costs
linear: average (n + 1)/2 · binary: at most ⌊log₂ n⌋ + 1 probes (1,000 → 10; 10⁶ → 20)
Array stack (top starts at −1)
empty: top == −1 · full: top == MAX − 1 · size = top + 1
Circular queue (front/rear = first/last)
full: (rear + 1) % MAX == front · count = (rear − front + MAX) % MAX + 1
Catalan number Cₙ
(2n)!/((n+1)!·n!) = 1, 2, 5, 14, 42, 132 — stack permutations, BSTs on n keys
Heap index arithmetic
0-based: parent ⌊(i−1)/2⌋, children 2i+1, 2i+2 · 1-based: parent ⌊i/2⌋, children 2i, 2i+1
Binary-heap costs
insert / delete-max O(log n) · find-max O(1) · build-heap O(n) · heap sort O(n log n)
Hashing load factor α = n/m
open addressing miss ≤ 1/(1 − α) probes · chaining hit ≈ 1 + α/2 · linear probing → primary clustering
Binary-tree counts
n₀ = n₂ + 1 · edges n − 1 · NULL links n + 1 · max nodes of height h (in edges) = 2ʰ⁺¹ − 1
AVL minimum nodes
N(h) = N(h−1) + N(h−2) + 1, height h in edges (N(0) = 1) → 1, 2, 4, 7, 12, 20, 33 · height ≈ 1.44 log₂ n
Graph edge counts
Kₙ has n(n − 1)/2 edges (directed n(n − 1)) · Σ deg(v) = 2|E| · tree has n − 1
BFS / DFS
queue / stack (recursion) · O(V + E) with adjacency lists, O(V²) with a matrix
Dijkstra
O(V²) array, O((V + E) log V) binary heap · fails with negative edges
Bellman–Ford · Floyd–Warshall
O(VE), V − 1 passes, detects negative cycles · O(V³), d[i][j] = min(d[i][j], d[i][k] + d[k][j])
Prim · Kruskal
O(V²) matrix or O(E log V) heap · O(E log E) = O(E log V) with union–find
Cayley's formula
Kₙ has nⁿ⁻² spanning trees (K₄ = 16, K₅ = 125); every spanning tree has V − 1 edges
Comparison-sort lower bound
⌈log₂ n!⌉ = Ω(n log n) · 3 keys → 3, 4 → 5, 5 → 7 comparisons
Stable vs unstable sorts
stable: bubble, insertion, merge, counting, radix · unstable: selection, quick, heap, Shell
C keywords
32 in ANSI C (C89) · 37 in C99 · 44 in C11 — all lowercase
Typical sizes (64-bit Linux)
char 1 · short 2 · int 4 · long 8 · long long 8 · float 4 · double 8 · any pointer 8 bytes (Turbo C: int and pointers 2)
n-bit integer range
signed −2ⁿ⁻¹ … 2ⁿ⁻¹ − 1 · unsigned 0 … 2ⁿ − 1 (16-bit int: −32,768 … 32,767)
Integer division (C99)
truncates toward zero; a % b takes the sign of a: −7 / 2 = −3, −7 % 2 = −1
Precedence, high → low
postfix → unary → multiplicative → additive → shift → relational → equality → & → ^ → | → && → || → ?: → assignment → comma (unary, ?: and assignment group right-to-left)
Sequence points
end of full expression (;) · after && || ?: and comma · before a function call — changing a variable twice between them is undefined
Storage classes
auto/register: stack, garbage, block scope · static local: 0, keeps value · static global: internal linkage · extern: declaration only
Tower of Hanoi
T(n) = 2T(n − 1) + 1 = 2ⁿ − 1 moves (3 discs → 7, 10 → 1,023)
Row-major address
&a[i][j] = B + (i × C + j) × w (0-based, C columns, w bytes per element)
sizeof vs strlen
char s[] = "abc": sizeof 4 (counts the '\0'), strlen 3 · a char pointer to "abc": sizeof 8 on 64-bit (the pointer itself)
strcmp(a, b)
< 0 if a sorts first · 0 if equal · > 0 if a sorts later — only the sign is guaranteed
Pointer arithmetic
p + n = address + n × (size of the pointed-to type) · q − p = elements between · a[i] ≡ i[a]
struct / union size
struct ≥ sum of members (padding to alignment) · union = largest member rounded up · enum starts at 0
malloc vs calloc
malloc(bytes): uninitialised · calloc(n, size): n × size bytes zeroed · realloc may move · all return NULL on failure
fopen modes
r: must exist · w: create or truncate · a: create, write at end · +: read and write · b: binary · failure → NULL
fseek origins
SEEK_SET 0 (start) · SEEK_CUR 1 (current) · SEEK_END 2 (end) · ftell = current offset · rewind = fseek(fp, 0, SEEK_SET)
Build stages
preprocess (gcc -E → .i) → compile (-S → .s) → assemble (-c → .o) → link (executable); macros expand before compilation