Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Xavier.Leroy@inria.fr (Xavier Leroy)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: Sort.array easily degenerates
Date: Wed, 10 Mar 1999 01:28:16 +0100 (MET)	[thread overview]
Message-ID: <199903100028.BAA20920@miss.wu-wien.ac.at> (raw)
In-Reply-To: <19990309114442.07231@pauillac.inria.fr> from "Xavier Leroy" at Mar 9, 99 11:44:42 am

> The Sort.array implementation is Quicksort with insertion sort for
> small partitions, as suggested in Sedgewick.  I should know better
> than take some code out of an algorithms textbook and expect that it
> will work well... 
> 
> At any rate, any one is welcome to send me a better implementation.

I have also compared it to the Sedgewick-version and wondered, what was
wrong with the implementation - it seems that the version in the book
doesn't hold what it promises...

Someone suggested via mail to me that "sort" as can be found in the STL
is very efficient. I took a look at it and it makes indeed a very good
impression. There is an excellent paper about it on the following page:

  http://www.cs.rpi.edu/~musser/gp/timing.html
  Name of paper: Introspective Sorting and Searching Algorithms
  
  download paper from:
  http://www.cs.rpi.edu/~musser/gp/introsort.ps

It's a kind of hybrid version of various sorting algorithms. It does not
only guarantee a worst-case bound of N*log(N), but it is also as fast as
quicksort in the average case. The constant factor compared to quicksort
is just a little bit larger so it seems to be a true alternative.

The implementation requires heap-algorithms. If someone has time, he could
try to implement the sort algorithm with a suitable heap-implementation
from Okasaki's purely functional data structures - some of them are very
efficient. Take a look at the paper and on the page

  http://miss.wu-wien.ac.at/~mottl/ocaml_sources/intro.html

and download "pure_fun.tar.gz". In chapter 3 you will find "LeftistHeap"
and in chapter 5 "SplayHeap". Both are quite efficient (SplayHeap
seems to be faster (garbage collection parameters can change the
behaviour significantly), but is a bit more complicated). With some minor
changes/additions it should be possible to use them for heap-sorting.

As it seems, a collection of such algorithms and data structures would
really come handy in the OCAML-standard-library...

Another question is, whether to also support "stable_sort" as in the
STL. It guarantees that elements which are already sorted will stay in
the same order. This is important with "order"-functions that consider
only a part of the data representation to be sorted.

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




  parent reply	other threads:[~1999-03-10  9:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-06  0:27 Markus Mottl
1999-03-09 10:44 ` Xavier Leroy
1999-03-09 23:03   ` doligez
1999-03-10 13:58     ` Xavier Leroy
1999-03-10  0:28   ` Markus Mottl [this message]
     [not found] <Xavier.Leroy@inria.fr>
1999-03-05 10:41 ` Objective Caml 2.02 Xavier Leroy
1999-03-05 13:34   ` Camlp4 2.02 Daniel de Rauglaudre
1999-03-05 15:11   ` Objective Caml 2.02 Pierpaolo Bernardi
1999-03-05 19:59   ` doligez
1999-03-11  3:06   ` Upgrade from OCaml 2.01 to OCaml 2.02 made things _slower_! Alexey Nogin
1999-03-11  9:44     ` Xavier Leroy
1999-03-11 23:59       ` Alexey Nogin
1999-03-13 13:40         ` Anton Moscal
1999-03-24  4:20           ` Alexey Nogin
1999-03-26 11:49             ` Anton Moscal
1999-04-06  2:06       ` Alexey Nogin
1999-04-06  7:53         ` Xavier Leroy
1999-03-11 23:42   ` List.filter in Ocaml 2.02 Alexey Nogin
1999-03-12 10:10     ` Wolfram Kahl
1999-03-12 18:18       ` Alexey Nogin
1999-03-13  2:43       ` David Monniaux
1999-03-12 17:01     ` Jean-Francois Monin
1999-03-12 18:41       ` Alexey Nogin
     [not found]     ` <199903121011.LAA27611@lsun565.lannion.cnet.fr>
1999-03-12 18:37       ` Alexey Nogin
1999-03-15  9:06         ` Jean-Francois Monin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199903100028.BAA20920@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox