Top MCQs on Balanced Binary Search Trees with Answers

A Balanced Binary Tree, also known as a self-balancing binary tree, is a binary tree data structure in which the height of the left and right subtrees of any node differ by at most a constant factor. This balancing property ensures that the tree remains relatively shallow, leading to more efficient operations compared to unbalanced trees. AVL tree is the example of this. More On Balanced Binary Tree….
Balanced Binary Search Tree  Quiz

Balanced Binary Search Tree Quiz

Question 1

The worst case running time to search for an element in a balanced in a binary search tree with n2^n elements is 
(A) \Theta(n log n)
(B) \Theta (n2^n)
(C) \Theta (n)
(D) \Theta (log n)

Cross

A

Cross

B

Tick

C

Cross

D



Question 1-Explanation: 

Time taken to search an element is \Theta (h) where h is the height of Binary Search Tree (BST). The growth of height of a balanced BST is logarithmic in terms of number of nodes. So the worst case time to search an element would be \Theta (Log(n*2^n)) which is \Theta (Log(n) + Log(2^n)) Which is \Theta (Log(n) + n) which can be written as \Theta (n) .

Question 2
What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0.
Cross
2
Tick
3
Cross
4
Cross
5


Question 2-Explanation: 
AVL trees are binary trees with the following restrictions. 1) the height difference of the children is at most 1. 2) both children are AVL trees Following is the most unbalanced AVL tree that we can get with 7 nodes
                 a
               /   \
             /      \
            b        c
          /  \      /
         /    \    /
        d     e   g
       /
      /
     h
Question 3
What is the worst case possible height of AVL tree?
Cross
2Logn
Assume base of log is 2
Tick
1.44log n
Assume base of log is 2
Cross
Depends upon implementation
Cross
Theta(n)


Question 3-Explanation: 
Question 4
Which of the following is AVL Tree?
A
        100
     /      
    50       200
   /           
 10            300


B
           100
       /       
     50        200
    /        /     
  10       150     300
 /
5


C
            100
       /          
     50            200
    /            /     
  10    60       150     300
 /                         
5                   180       400
Cross
Only A
Tick
A and C
Cross
A, B and C
Cross
Only B


Question 4-Explanation: 
A Binary Search Tree is AVL if balance factor of every node is either -1 or 0 or 1. Balance factor of a node X is [(height of X->left) - (height of X->right)]. In Tree B, the node with value 50 has balance factor 2. That is why B is not an AVL tree.
Question 5
Consider the following AVL tree.
         60
      /       
    20      100
           /   
         80    120     
Which of the following is updated AVL tree after insertion of 70
A
        70
      /      
    60      100
   /       /    
 20       80    120 

B
        100
      /      
    60      120
   /       /  
 20   70   80   


C
        80
      /      
    60      100
   /         
 20   70      120

D
        80
      /      
    60      100
   /       /   
 20      70    120  
Cross
A
Cross
B
Tick
C
Cross
D


Question 5-Explanation: 
Refer following for steps used in AVL insertion. AVL Tree | Set 1 (Insertion)
After insertion of 70, tree becomes following
         60
      /     \  
    20      100
           /   \
         80    120     
        /
       70
We start from 50 and travel up. We keep travelling up till we find an unbalanced node. In above case, we reach the node 60 and see 60 got unbalanced after insertion and this is Right Left Case. So we need to apply two rotations
         60                               60                            80
      /     \       Right Rotate(100)  /      \     Left Rotate(60)   /    \
    20      100    -----------------> 20        80 ---------------> 60      100 
           /   \                              /   \                /  \        \
         80    120                          70     100            20   70       120  
        /                                            \    
      70                                             120 
Question 6
Which of the following is a self-adjusting or self-balancing Binary Search Tree
Cross
Splay Tree
Cross
AVL Tree
Cross
Red Black Tree
Tick
All of the above


Question 6-Explanation: 
Question 7
Consider the following left-rotate and right-rotate functions commonly used in self-adjusting BSTs
T1, T2 and T3 are subtrees of the tree rooted with y (on left side) 
or x (on right side)           
                y                               x
               /      Right Rotation          /  
              x   T3   – - – - – - – >        T1   y 
             /        < - - - - - - -            / 
            T1  T2     Left Rotation            T2  T3
Which of the following is tightest upper bound for left-rotate and right-rotate operations.
Tick
O(1)
Cross
O(Logn)
Cross
O(LogLogn)
Cross
O(n)


Question 7-Explanation: 
The rotation operations (left and right rotate) take constant time as only few pointers are being changed there. Following are C implementations of left-rotate and right-rotate
Question 8

Which of the following is true

Tick

The AVL trees are more balanced compared to Red Black Trees, but they may cause more rotations during insertion and deletion.

Cross

Heights of AVL and Red-Black trees are generally same, but AVL Trees may cause more rotations during insertion and deletion.

Cross

Red Black trees are more balanced compared to AVL Trees, but may cause more rotations during insertion and deletion.

Cross

Heights of AVL and Red-Black trees are generally same, but Red Black trees may cause more rotations during insertion and deletion.



Question 8-Explanation: 

Red Black Tree with n nodes has height <= 2Log2(n+1) AVL Tree with n nodes has height less than Logφ(√5(n+2)) - 2. Therefore, the AVL trees are more balanced compared to Red Black Trees, but they may cause more rotations during insertion and deletion. So if your application involves many frequent insertions and deletions, then Red Black trees should be preferred. And if the insertions and deletions are less frequent and search is more frequent operation, then AVL tree should be preferred over Red Black Tree.

Question 9
Which of the following is true about Red Black Trees?
Tick
The path from the root to the furthest leaf is no more than twice as long as the path from the root to the nearest leaf
Cross
At least one children of every black node is red
Cross
Root may be red
Cross
A leaf node may be red


Question 10
Which of the following is true about AVL and Red Black Trees?
Tick
In AVL tree insert() operation, we first traverse from root to newly inserted node and then from newly inserted node to root. While in Red Black tree insert(), we only traverse once from root to newly inserted node.
Cross
In both AVL and Red Black insert operations, we traverse only once from root to newly inserted node,
Cross
In both AVL and Red Black insert operations, we traverse twiceL first traverse root to newly inserted node and then from newly inserted node to root.
Cross
None of the above


Question 10-Explanation: 
There are 20 questions to complete.

  • Last Updated : 27 Sep, 2023

Share your thoughts in the comments
Similar Reads