∑GateAndNet
Practice MCQs
GATE CS / Programming & Data Structures
Edit
INTERMEDIATE🔥 High-Yield Exam Topic 4 min read 4 views

AVL Trees, Binary Heaps & Hashing Probe Complexity

Minimum nodes in AVL tree of height h, O(n) Build-Heap proof, and LL/RR/LR/RL rotation rules.

Binary Heap Index Formulas (0-based vs 1-based)

ConventionRootLeft Child of iiRight Child of iiParent of ii
1-Based Array112i2i2i+12i + 1⌊i/2⌋\lfloor i / 2 \rfloor
0-Based Array002i+12i + 12i+22i + 2⌊(i−1)/2⌋\lfloor (i - 1) / 2 \rfloor
💡 Shortcut & Tip

Finding Maximum in a Min-Heap: In a Min-Heap of nn distinct elements, the maximum element MUST reside in one of the ⌈n/2⌉\lceil n/2 \rceil leaf nodes, so finding it requires Θ(n)\Theta(n) comparisons in the worst case!

AVL Rotations Summary

  • Single Rotation (1 rotation): Triggered by outer insertion LL (Right Rotate) or RR (Left Rotate).
  • Double Rotation (2 rotations): Triggered by zig-zag inner insertion LR (Left then Right) or RL (Right then Left).
  • In AVL insertion, fixing the lowest imbalanced ancestor restores balance to the entire tree (O(1)\mathcal{O}(1) rotations!). In AVL deletion, rotations may propagate up to the root (O(log⁡n)\mathcal{O}(\log n) rotations).
📐 Quick Revision Formula Sheet
Minimum Nodes in AVL Tree of Height h
N(h)=N(h−1)+N(h−2)+1,N(0)=1,  N(1)=2N(h) = N(h-1) + N(h-2) + 1,\quad N(0)=1,\; N(1)=2
💡 Sequence: 1, 2, 4, 7, 12, 20, 33, 54... (Fibonacci shifted!)
Leaf Nodes in n-element Binary Heap
Leaves start at index ⌊n/2⌋+1 (1-based), count=⌈n/2⌉\text{Leaves start at index } \lfloor n/2 \rfloor + 1 \text{ (1-based)}, \text{ count} = \lceil n/2 \rceil
💡 Build-Heap runs in tight O(n) time, NOT O(n log n)!
#Data Structures#AVL#Heap#Hashing

🎯 Practice PYQs on This Topic (3)

Q1.GATE CS DSAMCQMEDIUM
+2 Marks • -0.67 Neg

What is the tight worst-case time complexity of building a Binary Max-Heap bottom-up (Build-Max-Heap) from an unsorted array of nn elements?

Q2.GATE CS DSAMCQMEDIUM
+2 Marks • -0.67 Neg

What is the minimum number of nodes in an height-balanced AVL tree of height h=4h = 4 (where a single root node has height 00)?

Q3.UGC NET / GATE DSAMCQEASY
+1 Marks • -0.33 Neg

Which open-addressing collision resolution technique eliminates both primary and secondary clustering?

Previous TopicC Pointers, Static Storage, Array Decay & Tricky Output PatternsNext Topic Stacks, Queues, Linked Lists & Binary Tree Properties