Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Distinct keys are inserted in this order into an empty binary search tree: 26 41 30 45 83 99 61. A search is run for the key 40 (which is absent), 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. 4
  2. B. 2
  3. C. 3
  4. D. 5

Correct answer: C. 3

Follow the search path from the root, one node per comparison: it examines 3 nodes. Counting the missing child as a node, or counting edges instead of nodes, shifts the answer by one.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic