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

sorting agorithm

by abubacker (Pilgrim)
on Aug 13, 2009 at 07:52 UTC ( #788141=perlquestion: print w/ replies, xml ) 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

Comment on sorting agorithm
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 busunsl (Vicar) on Aug 13, 2009 at 08:06 UTC
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).

    perldoc sort for more information.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-21 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (175 votes), past polls