GATE 2025 CS (CS2) – Question 35
Suppose the values $10, -4, 15, 30, 20, 5, 60, 19$ are inserted in that order into an initially empty binary search tree. Let $T$ be the resulting binary search tree.
The number of edges in the path from the node containing 19 to the root node of $T$ is ___________. (Answer in integer)
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 4
Explanation
Insert into an initially empty BST in this order: 10, $-4$, 15, 30, 20, 5, 60, 19.
- 10 is the root.
- $-4<10$: left child of 10.
- $15>10$: right child of 10.
- $30>10$, $>15$: right child of 15.
- $20>10,>15$, $<30$: left child of 30.
- $5<10$, $>-4$: right child of $-4$.
- $60>30$: right child of 30.
- $19>10,>15,<30,<20$: left child of 20.
Path from 19 to the root: $19\to20\to30\to15\to10$, which has **4** edges.