edited by
7,990 views
23 votes
23 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.   
edited by

2 Answers

Best answer
24 votes
24 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 votes
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:

Related questions

14 votes
14 votes
2 answers
2
go_editor asked Sep 29, 2014
4,762 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...
36 votes
36 votes
6 answers
3
go_editor asked Sep 29, 2014
10,713 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...
25 votes
25 votes
5 answers
4
go_editor asked Sep 29, 2014
5,057 views
Consider the matrix as given below.$$\begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 7 \\ 0 & 0 & 3\end{bmatrix}$$Which one of the following options provides the CORRECT values of...