TIMED REVISION · 1-MINUTE PANIC SHEETS

Data Structures 10-Minute Rapid Revision

For the last few minutes before the exam hall: one core rule per topic, the formulas you must remember, and the traps that cost marks.

PANIC SHEET 01 · Arrays, Stacks, Queues & Linked Lists

Multi-Dimensional Arrays, Address Translation & Stack Mechanics

Full Lesson →
CORE INVARIANT ANCHOR:

“In Row-Major 2D array A[L1..U1, L2..U2] with element size c: Addr(A[i, j]) = Base + c * [ (i - L1) * (U2 - L2 + 1) + (j - L2) ].”

Must-Remember Principles:
  • —Row-Major 2D: Addr(A[i, j]) = Base + c * [ (i - L1) * N + (j - L2) ] where N = U2 - L2 + 1.
  • —Column-Major 2D: Addr(A[i, j]) = Base + c * [ (j - L2) * M + (i - L1) ] where M = U1 - L1 + 1.
  • —3D Row-Major: Addr(A[i, j, k]) = Base + c * [ (i - L1)*D2*D3 + (j - L2)*D3 + (k - L3) ].
  • —Lower Triangular Matrix (n x n): Stored row-major, element A[i, j] (1-indexed, i >= j) is preceded by i*(i - 1)/2 + (j - 1) elements.
  • —Infix-to-Postfix: Incoming operator popped while in-stack operator has >= precedence (left-associative) or > precedence (right-associative).
  • —Minimum Stacks to implement Queue = 2 Stacks (Amortized O(1) per operation).
Critical Exam Pitfalls:
  • —Check array indexing lower bounds (0 vs 1 vs negative index bounds like -3..5).
  • —Right-associative operators (like exponentiation `^`) have HIGHER incoming precedence than in-stack precedence; identical operators do NOT pop each other.
PANIC SHEET 02 · Arrays, Stacks, Queues & Linked Lists

Queues, Circular Buffers & Linked List Pointer Mechanics

Full Lesson →
CORE INVARIANT ANCHOR:

“In Circular Queue of capacity N: rear = (rear + 1) % N. Full condition: (rear + 1) % N == front. Empty condition: front == rear.”

Must-Remember Principles:
  • —Circular Queue Size: When one empty slot is reserved, max elements stored = N - 1.
  • —Current Count in Circular Queue: count = (rear - front + N) % N.
  • —Queue using Two Stacks: Enqueue pushes to Stack 1; Dequeue pops from Stack 2 (if empty, pop all from Stack 1 into Stack 2). Amortized O(1).
  • —Floyd's Cycle Detection: Slow pointer moves 1 step, Fast pointer moves 2 steps. If they meet, list has a cycle.
  • —Finding Cycle Start Node: After meeting at distance m, reset Slow to head. Advance both Slow and Fast 1 step at a time; they meet at the cycle start node.
Critical Exam Pitfalls:
  • —Linear queue suffers from false overflow: rear reaches N-1 even if front has advanced leaving empty slots at the beginning.
  • —Reversing a singly linked list in-place requires 3 pointers (prev, curr, next) and O(1) auxiliary space.
PANIC SHEET 03 · Tree Fundamentals, Traversals & Binary Search Trees

Binary Tree Axioms, Degree Theorems & Traversal Reconstruction

Full Lesson →
CORE INVARIANT ANCHOR:

“In ANY binary tree, the number of leaf nodes n0 is strictly equal to the number of degree-2 internal nodes plus one: n0 = n2 + 1.”

Must-Remember Principles:
  • —Leaf vs Degree-2 Formula: n0 = n2 + 1 (strictly holds for ALL binary trees regardless of balance).
  • —Total Edges: In any tree with n nodes, total edges E = n - 1.
  • —Max Nodes at Level i (root at level 0): 2^i nodes.
  • —Max Nodes in Binary Tree of height h (root at h=0): 2^{h+1} - 1.
  • —Number of Structurally Distinct Binary Trees with n unlabeled nodes: Catalan number C_n = (1 / (n + 1)) * binom(2n, n).
  • —Unique Tree Reconstruction: Requires INORDER + (PREORDER or POSTORDER). Preorder + Postorder is generally AMBIGUOUS.
