in Algorithms
249 views
2 votes
2 votes

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
in Algorithms
by
249 views

3 Answers

6 votes
6 votes
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 .

edited by
by

4 Comments

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

0
0
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?
0
0

@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.

2
2
1 vote
1 vote
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
0 votes
0 votes
is max heap sorted array in decreasing order or increasing order...????????
Answer:

Related questions