Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Insert the keys 50, 20, 70, 10, 30, 60, 90, 25, 35, 65 into a binary search tree in this order. How many keys in the tree lie in the closed range [25, 65]?

  1. A. 4
  2. B. 6
  3. C. 10
  4. D. 5

Correct answer: B. 6

A range search visits only subtrees that can hold keys in [25, 65]: 25, 30, 35, 50, 60, 65 → 6. Excluding both endpoints gives 4, using a half-open range gives 5, and 10 counts every key.

More Coding Interview Problems questions

Exams that ask this topic