can any one of you give idea to write a method that can validate that the heap is a minimun heap returns a true or false, given an array

# Java(Heap Sort)

Page 1 of 1## 4 Replies - 2172 Views - Last Post: 05 June 2011 - 09:40 PM

##
**Replies To:** Java(Heap Sort)

### #2

## Re: Java(Heap Sort)

Posted 05 June 2011 - 12:26 AM

To validate that a given binary tree satisfies the heap condition, you mean? Well, if you can state the heap condition, that should be pretty easy. Can you do that?

### #3

## Re: Java(Heap Sort)

Posted 05 June 2011 - 05:51 PM

### #4

## Re: Java(Heap Sort)

Posted 05 June 2011 - 06:07 PM

Presumably to demonstrate that you understand the heap condition and some basic tree walking. If I'd given that assignment, that would be what I would be looking for.

[Correction - this heap seems to be built on an array. Still, the point remains - it's a fairly simple task if you understand the material, and if not, it's not.]

[Correction - this heap seems to be built on an array. Still, the point remains - it's a fairly simple task if you understand the material, and if not, it's not.]

This post has been edited by **jon.kiparsky**: 05 June 2011 - 06:12 PM

### #5

## Re: Java(Heap Sort)

Posted 05 June 2011 - 09:40 PM

It's still tree walking...the tree just happens to be in an array.

The only things you really need to know are:

The only things you really need to know are:

- What kind of heap you're dealing with (in this case -- min) and what that type of heap implies with its structure
- How many children a node can have (usually 2 -- a binary heap)
- What indexes of the array you're dealing with to access the children of a certain node (simple mathematical formula)

Page 1 of 1