Suppose the values 10, −4, 15, 30, 20, 5, 60, 19 are inserted in that order…
2025
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)
Attempted by 130 students.
Show answer & explanation
Correct answer: 4
Solution: Build the binary search tree by inserting the values in the given order and then find the path from the node containing 19 up to the root.
Insert 10: becomes the root.
Insert -4: goes to the left of 10.
Insert 15: goes to the right of 10.
Insert 30: compare with 10 (right), then with 15 (right), so it becomes the right child of 15.
Insert 20: go right from 10 to 15, right to 30, then 20 is less than 30, so it becomes the left child of 30.
Insert 5: go left from 10 to -4, then 5 is greater than -4, so it becomes the right child of -4.
Insert 60: go right from 10 to 15 to 30, then 60 is greater than 30, so it becomes the right child of 30.
Insert 19: go right from 10 to 15 to 30, then left to 20, and 19 is less than 20, so it becomes the left child of 20.
Therefore the path from the node containing 19 up to the root is:
19
20
30
15
10 (root)
Count the edges along this path: there are 5 nodes on the path, so the number of edges is 4.
Answer: 4
A video solution is available for this question — log in and enroll to watch it.