GATE 2020 CS – Question 51
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$.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (B) $\Theta(\log n+k)$
Explanation
Locating $a$ and $b$ takes $O(\log n)$, and an in-order traversal of the reported elements takes $O(k)$. Total $\Theta(\log n+k)$.