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 1–5 of 32
Let be the set of all integers from to . Consider any order of insertion of the elements of into a binary search tree that creates a complete binary tree.
Which one of the following elements can NEVER be the third element that is inserted?
Which one of the following elements can NEVER be the third element that is inserted?
Answer: (D)
A complete binary tree on 15 keys is a perfect tree with 4 levels. As a BST on it is fixed: root 8; level 1: 4, 12; level 2: 2, 6, 10, 14; leaves: 1, 3, 5, 7, 9, 11, 13, 15.
A key can only be inserted after all its ancestors, since otherwise it would take the place of one of them. So an order gives this tree exactly when every key comes after its parent.
The 1st key is 8. The 2nd is 4 or 12. The 3rd is either the other level-1 key, or a child of the 2nd key. So the possible third keys are 2, 4, 6, 10, 12, 14.
For example 4 (order 8, 12, 4), 2 (order 8, 4, 2) and 10 (order 8, 12, 10) can all be third.
5 is the child of 6, whose parent is 4, whose parent is 8. The three keys 8, 4 and 6 must go in before 5, so 5 can be inserted 4th at the earliest. It can never be third.
Answer: (D)
A key can only be inserted after all its ancestors, since otherwise it would take the place of one of them. So an order gives this tree exactly when every key comes after its parent.
The 1st key is 8. The 2nd is 4 or 12. The 3rd is either the other level-1 key, or a child of the 2nd key. So the possible third keys are 2, 4, 6, 10, 12, 14.
For example 4 (order 8, 12, 4), 2 (order 8, 4, 2) and 10 (order 8, 12, 10) can all be third.
5 is the child of 6, whose parent is 4, whose parent is 8. The three keys 8, 4 and 6 must go in before 5, so 5 can be inserted 4th at the earliest. It can never be third.
Answer: (D)
The following sequence corresponds to the preorder traversal of a binary search tree :
The position of the element in the postorder traversal of is ________ . (answer in integer)
Note: The position begins with .
The position of the element in the postorder traversal of is ________ . (answer in integer)
Note: The position begins with .
Answer: 7
Build the BST from the preorder . In preorder the root comes first. Smaller values go to the left subtree and larger values go to the right subtree.
The root is . The left subtree has values : . The right subtree has values : .
Left subtree: the root is . Its left child is , a leaf. Its right subtree is , with root , left child and right child .
Right subtree: the root is . Its left subtree has root with only a right child (no left child). Its right subtree has root with only a left child (no right child).
Now take the postorder (left, right, root) of the whole tree:
The -subtree gives:
The -subtree gives:
Last comes the root .
Full postorder:
Count positions from . Then is element number .
Answer: 7
The root is . The left subtree has values : . The right subtree has values : .
Left subtree: the root is . Its left child is , a leaf. Its right subtree is , with root , left child and right child .
Right subtree: the root is . Its left subtree has root with only a right child (no left child). Its right subtree has root with only a left child (no right child).
Now take the postorder (left, right, root) of the whole tree:
The -subtree gives:
The -subtree gives:
Last comes the root .
Full postorder:
Count positions from . Then is element number .
Answer: 7
Consider a binary search tree (BST) with leaf nodes . Given any node , the key present in the node is denoted as . All the keys present in the given BST are distinct. The keys belong to the set of real numbers.
For a node , let denote the node that is its inorder successor. If a node does not have an inorder successor, then is . As there are no duplicates, if is not , then .
Corresponding to every leaf node that has a non-NULL , a new key with the following property is to be inserted into the BST.
Let represent the list of all such new keys to be inserted into the BST.
Which of the following statements is/are true?
For a node , let denote the node that is its inorder successor. If a node does not have an inorder successor, then is . As there are no duplicates, if is not , then .
Corresponding to every leaf node that has a non-NULL , a new key with the following property is to be inserted into the BST.
Let represent the list of all such new keys to be inserted into the BST.
Which of the following statements is/are true?
One or more options are correct.
Answer: (A), (C)
(A) True. Each new key lies strictly between two keys that are neighbours in the in-order sequence: a leaf and its successor. Different leaves give different neighbour pairs, so these intervals do not overlap and no two new keys can be equal.
(B) False. In a tree with one node, that node is the only leaf and has no in-order successor. No key is added and is empty.
(C) True. Take with . No key lies between these two, so is compared with every other key just as is. So the search reaches , and because it goes right. A leaf has no right child, so becomes the right child of . Each leaf gets at most one new child, so every path grows by at most 1 and the height rises by at most 1.
(D) False. At most one node is added per leaf, so at most new nodes. A tree with more than one node also has internal nodes, so its node count is more than . Then at most new nodes cannot double it. A single node tree gets no new node.
Answer: (A), (C)
(B) False. In a tree with one node, that node is the only leaf and has no in-order successor. No key is added and is empty.
(C) True. Take with . No key lies between these two, so is compared with every other key just as is. So the search reaches , and because it goes right. A leaf has no right child, so becomes the right child of . Each leaf gets at most one new child, so every path grows by at most 1 and the height rises by at most 1.
(D) False. At most one node is added per leaf, so at most new nodes. A tree with more than one node also has internal nodes, so its node count is more than . Then at most new nodes cannot double it. A single node tree gets no new node.
Answer: (A), (C)
Which of the following statement(s) is/are TRUE for any binary search tree (BST) having distinct integers?
One or more options are correct.
Answer: (A), (B)
We check each statement for a BST with distinct integers.
- The longest path from the root to any node is : True. In the worst case the BST is fully skewed (degenerate), like a linked list. All nodes lie in one chain. The path from the root to the deepest node then has edges. It can never be longer, because the tree has only nodes.
- Inorder traversal always gives sorted order: True. This is the main property of a BST: left subtree node right subtree, applied at every level. It holds for any tree shape.
- Finding an element takes time in the worst case: False. This bound holds only for a balanced BST. A skewed (degenerate) BST, as seen above, can push the search time up to .
- Every BST is also a Min-Heap: False. A min-heap needs every parent to be smaller than both children. A BST only orders the nodes as left parent right. So a BST can break the heap order.
Answer: The maximum path length is n-1, and inorder traversal always gives sorted order.
- The longest path from the root to any node is : True. In the worst case the BST is fully skewed (degenerate), like a linked list. All nodes lie in one chain. The path from the root to the deepest node then has edges. It can never be longer, because the tree has only nodes.
- Inorder traversal always gives sorted order: True. This is the main property of a BST: left subtree node right subtree, applied at every level. It holds for any tree shape.
- Finding an element takes time in the worst case: False. This bound holds only for a balanced BST. A skewed (degenerate) BST, as seen above, can push the search time up to .
- Every BST is also a Min-Heap: False. A min-heap needs every parent to be smaller than both children. A BST only orders the nodes as left parent right. So a BST can break the heap order.
Answer: The maximum path length is n-1, and inorder traversal always gives sorted order.
Suppose the values 10, -4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let be the resulting binary search tree. The number of edges in the path from the node containing 19 to the root node of is ___________. (Answer in integer)
Answer: 4
Put each value into the BST one by one. Go left if the value is smaller than the current node, and go right if it is larger:
(root), then (left of ), then (right of ), then (right of ), then (left of ), then (right of ), then (right of ), then (left of ).
Path from up to the root: . This has edges.
Answer: 4
(root), then (left of ), then (right of ), then (right of ), then (left of ), then (right of ), then (right of ), then (left of ).
Path from up to the root: . This has edges.
Answer: 4
Keep practising
Topics in Data Structures
ArrayStackQueueLink ListBinary Treen-ary Tree
Binary Search TreeYou are here
AVL TreeHeap TreeB TreeB plus TreeHashing