Question
Suppose the values 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 to the root node of 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 into an initially empty BST:
10becomes the root (depth ).-4goes to the left of10;5goes to the right of-4.15goes to the right of10(depth ).30goes to the right of15(depth ).20goes to the left of30(depth );60goes to the right of30.19goes to the left of20(depth ).
The unique path from 19 to the root 10 is , which contains edges.
4
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.