Binary search trees

Which keys are visited when searching for 5?

Examples

Worked example

Input
Root 8, left child 3, right child 10, and 3 has right child 5.
Expected output
8 → 3 → 5

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

At 8, go left because 5 is smaller. At 3, go right because 5 is larger.

Back to the lesson