Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Heap sort.

 
Munna Takedo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me the Heap sort logic and how to implement it in java ?
And suggest me which sort algorithm is the best in performance wise with huge Data and less Data?
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heapsort. There is an example there in Pascal / Delphi. Let's see if you can read that. For your information, ":=" is the assignment operator in Pascal / Delphi.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the Heap data structure is basically a tree, where the child nodes are always smaller (by whatever definition of 'smaller' you choose) than the parent.

There are algorithms for re-heapifying a heap once you remove an element.

A Heap sort builds a heap out of your data.

you remove the largest node (which is by definition the root of the heap), and stick it at the end of your array, then re-heapify what's left.

You then remove the largest node, put it in the second to last spot, and re-heapify.

etc.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heap is a complete binary tree.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic