Hai i have just started learning Data Structures.Please help me... Suppose i have a max heap of arr[1....n].arr[1] stores the maximum element. Is there any way in which i can find the second largest element in the array. we are not supposed to change the heap asked 29 Mar '14, 23:54

The maxheap is a tree structure in which the root contains the maximum element and value of each node is greater than the value of its children. The maxheap is stored as an array. So as the first element or the first index stores the maximum element of the maxheap. The second largest element of the heap is either of the two children of the max node i.e. either node 2 or node 3. Check the one which is bigger. answered 30 Mar '14, 00:11
Thanks a lot!!
(30 Mar '14, 22:01)
1
@bipin2 Your welcome! Please accept the solution if you are satisfied so that the question could be closed.
(31 Mar '14, 14:02)
Sorry....I forget that..:)
(01 Apr '14, 19:14)

If you are using a priority_queue , this can be done very easily.
If you need more clarifications just leave a comment below. answered 30 Mar '14, 00:24
thanks....but i wanted to the array to remain the same....or we can take 2 temporary variables and the pop and pop and then push back the 2 temporary variables right?
(30 Mar '14, 22:03)
@bipin2 Yes you can do that.
(01 Apr '14, 00:29)
