Einzelnen Beitrag anzeigen

tigerman33

Registriert seit: 30. Jul 2005
Ort: München
423 Beiträge
 
Delphi 2005 Professional
 
#5

Re: Build Heap And Heapsort Without Array

  Alt 1. Mai 2006, 20:05
Hi,

if you already have a binary tree, you should be able to transform it into a heap by successively performing a so-called sift operation on the nodes from the bottom up. A sift operation means exchanging the given node with the tree root. Then if necessary, you exchange that node with the larger one of its two sons to keep the ordering. After that, recursively repeat on the just-changed subtree, until the node is at its correct position.
If I remember right, it should actually be enough to do this on only the bottom half of the tree, but I'm not going to give you any guarantuee on that one...

I would suspect Wikipedia has an article on this operation, given that there seems to be one on the heapsort algorithm itself.

Hope this helped.
Christian
Der Computer hilft mir, Probleme zu lösen, die ich ohne Computer nicht hätte.
  Mit Zitat antworten Zitat