Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Re: Heap sorting in perlby Anonymous Monk |
on Apr 05, 2003 at 15:26 UTC ( [id://248299]=note: print w/replies, xml ) | Need Help?? |
The reason that someone with a large dataset might want a heap is that they don't want to have very much of the dataset in memory at once. With a Heap you can add an element at a time until you have your limit, and from there on you can add one and remove the biggest each time. When you are done you can then just extract off all of the elements in the heap, and you have the smallest N of them from largest to smallest. Without excessive memory usage.
In Section
Seekers of Perl Wisdom
|
|