What is the space complexity of searching in a heap?

Category: QuestionsWhat is the space complexity of searching in a heap?
Editor">Editor Staff asked 5 months ago

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 I
 
I had been asked this question in an interview for internship.

1 Answers
Editor">Editor Staff answered 5 months ago

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).


Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17
Articles: 40702