LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

In the binary search tree with root 6, children 2 and 9, 2's children 1 and 4, and 9's left child 8, which nodes does TreeSearch(4, root) visit, and where does TreeSearch(5, root) end?

TreeSearch(4) visits 6, 2 and 4: 4 < 6 goes left, 4 > 2 goes right, 4 = 4 is found. TreeSearch(5) follows the same path and then goes right from 4 (5 > 4), ending at 4's right external node: 5 is not in the tree.

Two copies of the search tree: the path 6, 2, 4 highlighted for TreeSearch(4), and the path continuing to 4's right external node for TreeSearch(5)

* A search follows one root-to-leaf path; a miss ends at the external node where the key belongs. *

Search At 6 At 2 At 4 Result
TreeSearch(4) 4 < 6: left 4 > 2: right equal the internal node 4
TreeSearch(5) 5 < 6: left 5 > 2: right 5 > 4: right 4's right external node

Both searches inspect three keys and never touch 1, 9 or 8: the first comparison at the root already excludes the entire right subtree.

The unsuccessful search is just as useful as the successful one. It names the external node where 5 would have to be, which is exactly where insert(5) will put it.

From Quiz: ADS / Binary Search Trees | Updated: Dec 01, 2026