279 views

Is an array that is sorted in decreasing order a max-heap?

1. always yes
2. always no
3. sometimes only
4. yes but not in presence of duplicates

Always Yes

Every array which is sorted in ascending order is always a min heap

And Every array which is sorted in descending order is always a max heap .

by

@Kapil

I think u have written in reverse manner

array with ascending order results in : Min Heap

and with descending order results in: Max Heap
Yes you are right and beside this question is wrong if you say decreasing order then duplicate cannot be in it else it should be non increasing order

i think max sorted in ascending order.....!!!!!!!!check out https://stackoverflow.com/questions/41212072/ascending-and-descending-heapsort

Why not option D? Root of subtrees of maxheap should be larger than children but in case of duplicate values this will be violated, right?

Yes, they can. You can read about this in 'Introduction to Algorithms' (by Charles E. Leiserson, Clifford Stein, Thomas H. Cormen, and Ronald Rivest). According to the definition of binary heaps in Wikipedia:

All nodes are either [greater than or equal to](max heaps) or [less than or equal to](min heaps) each of its children, according to a comparison predicate defined for the heap.

converse of this statement is not always true.

every array which is sorted in descending order is Max heap.

every heap may not be always sorted in descending order array. e-g - 20 18 12 16 15 10 9
by
is max heap sorted array in decreasing order or increasing order...????????