1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to check whether an array represents max heap

Tags:
  1. Dec 26, 2014 #1
    1. The problem statement, all variables and given/known data
    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

    2. Relevant equations


    3. 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)
     
  2. jcsd
  3. Dec 29, 2014 #2

    Stephen Tashi

    User Avatar
    Science Advisor

    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"?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: How to check whether an array represents max heap
Loading...