What are the worst case and average case complexities of a binary search tree?

Thê Hy

New member
What are the worst case and average case complexities of a binary search tree?
A. O(n), O(n)
B. O(logn), O(logn)
C. O(logn), O(n)
D. O(n), O(logn)
 
Answer: D
Explanation: Worst case arises when the tree is skewed(either to the left or right) in which case you have to process all the nodes of the tree giving O(n) complexity, otherwise O(logn) as you process only the left half or the right half of the tree.
 

Tìm kiếm

Back
Top