SlideShare a Scribd company logo
Algorithmes de tri
Tri : complexité
           minimale
• n! résultats possibles
• si tests binaires, on obtient un arbre de
  hauteur minimale
  log2 n! ~ log2 (n^n / e^n) ~ O(n log n)
• La complexité d’un tri sera donc au mieux
  en O(n log n)
The first pass has no effect in this example, because there is no element in the
       array smaller than the A at the left. On the second pass, the other A is the

                      Tri par sélection
   smallest remaining element, so it is exchanged with the S in the second position.
    Then, the E near the middle is exchanged with the O in the third position on the
   third pass; then, the other E is exchanged with the R in the fourth position on the

                      (selection sort)
                                fourth pass; and so forth.




           Récurrence sur le résultat (tableau de 1 à i-1 trié)
Program 6.12 is an implementation of selection sort that adheres to our conventions. The
inner loop is just a comparison to test a current element against the smallest element
found so far (plus the code necessary to increment the index of the current element and
to check that it does not exceed the array bounds); it could hardly be simpler. The work
of moving the items around falls outside the inner loop: each exchange puts an element
Tri par sélection
         (selection sort)
Pour chaque i de l à r-1, échanger a[i] avec l’élément
minimum de a[i], ..., a[r]. Quand l’index i va de gauche à
droite, les éléments à sa gauche sont à leur place finale dans le
tableau (et ne seront plus modifiés), donc le tableau est
complètement trié lorsque i arrive à l’extrémité droite.
static void selection(ITEM[] a, int l, int r)
  {
    for (int i = l; i < r; i++)
      { int min = i;
        for (int j = i+1; j <= r; j++)
          if (less(a[j], a[min])) min = j;
        exch(a, i, min);
      }
  }
During the first pass of insertion sort, the S in the second position is larger than
   the A, so it does not have to be moved. On the second pass, when the O in the
                         Tri par insertion
    third position is encountered, it is exchanged with the S to put A O S in sorted
   order, and so forth. Un-shaded elements that are not circled are those that were

                         (insertion sort)
                            moved one position to the right.




he implementation of insertion sort données (on insère l’élément i) but inefficien
                Récurrence sur les in Program 6.1 is straightforward,
 e shall now consider three ways to improve it in order to illustrate a recurrent them
 roughout many of our implementations: We want code to be succinct, clear, an
 ficient, but these goals sometimes conflict, so we must often strike a balance. We do s
Tri par insertion
           (insertion sort)
(i) met le plus petit élément du tableau à la première place pour que cet
élément serve de “sentinelle” ; (ii) une seule assignation, plutôt qu’un
échange, dans la boucle principale ; et (iii) la boucle interne se termine
quand l’élément inséré est à la bonne position. Pour chaque i, trie les
éléments a[l], ..., a[i] en déplaçant d’une position vers la droite les
éléments de la liste triée a[l], ..., a[i-1] qui sont plus grands que a[i],
place ensuite a[i] à la bonne position.

static void insertion(ITEM[] a, int l, int r)
  { int i;
    for (i = r; i > l; i--)
      if (less(a[i], a[i-1])) exch (a, i-1, i);
    for (i = l+2; i <= r; i++)
      { int j = i; ITEM v = a[i];
        while (less(v, a[j-1]))
           { a[j] = a[j-1]; j--; }
        a[j] = v;
      }
  }
ge A and S to get A S; then, we merge O and R to get O R; then, we merg
 with A S to get A O R S. Later, we merge I T with G N to get G I N T, then
erge this result with A O R S to get A G I N O R S T, and so on. The metho
               Tri fusion (Merge sort)
          recursively builds up small sorted files into larger ones.




wn mergesort isRécurrence dichotomique sur les donnéesstyle, where a m
                  analogous to a top-down management
n organization to take on a big task by dividing it into pieces to be
ndently by underlings. If each manager operates by simply dividing the give
 then putting together the solutions that the subordinates develop and pass
Tri fusion (Merge sort)

static void mergesort(ITEM[]   a,   int
l, int r)
  { if (r <= l) return;
    int m = (r+l)/2;
    mergesort(a, l, m);
    mergesort(a, m+1, r);
    merge(a, l, m, r);
  }