Critical Exam Pitfalls:
  • —Preorder + Postorder CANNOT uniquely reconstruct a general binary tree. It uniquely reconstructs ONLY strictly full binary trees (every node has 0 or 2 children).
  • —Inorder traversal alone gives ZERO structural information without Preorder or Postorder.
PANIC SHEET 04 · Tree Fundamentals, Traversals & Binary Search Trees

Binary Search Trees: Search, Insertion, Deletion & Successors

Full Lesson →
CORE INVARIANT ANCHOR:

“Inorder traversal of ANY valid BST yields strictly monotonically increasing sorted order.”

Must-Remember Principles:
  • —BST Invariant: For any node x, all keys in left subtree are < key(x), and all keys in right subtree are > key(x).
  • —Inorder Successor of node x: If x has right subtree => minimum key in right subtree. Else => lowest ancestor of x whose left child is also an ancestor of x.
  • —Deletion Case 1 (Leaf): Simply remove node (set parent's pointer to null).
  • —Deletion Case 2 (One Child): Splice out node by connecting parent directly to child.
  • —Deletion Case 3 (Two Children): Replace node's key with its Inorder Successor (or Predecessor), then delete the successor (which has at most 1 child).
  • —Height Complexity: Best/Average case O(log n); Worst case O(n) (skewed tree on sorted input).
Critical Exam Pitfalls:
  • —Predecessor and Successor in a BST with n nodes can be found in O(h) time WITHOUT inspecting all nodes.
  • —Inserting elements in already-sorted order degrades an ordinary BST into a singly linked list with O(n) search time.
PANIC SHEET 05 · Self-Balancing Trees & Multi-Way Indices

AVL Trees: Height Balancing, Rotations & Minimal Node Bounds

Full Lesson →
CORE INVARIANT ANCHOR:

“AVL Balance Factor: BF(node) = Height(LeftSubtree) - Height(RightSubtree) in {-1, 0, +1}. Rebalance immediately at the lowest critical unbalanced node.”

Must-Remember Principles:
  • —LL Imbalance: Critical node BF = +2, left child BF = +1 => Single Right Rotation at critical node.
  • —RR Imbalance: Critical node BF = -2, right child BF = -1 => Single Left Rotation at critical node.
  • —LR Imbalance: Critical node BF = +2, left child BF = -1 => Left Rotation at child, then Right Rotation at critical node.
  • —RL Imbalance: Critical node BF = -2, right child BF = +1 => Right Rotation at child, then Left Rotation at critical node.
  • —Minimum Nodes in AVL Tree of height h (root at h=0): N(h) = N(h-1) + N(h-2) + 1, with N(0)=1, N(1)=2.
  • —Maximum Height of AVL tree with n nodes: h <= 1.44 * log2(n + 2) - 0.328 = O(log n).
Critical Exam Pitfalls:
  • —When an insertion causes multiple ancestors to become unbalanced, ALWAYS rotate at the LOWEST (deepest) unbalanced node. A single rotation restores balance to the entire tree.
  • —Be meticulous whether the problem defines height of a single-node tree as 0 or 1.
PANIC SHEET 06 · Self-Balancing Trees & Multi-Way Indices

B-Trees & B+ Trees: Multi-Way Indexing & Block Size Numericals

Full Lesson →
CORE INVARIANT ANCHOR:

“In B-Tree of order m: Root has between 2 and m children (1 to m-1 keys). Internal nodes have between ceil(m/2) and m children (ceil(m/2)-1 to m-1 keys).”

Must-Remember Principles:
  • —B-Tree Order m Constraints: Max keys per node = m - 1; Min keys for non-root = ceil(m/2) - 1.
  • —B+ Tree Distinctive Property: Internal nodes store keys only as routing guides; all actual record pointers and keys reside in leaf nodes, linked as a doubly linked list.
  • —Internal Node Order Equation (Block B, Key K, Block Pointer P): p * P + (p - 1) * K <= B.
  • —Leaf Node Capacity Equation (Record Pointer Pr): q * (K + Pr) + P <= B.
Critical Exam Pitfalls:
  • —In B-Trees, data record pointers are present in ALL nodes (internal and leaf). In B+ Trees, data record pointers are EXCLUSIVELY in leaf nodes.
  • —Leaf nodes in B+ Trees require 1 block pointer to link to the next sibling leaf for range scanning.
PANIC SHEET 07 · Priority Queues & Binary Heaps

Binary Heaps: Invariants, Linear-Time Build-Heap & Heap Sort

Full Lesson →
CORE INVARIANT ANCHOR:

“Build-Heap from an arbitrary array runs in strictly O(n) linear time, NOT O(n log n), because sum_{h=0}^inf (h / 2^h) = 2.”

Must-Remember Principles:
  • —Array Indexing (1-indexed): Parent = floor(i/2), Left = 2i, Right = 2i + 1.
  • —Array Indexing (0-indexed): Parent = floor((i - 1)/2), Left = 2i + 1, Right = 2i + 2.
  • —Non-Leaf Internal Nodes: Span indices 1 to floor(n/2). Leaves span floor(n/2) + 1 to n.
  • —Max-Heap Property: A[parent(i)] >= A[i] for all i > 1.
  • —Heap Sort: Build-Heap O(n) + (n-1) Extract-Max calls O(n log n) => Theta(n log n) in-place, unstable.
Critical Exam Pitfalls:
  • —Inserting elements one-by-one into an initially empty heap takes O(n log n). Bottom-up Build-Heap takes O(n).
  • —In a Min-Heap of n elements, the maximum element must be located among the LEAVES (indices floor(n/2) + 1 to n).
PANIC SHEET 08 · Hashing, Collision Dynamics & Disjoint Sets

Hash Tables, Open Addressing & Collision Probing Dynamics

Full Lesson →
CORE INVARIANT ANCHOR:

“Double Hashing: h(k, i) = (h1(k) + i * h2(k)) % m eliminates both primary and secondary clustering. h2(k) must be relatively prime to m.”

Must-Remember Principles:
  • —Linear Probing: h(k, i) = (h'(k) + i) % m. Suffers from Primary Clustering (contiguous blocks of occupied slots).
  • —Quadratic Probing: h(k, i) = (h'(k) + c1*i + c2*i^2) % m. Eliminates primary clustering; suffers from Secondary Clustering (keys with same initial hash share probe path).
  • —Double Hashing: h(k, i) = (h1(k) + i * h2(k)) % m. Independent hash function h2(k) provides distinct step size for each key.
  • —Load Factor: alpha = n / m (where n is keys stored, m is table size). In open addressing, alpha <= 1 strictly.
Critical Exam Pitfalls:
  • —In double hashing, h2(k) must NEVER return 0 (an offset of 0 causes an infinite loop at the initial slot).
  • —When deleting from an open-addressed hash table, you CANNOT set slot to empty; you must use a 'DELETED' marker (tombstone) to avoid breaking probe chains.
PANIC SHEET 09 · Hashing, Collision Dynamics & Disjoint Sets

Chaining, Universal Hashing & Search Complexity Under Load

Full Lesson →
CORE INVARIANT ANCHOR:

“Under Simple Uniform Hashing: Expected time for successful search in chaining is Theta(1 + alpha/2); unsuccessful search is Theta(1 + alpha).”

Must-Remember Principles:
  • —Load Factor: alpha = n / m (average keys per slot). In chaining, alpha can exceed 1.
  • —Open Addressing Unsuccessful Search: Expected probes <= 1 / (1 - alpha).
  • —Open Addressing Successful Search: Expected probes <= (1 / alpha) * ln(1 / (1 - alpha)).
  • —Universal Hashing Definition: A family of hash functions H is universal if for any x != y, Pr_{h in H}[h(x) == h(y)] <= 1 / m.
Critical Exam Pitfalls:
  • —In open addressing, as load factor alpha approaches 1, the expected number of probes for an unsuccessful search approaches infinity: 1 / (1 - alpha).
PANIC SHEET 10 · Hashing, Collision Dynamics & Disjoint Sets

Disjoint Set Union (DSU): Union by Rank & Path Compression

Full Lesson →
CORE INVARIANT ANCHOR:

“DSU with Union by Rank AND Path Compression achieves nearly linear amortized time O(m * alpha(n)) for m operations on n elements.”

Must-Remember Principles:
  • —Make-Set(x): Creates single-node tree with parent[x] = x and rank[x] = 0. Time O(1).
  • —Find-Set(x) with Path Compression: Recursively sets parent[x] = Find-Set(parent[x]), flattening tree directly to root.
  • —Union(x, y) by Rank: Attaches root of smaller rank under root of larger rank. Rank increases by 1 ONLY if both roots share equal rank.
  • —Rank Heuristic Upper Bound: A tree with root of rank r has at least 2^r nodes. Hence maximum rank is <= floor(log2 n).
  • —Inverse Ackermann Function: alpha(n) <= 4 for all universe sizes n <= 2^{65536}.
Critical Exam Pitfalls:
  • —Union by rank ALONE gives O(m log n). Path compression ALONE gives O(m log n). BOTH together achieve O(m * alpha(n)).
  • —Path compression does NOT alter the stored rank value of nodes.
PANIC SHEET 11 · GATE DA: Python Programming

Python Fundamentals: Values, Expressions & Control Flow

Full Lesson →
CORE INVARIANT ANCHOR:

“Trace values in order; preserve types, mutation, branch conditions, and exclusive range endpoints.”

Must-Remember Principles:
  • —range(stop): 0, …, stop−1
  • —a // b = floor(a / b)
  • —a % b is the remainder paired with Python floor division
Critical Exam Pitfalls:
  • —Negative floor division
  • —Mutable list aliasing
  • —`is` versus `==`
  • —`break` affects loop `else`
PANIC SHEET 12 · GATE DA: Python Programming

Python Collections: Lists, Tuples, Dictionaries & Sets

Full Lesson →
CORE INVARIANT ANCHOR:

“Use the simplest container whose operations fit the task.”

Must-Remember Principles:
  • —list append/pop at end: amortized O(1)
  • —list search: O(n)
  • —dict/set lookup: expected O(1), with collision assumptions
Critical Exam Pitfalls:
  • —Aliasing mutable lists
  • —list front deletion shifts elements
  • —unhashable keys
  • —`sort` mutates; `sorted` returns a new list
PANIC SHEET 13 · GATE DA: Python Programming

Python Functions, Iteration & Data Transformations

Full Lesson →
CORE INVARIANT ANCHOR:

“Write a function contract, transform to a fresh result when appropriate, and handle missing or empty data explicitly.”

Must-Remember Principles:
  • —Mean = sum(observed) / count(observed)
  • —Comprehension order: iterate → filter → transform
Critical Exam Pitfalls:
  • —Implicit `None` return
  • —Mutable default values
  • —Mutating while iterating
  • —Undefined missing-data behavior
PANIC SHEET 14 · GATE DA: Python Programming

Python Search & Sorting: Trace the Required Algorithms

Full Lesson →
CORE INVARIANT ANCHOR:

“Check each algorithm's precondition, invariant, and worst-case bound separately.”

Must-Remember Principles:
  • —Linear search O(n); binary search O(log n) on sorted input
  • —Quadratic elementary sorts O(n²) worst case
  • —Merge sort O(n log n); common quicksort O(n²) worst case
Critical Exam Pitfalls:
  • —Unsorted binary-search input
  • —Off-by-one interval updates
  • —Expected time is not worst-case time
  • —State stability only when the code preserves equal-key order
PANIC SHEET 15 · GATE DA: Python Programming

Implementing Stacks, Queues, Lists, Trees & Hash Tables in Python

Full Lesson →
CORE INVARIANT ANCHOR:

“State the representation and supported operations before giving a data-structure complexity.”

Must-Remember Principles:
  • —Array/list indexing O(1); front insertion/deletion O(n)
  • —Linked-list search O(n), head insertion O(1)
  • —Tree traversal O(n)
  • —Hash lookup expected O(1), worst case can differ
Critical Exam Pitfalls:
  • —List versus linked list
  • —Stack versus queue order
  • —Unbalanced tree guarantees
  • —Expected versus worst-case hash cost