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?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2021 Set 1 · Q10
Time
Select one answerSingle correct
Solution
Official answer: D) (1)
Binary Search TreesLet be a binary search tree with distinct elements with root .
We need to find any element that is strictly smaller than the maximum element in :
If has a left child (or left subtree): Any node in the left subtree is smaller than . Therefore, the left child of is strictly smaller than , which means it must be strictly smaller than the maximum element of .
If does not have a left child: Since , must have a right child. All nodes in the right subtree are strictly greater than . Thus, is strictly smaller than all elements in its right subtree, including the maximum element.
In either case, we only need to inspect the root and potentially its left child, which takes a constant number of operations: .
Therefore, the time complexity is (Option D).
Try the question first, then check your work.
Examiner trap
Consider the root of the BST. Does the root (or one of its direct children) provide an element strictly smaller than the maximum element without needing to traverse the tree?
This Binary Search Trees previous year question is Q10 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Binary Search Trees in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Search Trees PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Binary Search Trees has 21 GATE CSE PYQs across 17 papers from 2011 to 2026. 8 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 1.
How GATE tests Binary Search TreesIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.