• edited by
13,013 views
35 35 votes

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

  1.        
  2.   

2 Answers

Best answer
37 37 votes

In option (A) - it is not a max heap because it is not a Complete Binary Tree (a heap must have all levels till last but one completely filled and in the last level all nodes must be filled from the left end without a gap till the last node)

In option (C) - it is complete binary tree but is not following the max heap property i.e. the value of parent node is not always greater than the child nodes as the node of value $5$ is less then one of its child node value of $8.$

In option (D) - similar to (C) option explanation here node of value $2$ is less than the child node value $4.$

Correct option is (B) and it satisfies all the properties of a max heap.

• edited by
5 5 votes
heap is complete binary tree . so it is filled from top to bottom. left to right. option b is correct.

in option a even if all parents are greater , it does not follow heap structure
Answer:
Position:
Show:

Related questions

75 75 votes
4 answers 4 answers
24.7k
24.7k views
go_editor asked Sep 29, 2014
24,696 views
On a non-pipelined sequential processor, a program segment, which is the part of the interrupt service routine, is given to transfer $500$ bytes from an I/O device to mem...
49 49 votes
2 answers 2 answers
16.9k
16.9k views
akash asked Oct 29, 2014
16,914 views
Let $P$ be a regular language and $Q$ be a context-free language such that $Q \subseteq P$. (For example, let $P$ be the language represented by the regular expression $p...
23 23 votes
2 answers 2 answers
8.6k
8.6k views
go_editor asked Sep 29, 2014
8,642 views
Choose the most appropriate word(s) from the options given below to complete the following sentence.I contemplated _________ Singapore for my vacation but decided against...
46 46 votes
7 answers 7 answers
16.9k
16.9k views
go_editor asked Sep 29, 2014
16,925 views
A deterministic finite automaton ($\text{DFA}$) $D$ with alphabet $\Sigma = \{a, b\}$ is given below.Which of the following finite state machines is a valid minimal $\tex...