Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Heap sorting in perl

by Aristotle (Chancellor)
on Apr 07, 2003 at 08:49 UTC ( #248540=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Heap sorting in perl
in thread Heap sorting in perl

In said note, blakem writes:
Heap sorting is attractive because selecting the smallest M elements from a dataset of size N (N being much larger than M) requires storing only M elements in memory at any one time.
That means that he can very well store the entire heap, the M elements, in memory.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^5: Heap sorting in perl
by Anonymous Monk on Apr 07, 2003 at 11:33 UTC
    Abigail's original solution as I read it requires that the entire dataset of size N be passed into the function smallest(). This requires that you have enough memory for N things up front. Which is the original poster's problem, he doesn't. He only comfortably has room for M things, but is fetching through a much larger dataset of N.

    Abigail's follow-up solution resolves this limitation admirably well...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://248540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2020-12-03 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (55 votes). Check out past polls.

    Notices?