Top MCQs on Binary Search Tree (BST) Data Structure with Answers

A Binary Search Tree (BST) is a special type of binary tree in which the left child of a node has a value less than the node’s value and the right child has a value greater than the node’s value. This property is called the BST property and it makes it possible to efficiently search, insert, and delete elements in the tree.
More on BST

Quiz On BST

Quiz On BST

Question 1

What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree for a skewed tree ?

Tick

O(n) for all

Cross

O(Logn) for all

Cross

O(Logn) for search and insert, and O(n) for delete

Cross

O(Logn) for search, and O(n) for insert and delete



Question 1-Explanation: 

In skewed Binary Search Tree (BST), all three operations can take O(n). See the following example BST and operations.

          10
        /
       20
      /
     30
    / 
   40

Search 40. 
Delete 40
Insert 50.
Question 2

In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?

Cross

Inorder Successor is always a leaf node

Tick

Inorder successor is always either a leaf node or a node with empty left child

Cross

Inorder successor may be an ancestor of the node

Cross

Inorder successor is always either a leaf node or a node with empty right child



Question 2-Explanation: 

Let X be the node to be deleted in a tree with root as \'root\'. There are three cases for deletion 1) X is a leaf node: We change left or right pointer of parent to NULL (depending upon whether X is left or right child of its parent) and we delete X 2) One child of X is empty: We copy values of non-empty child to X and delete the non-empty child 3) Both children of X are non-empty: In this case, we find inorder successor of X. Let the inorder successor be Y. We copy the contents of Y to X, and delete Y. So, we need inorder successor only when both left and right child of X are not empty. In this case, the inorder successor Y can never be an ancestor of X. In this case, the inorder successor is the leftmost node in right subtree of X. Since it is leftmost node, the left child of Y must be empty.

Question 3

We are given a set of n distinct elements and an unlabelled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree? (GATE CS 2011)

Cross

0

Cross

1

Cross

n!

Tick

(1/(n+1)).2nCn



Question 3-Explanation: 

There is only one way. The minimum value has to go to the leftmost node and the maximum value to the rightmost node. Recursively, we can define for other nodes.

Additionally, the number of distinct binary search trees possible for n nodes is similar to counting the number of distinct binary trees possible for n nodes assuming nodes are unlabeled. Hence, this value will also be 2nCn/(n+1).

Question 4

How many distinct binary search trees can be created out of 4 distinct keys?

Cross

4

Tick

14

Cross

24

Cross

42



Question 4-Explanation: 

number of distinct BSTs = (2n)!/[(n+1)!*n!] .

Question 5

Which of the following traversal outputs the data in sorted order in a BST?

Cross

Preorder

Tick

Inorder

Cross

Postorder

Cross

Level order



Question 5-Explanation: 

Inorder traversal of a BST outputs data in sorted order. 

Question 6
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?
Cross
7 5 1 0 3 2 4 6 8 9
Cross
0 2 4 3 1 6 5 9 8 7
Tick
0 1 2 3 4 5 6 7 8 9
Cross
9 8 6 4 2 3 0 1 5 7


Question 6-Explanation: 
In-order traversal of a BST gives elements in increasing order. So answer c is correct without any doubt.
Question 7

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)? (GATE CS 2004)
 

Cross

2
 

Tick

3
 

Cross

4
 

Cross

6
 



Question 7-Explanation: 

Constructed binary search tree will be.



 

Question 8

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

Cross

10, 20, 15, 23, 25, 35, 42, 39, 30

Cross

15, 10, 25, 23, 20, 42, 35, 39, 30

Cross

15, 20, 10, 23, 25, 42, 35, 39, 30

Tick

15, 10, 23, 25, 20, 35, 42, 39, 30



Question 8-Explanation: 

The following is the constructed tree
 

 

Question 9

Consider the following Binary Search Tree
 

 

If we randomly search one of the keys present in above BST, what would be the expected number of comparisons?

Cross

2.75

Cross

2.25

Tick

2.57

Cross

3.25



Question 9-Explanation: 

Expected number of comparisons = (1*1 + 2*2 + 3*3 + 4*1)/7 = 18/7 = 2.57

Question 10
Which of the following traversals is sufficient to construct BST from given traversals 1) Inorder 2) Preorder 3) Postorder
Cross
Any one of the given three traversals is sufficient
Tick
Either 2 or 3 is sufficient
Cross
2 and 3
Cross
1 and 3


Question 10-Explanation: 
When we know either preorder or postorder traversal, we can construct the BST. Note that we can always sort the given traversal and get the inorder traversal. Inorder traversal of BST is always sorted.
There are 41 questions to complete.


  • Last Updated : 27 Sep, 2023

Share your thoughts in the comments
Similar Reads