The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
665 views

Which of the following is a valid heap?

  1. A
  2. B
  3. C
  4. D
asked in Others by Veteran (358k points) | 665 views

2 Answers

+1 vote
A , D , C are invalid

As there are child>parent case

A: 8>4

C: 7>1

D: 10>3

only B is valid heap... parents>children
answered by Active (3.9k points)
0
This is the case of a max heap. in min heap parent < child
0 votes
A heap is a complete binary tree with special property that value of child nodes is either less or greater than their parent. Two types of Heaps are:

1. Max Heap: where value of parent node is greater than its child nodes (by default)

2. Min Heap: where value of parent node is less than its child nodes

In the given question, all cases are of max heap.

A is NOT valid heap as, 8>4 is there

C is NOT valid heap as, 7>1 is there

D is NOT valid heap as, 7>1 and 8>4 is there

Therefore, B is a valid heap.
answered by (253 points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,713 questions
46,750 answers
140,552 comments
58,384 users