in reply to Re^3: Heap sorting in perl
in thread Heap sorting in perl
If you know when you start how many you will want in the end, what would possibly prevent you from adding and removing from your heap before you had all of the data in? Sure, the first "maximum" removed and thrown away might not be the biggest element in the whole set. But it wasn't in the smallest N, and that is all we care about. Who cares what order we throw away the rest in?? (As long as we throw it away before running out of memory!)
As for overkill, using Perl to solve a problem that can be solved with the correct option to the Unix sort utility is overkill. But if you need a general purpose solution in Perl and you have a heap implementation there already, why not use it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Heap sorting in perl
by adrianh (Chancellor) on Apr 05, 2003 at 16:29 UTC | |
by Anonymous Monk on Apr 05, 2003 at 17:02 UTC | |
by adrianh (Chancellor) on Apr 05, 2003 at 20:12 UTC |