Introsort

Introsort

Introsort or introspective sort is a sorting algorithm designed by David Musser in 1997. It begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted. It is the best of both worlds, with a worst-case O("n" log "n") runtime and practical performance comparable to quicksort on typical data sets. Since both algorithms it uses are comparison sorts, it too is a comparison sort.

In quicksort, one of the critical operations is choosing the pivot: the element around which the list is partitioned. The simplest pivot selection algorithm is to take the first or the last element of the list as the pivot, causing poor behavior for the case of sorted or nearly-sorted input. Niklaus Wirth's variant uses the middle element to prevent these occurrences, degenerating to O("n"²) for contrived sequences. The median-of-3 pivot selection algorithm takes the median of the first, middle, and last elements of the list; however, even though this performs well on many real-world inputs, it is still possible to contrive a "median-of-3 killer" list that will cause dramatic slowdown of a quicksort based on this pivot selection technique. Such inputs could potentially be exploited by an aggressor, for example by sending such a list to an Internet server for sorting as a denial of service attack.

Musser reported that on a median-of-3 killer sequence of 100,000 elements, introsort's running time was 1/200 that of median-of-3 quicksort. Musser also considered the effect on caches of Sedgewick's delayed small sorting, where small ranges are sorted at the end in a single pass of insertion sort. He reported that it could double the number of cache misses, but that its performance with double-ended queues was significantly better and should be retained for template libraries, in part because the gain in other cases from doing the sorts immediately was not great.

Similarly, Musser also introduced a worst-case linear selection algorithm with time comparable to that of "Hoare's algorithm", a simple adaptation of quicksort that is the most efficient selection algorithm used in practice. This is called introspection selection or Introselect.

The June 2000 SGI C++ Standard Template Library [http://www.sgi.com/tech/stl/stl_algo.h stl_algo.h] implementation of unstable sort uses the Musser introsort approach with the recursion depth to switch to heapsort passed as a parameter, median-of-3 pivot selection and the Sedgewick final insertion sort pass. The element threshold for switching to the simple insertion sort was 16.

References

* cite journal
last=Musser
first=David
title=Introspective Sorting and Selection Algorithms
url=http://www.cs.rpi.edu/~musser/gp/introsort.ps
doi=10.1002/(SICI)1097-024X(199708)27:8<983::AID-SPE117>3.0.CO;2-#
journal=Software: Practice and Experience
volume=27
issue=8
publisher=Wiley
year=1997
pages=983–993

* Niklaus Wirth. "Algorithms and Data Structures". Prentice-Hall, Inc., 1985. ISBN 0-13-022005-1.

External links

* [http://ralphunden.net/content/tutorials/a-guide-to-introsort/ "A guide to Introsort"] Paper created over the course of a student research project by Ralph Unden. Contains a complete implementation in Java.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Introsort — ou introspective sort est un algorithme de tri par comparaisons. C est une variante du tri rapide inventée par David Musser en 1997. Par rapport au tri rapide, Introsort a l avantage d avoir une complexité O(nlogn) dans le pire cas. Principe L… …   Wikipédia en Français

  • Introsort — ist ein Sortieralgorithmus. Der Begriff ist eine Kurzform für „introspektives Sortieren“. Der Algorithmus ist eine Variation von Quicksort, welche in entarteten Fällen auf ein anderes Sortierverfahren mit Worst Case Laufzeit (zum Beispiel… …   Deutsch Wikipedia

  • Introsort — или интроспективная сортировка  алгоритм сортировки, предложенный Дэвидом Мюссером в 1997 году. Он использует быструю сортировку и переключается на пирамидальную сортировку, когда глубина рекурсии превысит некоторый заранее установленный… …   Википедия

  • Quick-Sort — Eine zufällige Permutation von Integerwerten wird mit Quicksort sortiert. Die blauen Linien zeigen das Pivotelement im jeweiligen Rekursionsschritt. Quicksort (von engl. quick – schnell, to sort – sortieren) ist ein schneller, rekursiver, nicht… …   Deutsch Wikipedia

  • Quick sort — Eine zufällige Permutation von Integerwerten wird mit Quicksort sortiert. Die blauen Linien zeigen das Pivotelement im jeweiligen Rekursionsschritt. Quicksort (von engl. quick – schnell, to sort – sortieren) ist ein schneller, rekursiver, nicht… …   Deutsch Wikipedia

  • Tri rapide — Le tri rapide (en anglais quicksort) est un algorithme de tri inventé par C.A.R. Hoare en 1961[1] et fondé sur la méthode de conception diviser pour régner. Il est généralement utilisé sur des tableaux, mais peut aussi être adapté aux listes.… …   Wikipédia en Français

  • Quicksort — Infobox Algorithm class=Sorting algorithm Quicksort in action on a list of numbers. The horizontal lines are pivot values. data=Varies time=O(nlog n) on average space=Varies by implementation optimal=Sometimes Stability= [Sorting… …   Wikipedia

  • Haldensortierung — Der Heapsort Algorithmus beim Sortieren eines Arrays aus permutierten Werten. Der Algorithmus besteht aus zwei Schritten; im vorbereitenden Schritt wird das Array zu einem binären Heap umgeordnet, dessen Baumstruktur vor dem eigentlichen… …   Deutsch Wikipedia

  • Heap-Sort — Der Heapsort Algorithmus beim Sortieren eines Arrays aus permutierten Werten. Der Algorithmus besteht aus zwei Schritten; im vorbereitenden Schritt wird das Array zu einem binären Heap umgeordnet, dessen Baumstruktur vor dem eigentlichen… …   Deutsch Wikipedia

  • Heap Sort — Der Heapsort Algorithmus beim Sortieren eines Arrays aus permutierten Werten. Der Algorithmus besteht aus zwei Schritten; im vorbereitenden Schritt wird das Array zu einem binären Heap umgeordnet, dessen Baumstruktur vor dem eigentlichen… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”