Balanced Trees (Intro) Quiz
40 comprehensive questions exploring balanced tree concepts — with 16 code examples covering height balancing, AVL trees, red-black trees, rotations, and balance factors in this cpp quiz.
Question 1
Why do trees need balancing?
Question 2
What is height balance in trees?
Height balanced: difference in subtree heights
Is limited to prevent skewingQuestion 3
What is the balance factor in AVL trees?
Question 4
How do rotations fix tree imbalance?
Left rotation: right child becomes parent
Right rotation: left child becomes parentQuestion 5
What is an AVL tree?
Question 6
What are the red-black tree properties?
Red-black properties:
1. Nodes are red or black
2. Root is black
3. Red nodes have black children
4. All paths have same black heightQuestion 7
What is a left rotation in tree balancing?
Question 8
How does AVL insertion maintain balance?
After insertion: update heights, check balance
If |balance| > 1, perform rotationsQuestion 9
What is the maximum height of a red-black tree with n nodes?
Question 10
What is a right rotation?
Right rotation: left child becomes parent
Original parent becomes right childQuestion 11
What is the advantage of red-black trees over AVL trees?
Question 12
How do double rotations work in AVL trees?
Left-right rotation: first left on left child
Then right on parentQuestion 13
What is the balance factor calculation?
Question 14
In red-black trees, what does the black height property ensure?
Black height: number of black nodes on any path
Must be same for all root-to-leaf pathsQuestion 15
What is the time complexity of AVL tree operations?
Question 16
How does red-black tree insertion handle color conflicts?
After insertion: recolor and rotate
Fix red-red violations and black heightQuestion 17
What is the significance of tree balancing in algorithm design?
Question 18
How do rotations preserve the BST property?
Rotation maintains inorder: left < parent < right
Order preserved through restructuringQuestion 19
What is the trade-off between AVL and red-black trees?
Question 20
In AVL trees, when do you perform a left-right double rotation?
Left-right case: insertion in right subtree of left child
Causes balance factor -2, +1 patternQuestion 21
What is the red-black tree recoloring process?
Question 22
How does height balancing prevent worst-case scenarios?
Height h ≤ c*log n
Prevents linked-list degradationQuestion 23
What is the balance factor range for AVL trees?
Question 24
In red-black trees, why are rotations needed?
Rotations fix structural imbalances
After recoloring attempts failQuestion 25
What is the practical difference between AVL and red-black trees?
Question 26
How do rotations affect subtree heights?
Single rotation: may decrease height by 1
Double rotation: adjusts heights appropriatelyQuestion 27
What is the black height in red-black trees?
Question 28
In AVL trees, what triggers a right-left double rotation?
Right-left case: insertion in left subtree of right child
Balance factor +2, -1 patternQuestion 29
What is the amortized cost of red-black tree operations?
Question 30
How do balanced trees compare to hash tables?
Balanced trees: ordered, log n worst-case
Hash tables: average O(1), no orderQuestion 31
What is the role of rotations in maintaining balance?
Question 32
In red-black trees, what does the red property prevent?
No two adjacent red nodes
Prevents long red paths that could unbalanceQuestion 33
What is the height guarantee of AVL trees?
Question 34
How does red-black tree deletion maintain properties?
Deletion: remove node, fix double black
Recolor and rotate to restore invariantsQuestion 35
What is the significance of the root being black in red-black trees?
Question 36
How do balance factors help in tree operations?
Balance factor = height(R) - height(L)
Check |bf| <= 1 for AVLQuestion 37
What is the practical impact of tree balancing on performance?
Question 38
In red-black trees, what is the relationship between colors and balance?
Colors enforce balance indirectly
Black height ensures bounded heightQuestion 39
What is the complexity of implementing rotations?
Question 40
Considering balanced tree concepts and their implementation challenges, which fundamental property makes height balancing crucial for maintaining efficient data structures despite the added complexity of rotation operations?