Tri par segmentation
                         (Quicksort, Hoare 1960)




  use the following general strategy to implement partitioning. First, we arbitra
ose a[r] to be the partitioning element—the one that will go into its final positi
 t, we scan from the left end of the array until we find an element greater than
titioning element, and we scan from the right end of the array until we find
Tri par segmentation
          (Quicksort, Hoare 1960)
•   Choisir un pivot v

•   Réarranger le tableau pour que tous les éléments
    plus petits que v soient à gauche, tous les plus
    grands à droite

•   Trier les deux sous-tableaux à droite et à gauche
    static void quicksort(ITEM[] a, int l, int r)
      {
        if (r <= l) return;
        int i = partition(a, l, r);
        quicksort(a, l, i-1);
        quicksort(a, i+1, r);
      }
Tri par segmentation : partition
                  (Quicksort, Hoare 1960)




ure 7.3. Dynamic characteristics of quicksort partition
Tri par segmentation
                  (Quicksort, Hoare 1960)
La variable v contient la valeur du pivot a[r], et i et j sont respectivement les indices
de parcours gauche et droit. La boucle de partition incrémente i et décrémente j, en
maintenant la propriété invariante : aucun élément à gauche de i n’est plus grand que v
et aucun élément à droite de j n’est plus petit que v. Quand les indices se rejoignent, on
termine le partitionnement en échangeant a[i] et a[r], ce qui met v dans a[i], avec
aucun élément plus grand que v à droite et aucun élément plus petit à gauche.
La boucle de partitionnement est codée comme une boucle infinie, avec un break quand
les indices se croisent. Le test j==l protège du cas où l’élément de partitionnement est le
plus petit du fichier.

static int partition(ITEM a[], int l, int r)
  { int i = l-1, j = r; ITEM v = a[r];
    for (;;)
      {
        while (less(a[++i], v)) ;
        while (less(v, a[--j])) if (j == l) break;
        if (i >= j) break;
        exch(a, i, j);
      }
    exch(a, i, r);
    return i;
  }
Tri : complexité
•   Tri par sélection : au plus n^2/2 comparaisons et n
    échanges

•   Tri par insertion : au plus n^2/4 comparaisons et
    n^2/4 affectations

•   Tri fusion : O(n log n) (démonstration à suivre)

•   Quicksort : n^2/2 comparaisons au pire,
    2n ln n comparaisons en moyenne,
    donc O(n log n). Partitionnement en O(n).
    Situation optimale : pivot au milieu, donc choix du
    pivot crucial
In addition to netting the improvements discussed in Section 8.2, a good Java VM
 implementation might avoid unnecessary array accesses to reduce the inner loop of
 mergesort to a comparison (with conditional branch), two index increments ( k and either
 i or j ), and a test with conditional branch for loop completion. The total number of
 instructions in such an inner loop is slightly higher than that for quicksort, but the
 instructions are executed only N lg N times, where quicksort's are executed 39 percent



Tri : temps d’exécution
 more often (or 29 percent with the median-of-three modification). Careful
 implementation and detailed analysis are required for more precise comparison of the
 algorithms in particular environments; nonetheless, we do know that mergesort has an
 inner loop that is slightly longer than that of quicksort.

              Table 8.1. Empirical study of mergesort algorithms
 These relative timings for various sorts on random files of integers indicate that
 standard quicksort is about twice as fast as standard mergesort; that adding a cutoff for
 small files lowers the running times of both bottom-up and top-down mergesort by
 about 15 percent; that top-down mergesort is about 10 percent faster than bottom-up
 mergesort for these file sizes; and that even eliminating the cost of the file copy (the
 method used in the Java system sort) leaves mergesort substantially slower than
 quicksort for randomly ordered files.
                        top-down                         bottom-up
 N              Q       T          T*         O          B           B*        S
 12500          23      27         16         19         30          20        19
 25000          20      43         34         27         42          36        28
 50000          45      91         79         52         92          77        56
 100000         95      199        164        111        204         175       117
 200000         201     421        352        244        455         396       256
 400000         449     904        764        520        992         873       529
 800000         927     1910       1629       1104       2106        1871      1119
 Key:

 Q Quicksort, standard (Program 7.1)

 T Top-down mergesort, standard (Program 8.1)

 T* Top-down mergesort with cutoff for small files

 O Top-down mergesort with cutoff and no array copy

 B Bottom-up mergesort, standard (Program 8.5)

 B* Bottom-up mergesort with cutoff for small files

 S java.util.Arrays.sort

