Perl: the Markov chain saw PerlMonks

### sorting agorithm

by abubacker (Pilgrim)
 on Aug 13, 2009 at 07:52 UTC Need Help??
abubacker has asked for the wisdom of the Perl Monks concerning the following question:

Dear all
Can any one tell me what algorithm sort command uses,
I am having some of the ideas to do with that

Replies are listed 'Best First'.
Re: sorting agorithm
by busunsl (Vicar) on Aug 13, 2009 at 08:06 UTC
Re: sorting agorithm
by Anonymous Monk on Aug 13, 2009 at 08:03 UTC
perldoc -f sort | grep algo
Perl 5.6 and earlier used a quicksort algorithm to implement sort. That algorithm was not stable, and *could* go quadratic. implementation was replaced with a stable mergesort algorithm sort. Its rather blunt control of the underlying algorithm may # guarantee stability, regardless of algorithm
And now including the lines that do not contain the word "algorithm":
```               Perl 5.6 and earlier used a quicksort algorithm to implement
sort.  That algorithm was not stable, and could go quadratic.
(A stable sort preserves the input order of elements that
compare equal.  Although quicksorts run time is O(NlogN) when
averaged over all arrays of length N, the time can be O(N**2),
quadratic behavior, for some inputs.)  In 5.7, the quicksort
implementation was replaced with a stable mergesort algorithm
whose worst-case behavior is O(NlogN).  But benchmarks
indicated that for some inputs, on some platforms, the original
quicksort was faster.  5.8 has a sort pragma for limited
control of the sort.  Its rather blunt control of the
underlying algorithm may not persist into future Perls, but the
ability to characterize the input or output in implementation
independent ways quite probably will.  See sort.
```
I see you used
```perldoc -f sort | grep -C5 algo
:)
Re: sorting agorithm
by deibyz (Hermit) on Aug 13, 2009 at 09:43 UTC
You can also change the way perl sorts with the "sort" pragama (I think available from 5.8).

Create A New User
Node Status?
node history
Node Type: perlquestion [id://788141]
Approved by ww
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-08-23 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (345 votes). Check out past polls.

Notices?