Data Structures & AlgorithmsModerateTCS NQT · data structures

Problem: What is the cost of inserting into a binary search tree that is perfectly balanced with n nodes?

  1. A. O(n)
  2. B. O(1)
  3. C. O(log n)
  4. D. O(n log n)

Correct answer: C. O(log n)

The tree height is logarithmic, so insertion follows one root-to-leaf path.

More Coding Interview Problems questions

Exams that ask this topic