1.

What is the space complexity of searching in a heap?(a) O(logn)(b) O(n)(c) O(1)(d) O(nlogn)This interesting question is from Binary Heap topic in portion Heap of Data Structures & Algorithms II had been asked this question in an interview for internship.

Answer»

The correct choice is (B) O(n)

Easiest explanation - The SPACE complexity of searching an ELEMENT in heap is O (n). Heap consists of n elements and we NEED to compare every element. Here no ADDITION or deletion of elements takes place. Hence space complexity is O (n).



Discussion

No Comment Found

Related InterviewSolutions