More Related Content

What's hot

Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sorting
ryokollll
 
signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)
iqbal ahmad
 
Z transform
Z transformZ transform
Z transform
ayushagrawal464
 
Advance control theory
Advance control theoryAdvance control theory
Advance control theory
SHIMI S L
 
Lti and z transform
Lti and z transformLti and z transform
Lti and z transform
pranvendra29
 
Chapter 2 fourier transform
Chapter 2 fourier transformChapter 2 fourier transform
Chapter 2 fourier transform
Vasudevan Kamasamudram
 
DSP, Differences between Fourier series ,Fourier Transform and Z transform
DSP, Differences between  Fourier series ,Fourier Transform and Z transform DSP, Differences between  Fourier series ,Fourier Transform and Z transform
DSP, Differences between Fourier series ,Fourier Transform and Z transform
Naresh Biloniya
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transform
AakankshaR
 
Laplace transformations
Laplace transformationsLaplace transformations
Laplace transformations
Pradipta Sarkar
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theorem
ijtsrd
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
Carlo Fanara
 
Sorting techniques
Sorting techniquesSorting techniques
Sorting techniques
Lovely Professional University
 
DSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-TransformDSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-Transform
Amr E. Mohamed
 
Laplace transform
Laplace transformLaplace transform
Laplace transform
Bassit Ali Khan
 
The Laplace Transform of Modeling of a Spring-Mass-Damper System
The Laplace Transform of Modeling of a Spring-Mass-Damper System The Laplace Transform of Modeling of a Spring-Mass-Damper System
The Laplace Transform of Modeling of a Spring-Mass-Damper System
Mahmoud Farg
 
Z Transform
Z TransformZ Transform
Z Transform
Darshan Bhatt
 
Analog properties and Z-transform
Analog properties and Z-transformAnalog properties and Z-transform
Analog properties and Z-transform
Gandhinagar Institute of Technology
 
Fourier transform
Fourier transformFourier transform
Fourier transform
Shahed Babu
 
Digital control systems (dcs) lecture 18-19-20
Digital control systems (dcs) lecture 18-19-20Digital control systems (dcs) lecture 18-19-20
Digital control systems (dcs) lecture 18-19-20
Ali Rind
 

What's hot (20)

Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sorting
 
signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)
 
Z transform
Z transformZ transform
Z transform
 
Advance control theory
Advance control theoryAdvance control theory
Advance control theory
 
Lti and z transform
Lti and z transformLti and z transform
Lti and z transform
 
Chapter 2 fourier transform
Chapter 2 fourier transformChapter 2 fourier transform
Chapter 2 fourier transform
 
DSP, Differences between Fourier series ,Fourier Transform and Z transform
DSP, Differences between  Fourier series ,Fourier Transform and Z transform DSP, Differences between  Fourier series ,Fourier Transform and Z transform
DSP, Differences between Fourier series ,Fourier Transform and Z transform
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transform
 
Laplace transformations
Laplace transformationsLaplace transformations
Laplace transformations
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theorem
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Sorting techniques
Sorting techniquesSorting techniques
Sorting techniques
 
DSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-TransformDSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-Transform
 
Laplace transform
Laplace transformLaplace transform
Laplace transform
 
The Laplace Transform of Modeling of a Spring-Mass-Damper System
The Laplace Transform of Modeling of a Spring-Mass-Damper System The Laplace Transform of Modeling of a Spring-Mass-Damper System
The Laplace Transform of Modeling of a Spring-Mass-Damper System
 
Z Transform
Z TransformZ Transform
Z Transform
 
Analog properties and Z-transform
Analog properties and Z-transformAnalog properties and Z-transform
Analog properties and Z-transform
 
Fourier transform
Fourier transformFourier transform
Fourier transform
 
Digital control systems (dcs) lecture 18-19-20
Digital control systems (dcs) lecture 18-19-20Digital control systems (dcs) lecture 18-19-20
Digital control systems (dcs) lecture 18-19-20
 

Viewers also liked

Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
Kelan tutkimus / Research at Kela
 
Assembly powerpoint
Assembly powerpointAssembly powerpoint
Assembly powerpoint
emmahehir
 
Hyvinvointi, kestävä talous ja degrowth
Hyvinvointi, kestävä talous ja degrowthHyvinvointi, kestävä talous ja degrowth
Hyvinvointi, kestävä talous ja degrowth
Kelan tutkimus / Research at Kela
 
Kelly digital story
Kelly digital storyKelly digital story
Kelly digital story
kkelly2
 
Investeringar i barns humankapital
Investeringar i barns humankapitalInvesteringar i barns humankapital
Investeringar i barns humankapital
Kelan tutkimus / Research at Kela
 
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutus
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutusHiekkala, Sinikka: Neuropsykologinen etäkuntoutus
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutus
Kelan tutkimus / Research at Kela
 
Toimeentulotukea Kelasta
Toimeentulotukea KelastaToimeentulotukea Kelasta
Toimeentulotukea Kelasta
Kelan tutkimus / Research at Kela
 
All about me
All about meAll about me
All about me
green13
 
Ami kiat menulis artikel step by step
Ami kiat menulis artikel step by stepAmi kiat menulis artikel step by step
Ami kiat menulis artikel step by step
Syifa Herbalisto
 
8710 Adoption - CA
8710 Adoption - CA8710 Adoption - CA
8710 Adoption - CAATD13
 
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissaYrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
Kelan tutkimus / Research at Kela
 
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhönErityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
Kelan tutkimus / Research at Kela
 
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminenIntegroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
Kelan tutkimus / Research at Kela
 
Tutorial dasar vegas
Tutorial dasar vegasTutorial dasar vegas
Tutorial dasar vegas
Syifa Herbalisto
 
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselytSubjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
Kelan tutkimus / Research at Kela
 
Henkisen hyvinvoinnin haasteet
Henkisen hyvinvoinnin haasteetHenkisen hyvinvoinnin haasteet
Henkisen hyvinvoinnin haasteet
Kelan tutkimus / Research at Kela
 
Rozzi distance
Rozzi distanceRozzi distance
Rozzi distance
jrozzi
 
Elina Ahola: Rekisteritutkimus omaishoitajien tulotasosta
Elina Ahola: Rekisteritutkimusomaishoitajien tulotasostaElina Ahola: Rekisteritutkimusomaishoitajien tulotasosta
Elina Ahola: Rekisteritutkimus omaishoitajien tulotasosta
Kelan tutkimus / Research at Kela
 
PR 2.0 (Optimizing for People)
PR 2.0 (Optimizing for People)PR 2.0 (Optimizing for People)
PR 2.0 (Optimizing for People)
JonnyWegs
 
Nuoret eläkkeensaajat
Nuoret eläkkeensaajatNuoret eläkkeensaajat
Nuoret eläkkeensaajat
Kelan tutkimus / Research at Kela
 

Viewers also liked (20)

Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
Suvi Rasimus: Tuottaako EU-tuomioistuin oikeusturvaa sosiaalivakuutuksessa?
 
Assembly powerpoint
Assembly powerpointAssembly powerpoint
Assembly powerpoint
 
Hyvinvointi, kestävä talous ja degrowth
Hyvinvointi, kestävä talous ja degrowthHyvinvointi, kestävä talous ja degrowth
Hyvinvointi, kestävä talous ja degrowth
 
Kelly digital story
Kelly digital storyKelly digital story
Kelly digital story
 
Investeringar i barns humankapital
Investeringar i barns humankapitalInvesteringar i barns humankapital
Investeringar i barns humankapital
 
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutus
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutusHiekkala, Sinikka: Neuropsykologinen etäkuntoutus
Hiekkala, Sinikka: Neuropsykologinen etäkuntoutus
 
Toimeentulotukea Kelasta
Toimeentulotukea KelastaToimeentulotukea Kelasta
Toimeentulotukea Kelasta
 
All about me
All about meAll about me
All about me
 
Ami kiat menulis artikel step by step
Ami kiat menulis artikel step by stepAmi kiat menulis artikel step by step
Ami kiat menulis artikel step by step
 
8710 Adoption - CA
8710 Adoption - CA8710 Adoption - CA
8710 Adoption - CA
 
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissaYrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
Yrjö Mattila: Oikeusturva sosiaalivakuutusasioissa
 
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhönErityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
Erityiskorvausoikeuksien vaikutus lääkekorvauksiin ja hallinnolliseen työhön
 
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminenIntegroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
Integroitumista vai eriytymistä? Maahanmuuttajaperheiden nuorten kotoutuminen
 
Tutorial dasar vegas
Tutorial dasar vegasTutorial dasar vegas
Tutorial dasar vegas
 
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselytSubjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
Subjektiivisen hyvinvoinnin mittaaminen ja kohdennetut kyselyt
 
Henkisen hyvinvoinnin haasteet
Henkisen hyvinvoinnin haasteetHenkisen hyvinvoinnin haasteet
Henkisen hyvinvoinnin haasteet
 
Rozzi distance
Rozzi distanceRozzi distance
Rozzi distance
 
Elina Ahola: Rekisteritutkimus omaishoitajien tulotasosta
Elina Ahola: Rekisteritutkimusomaishoitajien tulotasostaElina Ahola: Rekisteritutkimusomaishoitajien tulotasosta
Elina Ahola: Rekisteritutkimus omaishoitajien tulotasosta
 
PR 2.0 (Optimizing for People)
PR 2.0 (Optimizing for People)PR 2.0 (Optimizing for People)
PR 2.0 (Optimizing for People)
 
Nuoret eläkkeensaajat
Nuoret eläkkeensaajatNuoret eläkkeensaajat
Nuoret eläkkeensaajat
 

Similar to 10 algos de tri

CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
DeepakM509554
 
Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
Mahesh Tibrewal
 
Sorting2
Sorting2Sorting2
Sorting2
Saurabh Mishra
 
quicksort (1).ppt
quicksort (1).pptquicksort (1).ppt
quicksort (1).ppt
Balasubramanian699229
 
Algorithms - "quicksort"
Algorithms - "quicksort"Algorithms - "quicksort"
Algorithms - "quicksort"
Ra'Fat Al-Msie'deen
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
Quick sort.pptx
Quick sort.pptxQuick sort.pptx
Quick sort.pptx
Anbarasan Radhakrishnan R
 
Selection sort
Selection sortSelection sort
Selection sort
asra khan
 
s4_quick_sort.ppt
s4_quick_sort.ppts4_quick_sort.ppt
s4_quick_sort.ppt
AliAhmad38278
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
sajinis3
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksort
zukun
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
Preetiverma538521
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
WrushabhShirsat3
 
chapter7 Sorting.ppt
chapter7 Sorting.pptchapter7 Sorting.ppt
chapter7 Sorting.ppt
Nielmagahod
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
Tosin Amuda
 
Sorting
SortingSorting
Sorting
SortingSorting
Sorting
BHARATH KUMAR
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
RenalthaPujaBagaskar
 

Similar to 10 algos de tri (20)

CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
 
Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
 
Sorting2
Sorting2Sorting2
Sorting2
 
quicksort (1).ppt
quicksort (1).pptquicksort (1).ppt
quicksort (1).ppt
 
Algorithms - "quicksort"
Algorithms - "quicksort"Algorithms - "quicksort"
Algorithms - "quicksort"
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
 
Quick sort.pptx
Quick sort.pptxQuick sort.pptx
Quick sort.pptx
 
Selection sort
Selection sortSelection sort
Selection sort
 
s4_quick_sort.ppt
s4_quick_sort.ppts4_quick_sort.ppt
s4_quick_sort.ppt
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksort
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
 
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiufchapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
chapter7.pptfuifbsdiufbsiudfiudfiufeiufiuf
 
chapter7 Sorting.ppt
chapter7 Sorting.pptchapter7 Sorting.ppt
chapter7 Sorting.ppt
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 

Recently uploaded

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 

Recently uploaded (20)

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 

10 algos de tri

  • 2. Tri : complexité minimale • n! résultats possibles • si tests binaires, on obtient un arbre de hauteur minimale log2 n! ~ log2 (n^n / e^n) ~ O(n log n) • La complexité d’un tri sera donc au mieux en O(n log n)
  • 3. The first pass has no effect in this example, because there is no element in the array smaller than the A at the left. On the second pass, the other A is the Tri par sélection smallest remaining element, so it is exchanged with the S in the second position. Then, the E near the middle is exchanged with the O in the third position on the third pass; then, the other E is exchanged with the R in the fourth position on the (selection sort) fourth pass; and so forth. Récurrence sur le résultat (tableau de 1 à i-1 trié) Program 6.12 is an implementation of selection sort that adheres to our conventions. The inner loop is just a comparison to test a current element against the smallest element found so far (plus the code necessary to increment the index of the current element and to check that it does not exceed the array bounds); it could hardly be simpler. The work of moving the items around falls outside the inner loop: each exchange puts an element
  • 4. Tri par sélection (selection sort) Pour chaque i de l à r-1, échanger a[i] avec l’élément minimum de a[i], ..., a[r]. Quand l’index i va de gauche à droite, les éléments à sa gauche sont à leur place finale dans le tableau (et ne seront plus modifiés), donc le tableau est complètement trié lorsque i arrive à l’extrémité droite. static void selection(ITEM[] a, int l, int r) { for (int i = l; i < r; i++) { int min = i; for (int j = i+1; j <= r; j++) if (less(a[j], a[min])) min = j; exch(a, i, min); } }
  • 5. During the first pass of insertion sort, the S in the second position is larger than the A, so it does not have to be moved. On the second pass, when the O in the Tri par insertion third position is encountered, it is exchanged with the S to put A O S in sorted order, and so forth. Un-shaded elements that are not circled are those that were (insertion sort) moved one position to the right. he implementation of insertion sort données (on insère l’élément i) but inefficien Récurrence sur les in Program 6.1 is straightforward, e shall now consider three ways to improve it in order to illustrate a recurrent them roughout many of our implementations: We want code to be succinct, clear, an ficient, but these goals sometimes conflict, so we must often strike a balance. We do s
  • 6. Tri par insertion (insertion sort) (i) met le plus petit élément du tableau à la première place pour que cet élément serve de “sentinelle” ; (ii) une seule assignation, plutôt qu’un échange, dans la boucle principale ; et (iii) la boucle interne se termine quand l’élément inséré est à la bonne position. Pour chaque i, trie les éléments a[l], ..., a[i] en déplaçant d’une position vers la droite les éléments de la liste triée a[l], ..., a[i-1] qui sont plus grands que a[i], place ensuite a[i] à la bonne position. static void insertion(ITEM[] a, int l, int r) { int i; for (i = r; i > l; i--) if (less(a[i], a[i-1])) exch (a, i-1, i); for (i = l+2; i <= r; i++) { int j = i; ITEM v = a[i]; while (less(v, a[j-1])) { a[j] = a[j-1]; j--; } a[j] = v; } }
  • 7. ge A and S to get A S; then, we merge O and R to get O R; then, we merg with A S to get A O R S. Later, we merge I T with G N to get G I N T, then erge this result with A O R S to get A G I N O R S T, and so on. The metho Tri fusion (Merge sort) recursively builds up small sorted files into larger ones. wn mergesort isRécurrence dichotomique sur les donnéesstyle, where a m analogous to a top-down management n organization to take on a big task by dividing it into pieces to be ndently by underlings. If each manager operates by simply dividing the give then putting together the solutions that the subordinates develop and pass
  • 8. Tri fusion (Merge sort) static void mergesort(ITEM[] a, int l, int r) { if (r <= l) return; int m = (r+l)/2; mergesort(a, l, m); mergesort(a, m+1, r); merge(a, l, m, r); }
  • 9. Tri par segmentation (Quicksort, Hoare 1960) use the following general strategy to implement partitioning. First, we arbitra ose a[r] to be the partitioning element—the one that will go into its final positi t, we scan from the left end of the array until we find an element greater than titioning element, and we scan from the right end of the array until we find
  • 10. Tri par segmentation (Quicksort, Hoare 1960) • Choisir un pivot v • Réarranger le tableau pour que tous les éléments plus petits que v soient à gauche, tous les plus grands à droite • Trier les deux sous-tableaux à droite et à gauche static void quicksort(ITEM[] a, int l, int r) { if (r <= l) return; int i = partition(a, l, r); quicksort(a, l, i-1); quicksort(a, i+1, r); }
  • 11. Tri par segmentation : partition (Quicksort, Hoare 1960) ure 7.3. Dynamic characteristics of quicksort partition
  • 12. Tri par segmentation (Quicksort, Hoare 1960) La variable v contient la valeur du pivot a[r], et i et j sont respectivement les indices de parcours gauche et droit. La boucle de partition incrémente i et décrémente j, en maintenant la propriété invariante : aucun élément à gauche de i n’est plus grand que v et aucun élément à droite de j n’est plus petit que v. Quand les indices se rejoignent, on termine le partitionnement en échangeant a[i] et a[r], ce qui met v dans a[i], avec aucun élément plus grand que v à droite et aucun élément plus petit à gauche. La boucle de partitionnement est codée comme une boucle infinie, avec un break quand les indices se croisent. Le test j==l protège du cas où l’élément de partitionnement est le plus petit du fichier. static int partition(ITEM a[], int l, int r) { int i = l-1, j = r; ITEM v = a[r]; for (;;) { while (less(a[++i], v)) ; while (less(v, a[--j])) if (j == l) break; if (i >= j) break; exch(a, i, j); } exch(a, i, r); return i; }
  • 13. Tri : complexité • Tri par sélection : au plus n^2/2 comparaisons et n échanges • Tri par insertion : au plus n^2/4 comparaisons et n^2/4 affectations • Tri fusion : O(n log n) (démonstration à suivre) • Quicksort : n^2/2 comparaisons au pire, 2n ln n comparaisons en moyenne, donc O(n log n). Partitionnement en O(n). Situation optimale : pivot au milieu, donc choix du pivot crucial
  • 14. In addition to netting the improvements discussed in Section 8.2, a good Java VM implementation might avoid unnecessary array accesses to reduce the inner loop of mergesort to a comparison (with conditional branch), two index increments ( k and either i or j ), and a test with conditional branch for loop completion. The total number of instructions in such an inner loop is slightly higher than that for quicksort, but the instructions are executed only N lg N times, where quicksort's are executed 39 percent Tri : temps d’exécution more often (or 29 percent with the median-of-three modification). Careful implementation and detailed analysis are required for more precise comparison of the algorithms in particular environments; nonetheless, we do know that mergesort has an inner loop that is slightly longer than that of quicksort. Table 8.1. Empirical study of mergesort algorithms These relative timings for various sorts on random files of integers indicate that standard quicksort is about twice as fast as standard mergesort; that adding a cutoff for small files lowers the running times of both bottom-up and top-down mergesort by about 15 percent; that top-down mergesort is about 10 percent faster than bottom-up mergesort for these file sizes; and that even eliminating the cost of the file copy (the method used in the Java system sort) leaves mergesort substantially slower than quicksort for randomly ordered files. top-down bottom-up N Q T T* O B B* S 12500 23 27 16 19 30 20 19 25000 20 43 34 27 42 36 28 50000 45 91 79 52 92 77 56 100000 95 199 164 111 204 175 117 200000 201 421 352 244 455 396 256 400000 449 904 764 520 992 873 529 800000 927 1910 1629 1104 2106 1871 1119 Key: Q Quicksort, standard (Program 7.1) T Top-down mergesort, standard (Program 8.1) T* Top-down mergesort with cutoff for small files O Top-down mergesort with cutoff and no array copy B Bottom-up mergesort, standard (Program 8.5) B* Bottom-up mergesort with cutoff for small files S java.util.Arrays.sort