4 Replies - 1986 Views - Last Post: 05 June 2011 - 09:40 PM Rate Topic: -----

#1 pmummar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-May 11

Java(Heap Sort)

Posted 04 June 2011 - 08:40 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: Java(Heap Sort)

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7802
  • View blog
  • Posts: 13,197
  • Joined: 19-March 11

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?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java(Heap Sort)

Posted 05 June 2011 - 05:51 PM

View Postpmummar, on 04 June 2011 - 11:40 PM, said:

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

for which obscur reason would you want to do that ?
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7802
  • View blog
  • Posts: 13,197
  • Joined: 19-March 11

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.]

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

Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

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:

  • 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)

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1