GateMCQSCIENTIFIC PREP LAB
PlanSign Up
INTERMEDIATEFrequently Tested 4 min read 24 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
Quick 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).
Key Formulas Summary
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
Note: 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
Note: Build-Heap runs in tight O(n) time, NOT O(n log n)!
#Data Structures#AVL#Heap#Hashing

Practice Questions on This Chapter (6)

Q1GATE CS DSAMCQMEDIUM
+2M • -0.67

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?

⚡ Click an option above to verify instantly
Q2GATE CS DSAMCQMEDIUM
+2M • -0.67

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)?

⚡ Click an option above to verify instantly
Q3UGC NET / GATE DSAMCQEASY
+1M • -0.33

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

⚡ Click an option above to verify instantly
Q4GATE CS 2020NATMEDIUM
+2M • 0 Neg

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

Q5GATE CS 2019MCQMEDIUM
+2M • -0.67

Keys 12, 18, 13, 2, 3, 23, 5, 15 are inserted in order into an initially empty hash table of size m=10m = 10 using h(k)=k mod 10h(k) = k \bmod 10 and Linear Probing. At which index is key 15 placed?

⚡ Click an option above to verify instantly
Q6GATE CS 2024 Set-1MCQEASY
+1M • -0.33

In a Binary Max-Heap containing n=100n = 100 distinct elements stored in a 1-indexed array H[1..100], in which subarray index range MUST the minimum element reside?

⚡ Click an option above to verify instantly
Previous TopicC Pointers, Static Storage, Array Decay & Tricky Output PatternsNext Topic Stacks, Queues, Linked Lists & Binary Tree Properties