Binary Search & Balanced Trees

Answer & solution
Official answer: 4
Step through it (10 steps)
Insert by comparing each new key with the nodes on its search path. The first key 10 becomes the root. −4 is its left child and 15 its right child. Next 30 becomes the right child of 15; 20 becomes the left child of 30. The key 5 goes right of −4, and 60 goes right of 30.
For 19, compare with 10: go right. Compare with 15: go right. Compare with 30: go left. Compare with 20: go left and insert there. Thus its root path is 10→15→30→20→19.
There are five nodes on that path but four edges, so the requested distance is 4. This is its depth when the root has depth zero. The left branch containing −4 and 5, and the right branch containing 60, do not contribute to this path. Answer: 4.





