How to check whether an array represents max heap

  • #1
142
1

Homework Statement


Does the following array represents the binary max heap
99,98,97,55,49,49,48,13,54
99,98,97,55,54,49,49,48,13

Homework Equations




The Attempt at a Solution


I've tried to construct the tree structure and all the above array representation satisfies the binary max heap property. But ans is given as no (i.e non of them represents the binary max heap)
 

Answers and Replies

  • #2
Stephen Tashi
Science Advisor
7,580
1,470
After glancing at the method or representing heaps as arrays and looking up the definition of a max heap, I think your answer is correct (i.e. each array does represent a max heap).

However, the grammer in the statement of the problem is peculiar. I think the problem should say "Do the following arrays represent a binary max heap?". That version is still not clear. It would be clear if it said "For each of the following arrays, tell whether the array represents a binary max heap." Is it possible that there is only supposed to be a single array and that a comma was omitted after "54"?
 

Related Threads on How to check whether an array represents max heap

Replies
3
Views
724
Replies
3
Views
831
  • Last Post
Replies
0
Views
977
Replies
5
Views
3K
Replies
3
Views
998
  • Last Post
Replies
2
Views
1K
Replies
1
Views
1K
Replies
1
Views
649
  • Last Post
2
Replies
26
Views
3K
Replies
0
Views
1K
Top