Question:

What is the time complexity of inserting an element into a balanced binary search tree?

Show Hint

Balanced BSTs ensure $O(\log n)$ for operations by maintaining height constraints.
Updated On: Jun 18, 2025
  • $O(\log n)$
  • $O(n)$
  • $O(n \log n)$
  • $O(1)$
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

In a balanced binary search tree (e.g., AVL or Red-Black tree):
- The height is $O(\log n)$ due to balancing properties.
- Insertion involves traversing from root to leaf to find the insertion point, which takes $O(\log n)$.
- After insertion, rebalancing (rotations) takes $O(\log n)$ in worst case.
Thus, total time complexity is $O(\log n)$.
Option (1) is correct.
Was this answer helpful?
0
0