Question:

A binary search tree \( T \) contains \( n \) distinct elements. What is the time complexity of picking an element in \( T \) that is smaller than the maximum element in \( T \)?

Show Hint

If a problem only requires selecting any valid element and not searching for a specific one, the operation can often be done in constant time.
Updated On: Jan 30, 2026
  • \( \Theta(n \log n) \)
  • \( \Theta(n) \)
  • \( \Theta(\log n) \)
  • \( \Theta(1) \)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understanding the question.
The question asks for the time required to pick any element that is smaller than the maximum element in a binary search tree.

Step 2: Key observation.
In a BST with distinct elements, the maximum element is the rightmost node. Any other node in the tree automatically satisfies the condition of being smaller than the maximum.

Step 3: Time complexity.
We can simply pick the root (or any arbitrary node other than the maximum) without performing any traversal or comparison. This operation takes constant time.

Step 4: Conclusion.
Thus, the time complexity is \( \Theta(1) \).

Was this answer helpful?
0
0

Top Questions on Trees

View More Questions