Binary Search Tree · Data Structures
32 questions · asked in 17 of 27 years (2000–2026)
MCQ 26 · MSQ 2 · NAT 41-mark 20 · 2-mark 12
2000Questions per year2026
Questions 6–10 of 32
You are given a set of distinct integers. A binary search tree is created by inserting all elements of one by one, starting with an empty tree. The tree follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into , and you do not have access to .
Which one of the following statements is TRUE?
Which one of the following statements is TRUE?
Answer: (A)
For any BST, the inorder traversal lists the keys in sorted order. This is true for every insertion order. So we can get it from V by simply sorting V.
The root, preorder and postorder change with the insertion order. Take V = {1, 2} as an example. If 1 is inserted first and then 2, the root is 1. If 2 is inserted first and then 1, the root is 2.
Answer: Inorder traversal of T can be determined from V
The root, preorder and postorder change with the insertion order. Take V = {1, 2} as an example. If 1 is inserted first and then 2, the root is 1. If 2 is inserted first and then 1, the root is 2.
Answer: Inorder traversal of T can be determined from V
Suppose a binary search tree with 1000 distinct elements is also a complete binary tree. The tree is stored using the array representation of binary heap trees. Assuming that the array indices start with 0, the 3rd largest element of the tree is stored at index _______.
Answer: 509
The tree is complete and has 1000 nodes, so the indices run from 0 to 999. The children of node i are at and .
- Largest: keep going right as far as possible. The path is 0 2 6 14 30 62 126 254 510. The children 1021 and 1022 do not exist, so index 510 holds the largest element.
- 2nd largest: this is the predecessor of 510. Node 510 has no left child, so its predecessor is its parent, which is index 254.
- 3rd largest: this is the maximum of the left subtree of 254. The left child is 509, and its children 1019 and 1020 do not exist, so the maximum is at 509.
Answer: 509
- Largest: keep going right as far as possible. The path is 0 2 6 14 30 62 126 254 510. The children 1021 and 1022 do not exist, so index 510 holds the largest element.
- 2nd largest: this is the predecessor of 510. Node 510 has no left child, so its predecessor is its parent, which is index 254.
- 3rd largest: this is the maximum of the left subtree of 254. The left child is 509, and its children 1019 and 1020 do not exist, so the maximum is at 509.
Answer: 509
A binary search tree T contains n distinct elements. What is the time complexity of picking an element in T that is smaller than the maximum element in T?
Answer: (D)
Check just the root and its children:
- If the root has a right child, then some element is bigger than the root, so the root is not the maximum choose the root.
- If not, the root is the maximum, and its left child is smaller choose the left child.
Only a fixed number of steps is needed .
Answer:
- If the root has a right child, then some element is bigger than the root, so the root is not the maximum choose the root.
- If not, the root is the maximum, and its left child is smaller choose the left child.
Only a fixed number of steps is needed .
Answer:
The preorder traversal of a binary search tree is 15,10,12,11,20,18,16,19. Which one of the following is the postorder traversal of the tree?
Answer: (B)
Construct the BST from the preorder, where the root comes first:
- The root is 15. The left subtree has {10, 12, 11}: 10 has right child 12 which has left child 11.
- The right subtree has {20, 18, 16, 19}: 20 has left child 18 which has children 16 and 19.
Postorder (left, right, root): 11, 12, 10, 16, 19, 18, 20, 15
Answer: 11, 12, 10, 16, 19, 18, 20, 15
- The root is 15. The left subtree has {10, 12, 11}: 10 has right child 12 which has left child 11.
- The right subtree has {20, 18, 16, 19}: 20 has left child 18 which has children 16 and 19.
Postorder (left, right, root): 11, 12, 10, 16, 19, 18, 20, 15
Answer: 11, 12, 10, 16, 19, 18, 20, 15
Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are :
Note: The height of a tree with a single node is 0.
Note: The height of a tree with a single node is 0.
Answer: (B)
Let us check both cases:
- Minimum height: take a complete tree. 15 nodes fill levels 0 to 3 (1 + 2 + 4 + 8) so the height is 3.
- Maximum height: take a chain of 15 nodes so the height is 14.
Answer: 3 and 14 respectively
- Minimum height: take a complete tree. 15 nodes fill levels 0 to 3 (1 + 2 + 4 + 8) so the height is 3.
- Maximum height: take a chain of 15 nodes so the height is 14.
Answer: 3 and 14 respectively
Keep practising
Topics in Data Structures
ArrayStackQueueLink ListBinary Treen-ary Tree
Binary Search TreeYou are here
AVL TreeHeap TreeB TreeB plus TreeHashing