recategorized by
1,007 views
0 0 votes
The time complexity of the most efficient algorithm to determine whether an arbitrary array of size ‘n’, is min-heap or not?

(A) O(log n)

(B) O(n)

(C) O(n logn)

(D) O(1)

1 Answer

2 2 votes

Time complexity is O(n). We can visualize it using  traversal of Binary Tree.

We just check the root and its immediate descendent (not all the children) and return the result whether the root is smaller then its immediate children or not.

Similarly we proceed to the next levels and perform the same procedure. Check whether the root is smaller than immediate descendent or not. In this way we can check the entire tree in O(n) time. In this way we can say whether tree is mean - heap or not.

NOTE:- Dont check all the children for a root. It would increase the complexity to O(n^2)

Answer:
Position:
Show:

Related questions

1 1 vote
1 answers 1 answer
3.3k
3.3k views
gmrishikumar asked Dec 1, 2018
3,331 views
What is the time complexity to find the Kth largest element in a Min-Heap? Or equivalently, What is the time complexity to find Kth smallest element in Max-Heap?
6 6 votes
2 answers 2 answers
6.4k
6.4k views
Shivam Chauhan asked Oct 31, 2017
6,418 views
In a min-heap, the next largest element of a particular element can be found in ___ time.A) O(1)B) O(log n)C) O(n)
8 8 votes
3 3 answers
5.8k
5.8k views
Kapil asked Sep 4, 2016
5,796 views
In a min-heap with n elements1). The 7th smallest element can be found in time, if duplicates are allowed ?2). The 7th distinct smallest element can be found in time, I...
11 11 votes
5 answers 5 answers
5.9k
5.9k views
Vikrant Singh asked Dec 28, 2014
5,931 views
What is the complexity of finding $50^{th}$ smallest element in an already constructed binary min-heap?$\Theta(1)$$\Theta (\log n)$$\Theta (n)$$\Theta (n \log n)$