It depends on how qsort is implemented by the C
stdlib library with which perl was compiled. My guess is no,
but it really depends on how your C stdlib was implemented.
It is easy to add a "quicksort worst-case avoider"
by not using a "use the first element as the pivot" and instead
doing something like:
- adding a "sorted list detector"
- Picking the pivot randomly (instead of as the first element)
- Shuffling the list before sorting
- Using another pivot picking technique
Since not everyone knows the internals of quicksort, there
is a worst case performance of O(n^2) with quicksort if the
worst pivot is picked for each iteration (if you don't know what a
pivot is don;t worry.... if you want to know I can explain it. This
worst-case performance can happen if the list is already in
is in sorted order and the pivot is picked by choosing the first
element of the list as the pivot. However, there are
techniques for easily avoiding this pitfall.
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.