What is the time complexity of searching in a balanced Binary Search Tree?
- A.O(1)
- B.O(log n)
- C.O(n)
- D.O(n log n)
Show answer
Answer: B. O(log n)
In a balanced BST, the height is O(log n), so search requires O(log n) comparisons.
5 published questions in this subject.
What is the time complexity of searching in a balanced Binary Search Tree?
Answer: B. O(log n)
In a balanced BST, the height is O(log n), so search requires O(log n) comparisons.
Which sorting algorithm has the best average-case time complexity?
Answer: B. Merge Sort O(n log n)
Merge Sort consistently achieves O(n log n) time complexity in all cases (best, average, worst).
In a max-heap with n elements, what is the minimum number of comparisons needed to find the minimum element?
Answer: D. O(n)
In a max-heap, the minimum is always a leaf node. All leaves must be checked: O(n/2) ≈ O(n).
Which data structure is used internally by a recursive function?
Answer: C. Stack
Function calls use the call stack — each recursive call pushes a new frame, and returns pop frames.
Which of the following is a stable sorting algorithm?
Answer: C. Merge Sort
Merge Sort is stable — equal elements maintain their relative order. Heap Sort and Quick Sort are not stable.