Wednesday, February 16, 2011

A max-heap is a heap where the value of each parent is greater than or equal to the values of its children. Which of the following is a max-heap?



8 comments:

  1. both a and b are right but i think k heap tree must be complete binary tree so ans is b..is it??

    ReplyDelete
  2. I think, No one is a max-heap..
    right???

    ReplyDelete
  3. @monthan Y u think so??
    @khushbu answers on tomorrow..

    ReplyDelete
  4. Sory bhai ans is only one.. so do more research on heap tree..

    ReplyDelete
  5. yup agree with prashant A & B both.....

    ReplyDelete
  6. Answer is B coz A is not a complete binary tree.

    ReplyDelete
  7. Monthan is write..
    Answer: (B)
    A binary tree is max-heap if it is a complete binary tree (A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible) and it follows the max-heap property (value of each parent is greater than or equal to the values of its children).

    A) is not a max-heap because it is not a complete binary tree
    B) is a max-heap because it is complete binary tree and follows max-heap property.
    C) is not a max-heap because 8 is a chile of 5 in this tree, so violates the max-heap property.
    D) is not a max-heap because 8 is a chile of 5 in this tree, so violates the max-heap property. There are many other nodes in this tree which violate max-heap property in this tree.

    ReplyDelete