Data Structures & AlgorithmsHardGATE CS · ICPC regional

Distinct keys are inserted in this order into an empty binary search tree: 25 45 51 93 63 52 92 61 84. A search is run for the key 84 (which is present), starting at the root. How many nodes are examined, counting each node whose key is compared with the search key (a missing child is not a node)?

  1. A. 6
  2. B. 4
  3. C. 1
  4. D. 7

Correct answer: D. 7

The path is 25 → 45 → 51 → 93 → 63 → 92 → 84: 7 nodes compared. Counting edges gives 6, assuming a balanced tree gives ⌈log₂ 10⌉ = 4, and 1 would mean 84 is the root.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic