Question

Suppose the values 10,−4,15,30,20,5,60,1910, -4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let TT be the resulting binary search tree. The number of edges in the path from the node containing 1919 to the root node of TT is ___________. (Answer in integer)

Official answer and solution
Official answer
4
From
Official GATE 2025 answer key

Solution

Insert the keys sequentially into the BST and count the edges from the root 10 down to 19.

Inserting 10,−4,15,30,20,5,60,1910, -4, 15, 30, 20, 5, 60, 19 into an initially empty BST:

  • 10 becomes the root (depth 00).
  • -4 goes to the left of 10; 5 goes to the right of -4.
  • 15 goes to the right of 10 (depth 11).
  • 30 goes to the right of 15 (depth 22).
  • 20 goes to the left of 30 (depth 33); 60 goes to the right of 30.
  • 19 goes to the left of 20 (depth 44).

The unique path from 19 to the root 10 is 19→20→30→15→1019 \rightarrow 20 \rightarrow 30 \rightarrow 15 \rightarrow 10, which contains 44 edges.

Final answer

4

Common trap

Counting the number of nodes (5) on the path instead of the number of edges (4).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2025 Computer Science and Information Technology - Session 2 (CS2)
Question
35 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.