Given that, our steps to find the smallest M elements would be:
As you can see, this is very similar to the strategy you proposed. In fact, you could view heaps as a datastructure designed specifically to implement this algorithm efficiently.
-Blake
In reply to Re: Re: Heap sorting in perl
by blakem
in thread Heap sorting in perl
by blakem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |