Introsort

Introsort or introspective leaves is an algorithm of sorting in O (N \ log N) some are the starting data. It is an improvement of the Tri rapid found by David Musser in 1997.

Principle

The algorithm quicksort is slowed down when the selected pivot is each time at the end or the beginning of the sorted sublist. In this case, the number of recursion is in O (N) and total time in O (n^2) , which is a time comparable with a Tri by selection. But, put aside the case of linear recursion, the Tri rapid, as its name indicates it is fast, i.e. in O (N \ log N) .

Introsort to mitigate this disadvantage, uses a meter of recursion. Thus it measures progressively the depth of recursion in progress (from where the name of the algorithm). When the depth exceeds K \ log n where K is a constant, an algorithm in O (N \ log N) is used to sort the remaining sublists: a Tri by heap, a Smoothsort etc

Just like the Tri rapid, Introsort can be optimized by sorting the sublists of less than 15 elements with a Tri by insertion or a Tri from Shell, progressively, or at the end (principle of Sedgesort).

Algorithm

With a: Table and N = Length (A)

To make Introsort (has, 2*PartieEntière (Log2 (N)) )

  • Procedure Introsort (a: Table, ProfondeurLimite: Entirety > 0)

    • To initialize
      • CurMin: = Min and CurMax: = max
      • Pivot: = + max/2)
    • Répéter until has CurMin > CurMax
      • As long as < Pivot has, CurMin: = CurMin + 1
      • As long as > Pivot has, CurMax: = CurMax - 1
      • If CurMin < CurMax then Echanger (has, A)
      • CurMin = CurMin + 1
      • CurMax = CurMax + 1
    • If CurMax > Min
      • If ProfondeurLimite = 1 then to make Heapsort (A)
      • If not to make Introsort (has, ProfondeurLimite - 1)
    • If CurMin < max
      • If ProfondeurLimite = 1 then to make Heapsort (A)
      • If not to make Introsort (has, ProfondeurLimite - 1)

See too

  • Tri rapid (quicksort)
  • Tri by heap (heapsort)

Random links:Constantius Gallus | Canton of Lyon-XIi | Worsen Arab | Kralendijk | Charlotte Lennox | Traînées_de_jeep_aux_villes_fantômes_du_Colorado