239 views
0 votes
0 votes
I got HEAP DS as a ADT(abstract data type). Means i can perform few operations on it like getMin(),getMax(),deleteRoot() etc.

So if i have to get 2nd smallest in min heap then it will be in 2nd level definitely. so should i approach it as make a level order traversal and get it in O(1) time. or i should take it as standard way like delete root, hepify ,getRoot() ,insert() deleted item=O(2Logn) ?

 

I found a prev. gate question as find 7th min in min heap, and all answers are O(1).

1 Answer

0 votes
0 votes
in a heap only getmin() or getmax(), insertion  can be performed. if u are doing any other operation , then the ds cannot be treated as heap. so you should  use only getmin() 7 times to  get 7th minimum element

Related questions

2 votes
2 votes
1 answer
1
radha gogia asked Dec 10, 2015
1,606 views
If I have n elements in the heap then why does the index of leaf nodes ranges from index ⌊n/2⌋+1 to index n ?