IAE Academy

GATE 2025 CS1 Q.26: solution and answer

GATE 2025 · CS1Q.26 · 1 mark · MSQ

Which of the following statement(s) is/are TRUE for any binary search tree (BST) having distinct integers?

  1. (A)

    The maximum length of a path from the root node to any other node is .

  2. (B)

    An inorder traversal will always produce a sorted sequence of elements.

  3. (C)

    Finding an element takes time in the worst case.

  4. (D)

    Every BST is also a Min-Heap.

See the question in the paper

Answer and solution

ANSWER

The answer is (A) and (B). A root-to-node path in an -node tree can have at most edges, and an inorder traversal of any BST gives its keys in sorted order.

Official answer: A, BSource: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. Option A (TRUE). A path from the root down to any node is a simple path, so it visits each node at most once. The tree has only nodes, so such a path has at most nodes and at most edges. This limit is actually reached: insert in increasing order to get a right-skewed BST, and the path from the root to the node has exactly edges. So for every BST on distinct keys, the longest a root-to-node path can be is . The statement gives this upper bound. It does not claim that every BST has height .

  2. Option B (TRUE). At every node, all keys in the left subtree are smaller than the node's key and all keys in the right subtree are larger. An inorder traversal visits the left subtree, then the node, then the right subtree. By induction on the subtree size, each subtree is output in increasing order, then the node's key, which is larger than everything already printed and smaller than everything still to come. So the whole sequence is sorted in increasing order, whatever the shape of the tree.

  3. Option C (FALSE). A search follows one root-to-leaf path, so its worst-case cost is proportional to the height of the tree. In the skewed BST from option A the height is , and searching for (or for any key greater than ) takes comparisons. That is , not . The bound holds only for a balanced BST, such as an AVL or red-black tree.

  4. Option D (FALSE). A min-heap needs every parent its children. In a BST, a left child is always smaller than its parent. Take the BST with root , left child and right child : the parent is greater than its child , so the min-heap property fails. Any BST where some node has a left child breaks the min-heap property in the same way.

  5. The statements that hold for every BST on distinct integers are (A) and (B).

KEY IDEA

A root-to-node path cannot repeat a node, so in any -node tree it has at most edges. A skewed BST reaches that limit. Inorder traversal of a BST (left, node, right) always gives the keys in sorted order. Search cost depends on the height, which can be as large as , so an unbalanced BST has worst-case search. A left child is always smaller than its parent, so a BST with any left child cannot be a min-heap.

WATCH OUT FOR

The common mistake is to read (A) as "every BST has height " and reject it because a balanced BST is only deep. The statement gives the largest length a root-to-node path can have in any BST, and is that upper bound. It is reached by a skewed tree. A second mistake is to accept (C) by assuming the BST is balanced. A plain BST has no such guarantee.

From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 26 Trees & heaps questions, with notes

More Trees & heaps questions