In a balanced binary search tree with n elements, what is the worst case time complexity of reporting all elements in range [a, b]? Assume that the number of reported elements is k.
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2020 · Q41
Time
Select one answerSingle correct
Solution
Official answer: B) (log n + k)
Binary Search TreesTo perform a range query in a balanced binary search tree with elements:
Finding the range boundary: Searching for the first element (or the lowest common ancestor / split node) takes time proportional to the height of the balanced BST, which is .
Reporting elements: An in-order traversal is performed to collect all keys within . Visiting each of the relevant nodes and traversing up to boundary edges takes additional time.
Thus, the total worst-case time complexity is .
*(Note: Option D continues onto the next page and is not visible on this page. The question is marked as incomplete.)*
Try the question first, then check your work.
Examiner trap
The height of a balanced BST with nodes is . Finding the start of the range takes logarithmic time, after which reporting elements takes proportional time.
This Binary Search Trees previous year question is Q41 of the GATE CSE 2020 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. 6 of them are 2-mark MCQs like this one, and GATE CSE 2020 has 2.
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.