277 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

## 3 Answers

Best answer

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

### 4 Comments

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?

@shraddha priya

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...????????
Answer:

2 votes
1 answer
1
420 views
2 votes
1 answer
2
3 votes
1 answer
3
488 views
2 votes
2 answers
4