Technopedia Center
PMB University Brochure
Faculty of Engineering and Computer Science
S1 Informatics S1 Information Systems S1 Information Technology S1 Computer Engineering S1 Electrical Engineering S1 Civil Engineering

faculty of Economics and Business
S1 Management S1 Accountancy

Faculty of Letters and Educational Sciences
S1 English literature S1 English language education S1 Mathematics education S1 Sports Education
  • Registerasi
  • Brosur UTI
  • Kip Scholarship Information
  • Performance
  1. Weltenzyklopädie
  2. Tri de Shell — Wikipédia
Tri de Shell — Wikipédia 👆 Click Here! Read More..
Un article de Wikipédia, l'encyclopédie libre.
Tri de Shell
Exemple du tri de Shell avec les espacements 23, 10, 4, 1
Découvreur ou inventeur
Donald Shell (en)[1]Voir et modifier les données sur Wikidata
Date de découverte
1959Voir et modifier les données sur Wikidata
Problèmes liés
Algorithme de tri, algorithme en place, tri par comparaisonVoir et modifier les données sur Wikidata
Structure des données
liste ou tableau
Complexité en temps
Pire cas
O ( n 2 ) {\displaystyle O(n^{2})} {\displaystyle O(n^{2})}[2]Voir et modifier les données sur Wikidata
Moyenne
O ( n 1.25 ) {\displaystyle O(n^{1.25})} {\displaystyle O(n^{1.25})}[3]Voir et modifier les données sur Wikidata
Meilleur cas
O ( n log ⁡ n ) {\displaystyle O(n\log n)} {\displaystyle O(n\log n)}[3]Voir et modifier les données sur Wikidata
Complexité en espace
Pire cas
O ( 1 ) {\displaystyle O(1)} {\displaystyle O(1)}[3]Voir et modifier les données sur Wikidata

modifier - modifier le code - modifier WikidataDocumentation du modèle

Tri de Shell barres de couleur de l'algorithme

Le tri de Shell ou Shell sort en anglais est un algorithme de tri. C'est une amélioration notable du tri par insertion au niveau de la vitesse d'exécution, mais ce tri n'est pas stable. Le principe de l'algorithme est simple mais l'étude du temps d'exécution est très complexe, et plusieurs problèmes sont toujours ouverts à ce sujet.

Le nom vient de son inventeur Donald Shell (en) (1924-2015) qui publia l'algorithme dans le numéro de juillet 1959 de Communications of the ACM[4].

Principe

[modifier | modifier le code]

Amélioration du tri par insertion

[modifier | modifier le code]

Le tri de Shell est une amélioration du tri par insertion en observant deux choses :

  • Le tri par insertion est efficace si la liste est à peu près triée (1) ;
  • Le tri par insertion est inefficace en moyenne car il ne déplace les valeurs que d'une position par instruction (2).

Le tri de Shell trie chaque liste d'éléments séparés de n positions chacun avec le tri par insertion. L'algorithme effectue plusieurs fois cette opération en diminuant n jusqu'à n=1 ce qui équivaut à trier tous les éléments ensemble.

Le fait de commencer avec des éléments espacés permet de pallier l'inconvénient (2), tandis que lorsque l'on fait à la fin avec un espacement de 1, ce qui est en fait un tri par insertion ordinaire, on tire parti de l'avantage (1).

Code Python

[modifier | modifier le code]
gaps = [701, 301, 132, 57, 23, 10, 4, 1]

def shell_sort(tab):
  n = len(tab)
  for m in gaps:
    for r in range(m):
      # tri par insertion des positions de la forme k * m + r
      for i in range (r + m, n, m):
        j = i
        x = tab[i]
        while j > r and tab[j-m] > x:
          tab[j] = tab[j-m]
          j = j - m
        tab[j] = x

Gap ou espacement entre les éléments

[modifier | modifier le code]

Les premiers espacements optimaux (empiriquement trouvés) sont les suivants : 1, 4, 10, 23, 57, 132, 301, 701[5].

On remarque que le facteur entre ces valeurs, exception faite des deux premières, est d'environ 2,3. On peut effectivement prolonger cette liste avec ce facteur si les dimensions du tableau dépassent environ 1600 éléments. Par exemple pour étendre la liste gaps jusqu'à la taille nécessaire:

gap = gaps[0]
while gap<length(liste):
  gap = round(gap*2.3);
  gaps = [gap] + gaps

Des espacements de la forme 2 p 3 q {\displaystyle 2^{p}3^{q}} {\displaystyle 2^{p}3^{q}}, dans l'ordre croissant, garantissent quant à eux la meilleure complexité théorique prouvée aujourd'hui, O ( n log 2 ⁡ n ) {\displaystyle O(n\log ^{2}n)} {\displaystyle O(n\log ^{2}n)}[6].

Analyse de la complexité

[modifier | modifier le code]
Article connexe : Analyse de la complexité des algorithmes.

Sur des tableaux de moins d'une centaine d'éléments, ce tri est aussi rapide qu'un tri rapide simple. Mais plutôt que d'être en compétition avec l'algorithme quicksort, il peut être utilisé pour son optimisation quand les sous-listes à traiter deviennent petites.

Le choix de la suite des espacements entre les éléments qu'on trie à chaque étape (gap) est très important. Il peut faire varier la complexité dans le pire cas de O ( n 2 ) {\displaystyle O\left(n^{2}\right)} {\displaystyle O\left(n^{2}\right)} à O ( n log 2 ⁡ n ) {\displaystyle O\left(n\log ^{2}n\right)} {\displaystyle O\left(n\log ^{2}n\right)}[6]. Il est également possible que la complexité en moyenne puisse être O ( n log ⁡ n ) {\displaystyle O\left(n\log n\right)} {\displaystyle O\left(n\log n\right)} avec un bon choix d'espacements (problème ouvert).

Des bornes inférieures ont aussi été publiées, on peut citer une borne de Ω ( n ( log ⁡ n log ⁡ log ⁡ n ) 2 ) {\displaystyle \Omega \left(n\left({\log n \over \log \log n}\right)^{2}\right)} {\displaystyle \Omega \left(n\left({\log n \over \log \log n}\right)^{2}\right)} sur la complexité dans le pire cas quels que soient les espacements[7].

Le tableau suivant compare les gaps publiés jusqu'à aujourd'hui :

OEIS Terme général (k ≥ 1) Gaps ou espacements concrets Complexité dans le pire des cas Auteur et année de publication
⌊ N 2 k ⌋ {\displaystyle \left\lfloor {\frac {N}{2^{k}}}\right\rfloor } {\displaystyle \left\lfloor {\frac {N}{2^{k}}}\right\rfloor } ⌊ N 2 ⌋ , ⌊ N 4 ⌋ , … , 1 {\displaystyle \left\lfloor {\frac {N}{2}}\right\rfloor ,\left\lfloor {\frac {N}{4}}\right\rfloor ,\ldots ,1} {\displaystyle \left\lfloor {\frac {N}{2}}\right\rfloor ,\left\lfloor {\frac {N}{4}}\right\rfloor ,\ldots ,1} Θ ( N 2 ) {\displaystyle \Theta \left(N^{2}\right)} {\displaystyle \Theta \left(N^{2}\right)} [i.e quand N = 2p] Donald Shell (en), 1959
2 ⌊ N 2 k + 1 ⌋ + 1 {\displaystyle 2\left\lfloor {\frac {N}{2^{k+1}}}\right\rfloor +1} {\displaystyle 2\left\lfloor {\frac {N}{2^{k+1}}}\right\rfloor +1} 2 ⌊ N 4 ⌋ + 1 , … , 3 , 1 {\displaystyle 2\left\lfloor {\frac {N}{4}}\right\rfloor +1,\ldots ,3,1} {\displaystyle 2\left\lfloor {\frac {N}{4}}\right\rfloor +1,\ldots ,3,1} Θ ( N 3 2 ) {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} Frank & Lazarus, 1960[8]
A168604 2 k − 1 {\displaystyle 2^{k}-1} {\displaystyle 2^{k}-1} 1 , 3 , 7 , 15 , 31 , 63 , … {\displaystyle 1,3,7,15,31,63,\ldots } {\displaystyle 1,3,7,15,31,63,\ldots } Θ ( N 3 2 ) {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} Thomas N. Hibbard (en), 1963[9]
A083318 2 k + 1 {\displaystyle 2^{k}+1} {\displaystyle 2^{k}+1}, préfixé avec 1 1 , 3 , 5 , 9 , 17 , 33 , 65 , … {\displaystyle 1,3,5,9,17,33,65,\ldots } {\displaystyle 1,3,5,9,17,33,65,\ldots } Θ ( N 3 2 ) {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} Papernov & Stasevich, 1965[10]
A003586 Nombres successifs de la forme 2 p 3 q {\displaystyle 2^{p}3^{q}} {\displaystyle 2^{p}3^{q}} (entier friable 3-lisse) 1 , 2 , 3 , 4 , 6 , 8 , 9 , 12 , … {\displaystyle 1,2,3,4,6,8,9,12,\ldots } {\displaystyle 1,2,3,4,6,8,9,12,\ldots } Θ ( N log 2 ⁡ N ) {\displaystyle \Theta \left(N\log ^{2}N\right)} {\displaystyle \Theta \left(N\log ^{2}N\right)} Vaughan Ronald Pratt (en), 1971[6]
A003462 3 k − 1 2 {\displaystyle {\frac {3^{k}-1}{2}}} {\displaystyle {\frac {3^{k}-1}{2}}}, plus petit que ⌈ N 3 ⌉ {\displaystyle \left\lceil {\frac {N}{3}}\right\rceil } {\displaystyle \left\lceil {\frac {N}{3}}\right\rceil } 1 , 4 , 13 , 40 , 121 , … {\displaystyle 1,4,13,40,121,\ldots } {\displaystyle 1,4,13,40,121,\ldots } Θ ( N 3 2 ) {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} {\displaystyle \Theta \left(N^{\frac {3}{2}}\right)} Vaughan Ronald Pratt (en), 1971[6]
A036569 ∏ I a q , où a q = min { n ∈ N : n ≥ ( 5 2 ) q + 1 , ∀ p : 0 ≤ p < q ⇒ p g c d ( a p , n ) = 1 } I = { 0 ≤ q < r ∣ q ≠ 1 2 ( r 2 + r ) − k } r = ⌊ 2 k + 2 k ⌋ {\displaystyle {\begin{aligned}&\prod \limits _{I}a_{q},{\hbox{où}}\\a_{q}={}&\min \left\{n\in \mathbb {N} \colon n\geq \left({\frac {5}{2}}\right)^{q+1},\forall p\colon 0\leq p<q\Rightarrow pgcd(a_{p},n)=1\right\}\\I={}&\left\{0\leq q<r\mid q\neq {\frac {1}{2}}\left(r^{2}+r\right)-k\right\}\\r={}&\left\lfloor {\sqrt {2k+{\sqrt {2k}}}}\right\rfloor \end{aligned}}} {\displaystyle {\begin{aligned}&\prod \limits _{I}a_{q},{\hbox{où}}\\a_{q}={}&\min \left\{n\in \mathbb {N} \colon n\geq \left({\frac {5}{2}}\right)^{q+1},\forall p\colon 0\leq p<q\Rightarrow pgcd(a_{p},n)=1\right\}\\I={}&\left\{0\leq q<r\mid q\neq {\frac {1}{2}}\left(r^{2}+r\right)-k\right\}\\r={}&\left\lfloor {\sqrt {2k+{\sqrt {2k}}}}\right\rfloor \end{aligned}}} 1 , 3 , 7 , 21 , 48 , 112 , … {\displaystyle 1,3,7,21,48,112,\ldots } {\displaystyle 1,3,7,21,48,112,\ldots } O ( N 1 + 8 ln ⁡ ( 5 / 2 ) ln ⁡ ( N ) ) {\displaystyle O\left(N^{1+{\sqrt {\frac {8\ln \left(5/2\right)}{\ln(N)}}}}\right)} {\displaystyle O\left(N^{1+{\sqrt {\frac {8\ln \left(5/2\right)}{\ln(N)}}}}\right)} Incerpi & Robert Sedgewick, 1985[11], Knuth[12]
A036562 4 k + 3 ⋅ 2 k − 1 + 1 {\displaystyle 4^{k}+3\cdot 2^{k-1}+1} {\displaystyle 4^{k}+3\cdot 2^{k-1}+1}, préfixé par 1 1 , 8 , 23 , 77 , 281 , … {\displaystyle 1,8,23,77,281,\ldots } {\displaystyle 1,8,23,77,281,\ldots } O ( N 4 3 ) {\displaystyle O\left(N^{\frac {4}{3}}\right)} {\displaystyle O\left(N^{\frac {4}{3}}\right)} Sedgewick, 1986[13]
A033622 { 9 ( 2 k − 2 k 2 ) + 1 k  pair , 8 ⋅ 2 k − 6 ⋅ 2 ( k + 1 ) / 2 + 1 k  impair {\displaystyle {\begin{cases}9\left(2^{k}-2^{\frac {k}{2}}\right)+1&k{\text{ pair}},\\8\cdot 2^{k}-6\cdot 2^{(k+1)/2}+1&k{\text{ impair}}\end{cases}}} {\displaystyle {\begin{cases}9\left(2^{k}-2^{\frac {k}{2}}\right)+1&k{\text{ pair}},\\8\cdot 2^{k}-6\cdot 2^{(k+1)/2}+1&k{\text{ impair}}\end{cases}}} 1 , 5 , 19 , 41 , 109 , … {\displaystyle 1,5,19,41,109,\ldots } {\displaystyle 1,5,19,41,109,\ldots } O ( N 4 3 ) {\displaystyle O\left(N^{\frac {4}{3}}\right)} {\displaystyle O\left(N^{\frac {4}{3}}\right)} Sedgewick, 1986[14]
h k = max { ⌊ 5 h k − 1 11 ⌋ , 1 } , h 0 = N {\displaystyle h_{k}=\max \left\{\left\lfloor {\frac {5h_{k-1}}{11}}\right\rfloor ,1\right\},h_{0}=N} {\displaystyle h_{k}=\max \left\{\left\lfloor {\frac {5h_{k-1}}{11}}\right\rfloor ,1\right\},h_{0}=N} ⌊ 5 N 11 ⌋ , ⌊ 5 11 ⌊ 5 N 11 ⌋ ⌋ , … , 1 {\displaystyle \left\lfloor {\frac {5N}{11}}\right\rfloor ,\left\lfloor {\frac {5}{11}}\left\lfloor {\frac {5N}{11}}\right\rfloor \right\rfloor ,\ldots ,1} {\displaystyle \left\lfloor {\frac {5N}{11}}\right\rfloor ,\left\lfloor {\frac {5}{11}}\left\lfloor {\frac {5N}{11}}\right\rfloor \right\rfloor ,\ldots ,1} Inconnue Gaston Gonnet (en) & Ricardo Baeza-Yates (en), 1991[15]
A108870 ⌈ 1 5 ( 9 ⋅ ( 9 4 ) k − 1 − 4 ) ⌉ {\displaystyle \left\lceil {\frac {1}{5}}\left(9\cdot \left({\frac {9}{4}}\right)^{k-1}-4\right)\right\rceil } {\displaystyle \left\lceil {\frac {1}{5}}\left(9\cdot \left({\frac {9}{4}}\right)^{k-1}-4\right)\right\rceil } 1 , 4 , 9 , 20 , 46 , 103 , … {\displaystyle 1,4,9,20,46,103,\ldots } {\displaystyle 1,4,9,20,46,103,\ldots } Inconnue Tokuda, 1992[16]
A102549 Inconnue (trouvé expérimentalement) 1 , 4 , 10 , 23 , 57 , 132 , 301 , 701 {\displaystyle 1,4,10,23,57,132,301,701} {\displaystyle 1,4,10,23,57,132,301,701} Inconnue Ciura, 2001[17]

Références

[modifier | modifier le code]
  1. ↑ (en) D. L. Shell, « A high-speed sorting procedure », Communications of the ACM, New York, ACM, vol. 2, no 7,‎ 1er juillet 1959, p. 30-32 (ISSN 0001-0782 et 1557-7317, OCLC 1514517, DOI 10.1145/368370.368387).Voir et modifier les données sur Wikidata
  2. ↑ Vaughan Pratt, « Shellsort and Sorting Networks (Outstanding Dissertations in the Computer Sciences) »
  3. ↑ a b et c « https://www.cs.wcupa.edu/rkline/ds/shell-comparison.html »
  4. ↑ (en) ShellD L, « A high-speed sorting procedure », Communications of the ACM,‎ 1er juillet 1959 (DOI 10.1145/368370.368387, lire en ligne, consulté le 9 mai 2020)
  5. ↑ Marcin Ciura, « Best Increments for the Average Case of Shellsort », dans Proceedings of the 13th International Symposium on Fundamentals of Computation Theory, Springer, 2001 (ISBN 3540424873, lire en ligne), p. 106–117
  6. ↑ a b c et d Vaughan Pratt, Shellsort and sorting networks, Garland Pub, 1979, 59 p. (ISBN 0-8240-4406-1, OCLC 5008158, lire en ligne)
  7. ↑ C. Greg Plaxton, Bjarne Poonen et Torsten Suel, « Improved Lower Bounds for Shellsort », dans Annual Symposium on Foundations of Computer Science, vol. 33, 1992 (DOI 10.1109/SFCS.1992.267769), p. 226–235
  8. ↑ Frank R. M. et R. B. Lazarus, « A High-Speed Sorting Procedure », Communications of the ACM, vol. 3, no 1,‎ 1960, p. 20–22 (DOI 10.1145/366947.366957)
  9. ↑ Thomas N. Hibbard, « An Empirical Study of Minimal Storage Sorting », Communications of the ACM, vol. 6, no 5,‎ 1963, p. 206–213 (DOI 10.1145/366552.366557)
  10. ↑ A. A. Papernov et G. V. Stasevich, « A Method of Information Sorting in Computer Memories », Problems of Information Transmission, vol. 1, no 3,‎ 1965, p. 63–75 (lire en ligne)
  11. ↑ Janet Incerpi et Robert Sedgewick, « Improved Upper Bounds on Shellsort », Journal of Computer and System Sciences, vol. 31, no 2,‎ 1985, p. 210–224 (DOI 10.1016/0022-0000(85)90042-x)
  12. ↑ Donald E. Knuth, The Art of Computer Programming. Volume 3: Sorting and Searching, Reading, Massachusetts, Addison-Wesley, 1997, 83–95 p. (ISBN 0-201-89685-0), « Shell's method »
  13. ↑ Robert Sedgewick, Algorithms in C, vol. 1, Addison-Wesley, 1998, 273–281 p. (ISBN 0-201-31452-5)
  14. ↑ Robert Sedgewick, « A New Upper Bound for Shellsort », Journal of Algorithms, vol. 7, no 2,‎ 1986, p. 159–173 (DOI 10.1016/0196-6774(86)90001-5)
  15. ↑ Gaston H. Gonnet et Ricardo Baeza-Yates, Handbook of Algorithms and Data Structures : In Pascal and C, Reading, Massachusetts, Addison-Wesley, 1991, 2e éd., 161–163 p. (ISBN 0-201-41607-7), « Shellsort »
  16. ↑ Naoyuki Tokuda, Proceedings of the IFIP 12th World Computer Congress on Algorithms, Software, Architecture, Amsterdam, North-Holland Publishing Co., 1992, 449–457 p. (ISBN 0-444-89747-X), « An Improved Shellsort »
  17. ↑ Marcin Ciura, Proceedings of the 13th International Symposium on Fundamentals of Computation Theory, London, Springer-Verlag, 2001, 106–117 p. (ISBN 3-540-42487-3), « Best Increments for the Average Case of Shellsort »

Liens externes

[modifier | modifier le code]

Sur les autres projets Wikimedia :

  • Tri de Shell, sur Wikibooks
  • Shell Sort en C, Java, Pascal, C#
  • (en) Illustration dynamique du tri shell
v · m
Algorithmes de tri
Tris par comparaisons
Sans hypothèse autre
Complexité moyenne O ( n log ⁡ n ) {\displaystyle {\mathcal {O}}(n\log n)} {\displaystyle {\mathcal {O}}(n\log n)}
  • Tri rapide
  • Tri fusion
  • Tri par tas
  • Introsort
  • Smoothsort
  • Timsort
  • Tri arborescent
  • Tri à peigne (?)
  • Tri de Shell (?)
Complexité moyenne O ( n 2 ) {\displaystyle {\mathcal {O}}(n^{2})} {\displaystyle {\mathcal {O}}(n^{2})}
  • Tri à bulles
  • Tri par insertion
  • Tri par sélection
  • Tri cocktail
Complexité moyenne moins bonne que O ( n 2 ) {\displaystyle {\mathcal {O}}(n^{2})} {\displaystyle {\mathcal {O}}(n^{2})}
  • Tri spaghetti
  • Tri stupide
  • Tri faire-valoir
Avec hypothèse supplémentaire
  • Tri comptage
  • Tri par base
  • Tri par paquets
Réseau de tri
  • Tri bitonique
  • Tri pair-impair
Tri utilisant d'autres opérations
  • Tri de crêpes
  • Algorithme de tri externe
  • Tri topologique
Applications
  • Problème du drapeau hollandais
  • Recherche dichotomique
  • icône décorative Portail de l'informatique théorique
Ce document provient de « https://fr.teknopedia.teknokrat.ac.id/w/index.php?title=Tri_de_Shell&oldid=225238083 ».
Catégorie :
  • Algorithme de tri
Catégories cachées :
  • Page utilisant P61
  • Page utilisant P575
  • Page utilisant P31
  • Page utilisant P3752
  • Page utilisant P3754
  • Page utilisant P3753
  • Page utilisant P3755
  • Page utilisant P18
  • Article utilisant l'infobox Algorithme
  • Article utilisant une Infobox
  • Article contenant un appel à traduction en anglais
  • Portail:Informatique théorique/Articles liés
  • Portail:Informatique/Articles liés
  • Portail:Mathématiques/Articles liés
  • Portail:Sciences/Articles liés
  • Bon article en polonais

  • indonesia
  • Polski
  • الرية
  • Deutsch
  • English
  • Español
  • Français
  • Italiano
  • مصر
  • Nederlands
  • 本語
  • Português
  • Sinugboanong Binisaya
  • Svenska
  • Українска
  • Tiếng Việt
  • Winaray
  • 中文
  • Русски
Sunting pranala
Pusat Layanan

UNIVERSITAS TEKNOKRAT INDONESIA | ASEAN's Best Private University
Jl. ZA. Pagar Alam No.9 -11, Labuhan Ratu, Kec. Kedaton, Kota Bandar Lampung, Lampung 35132
Phone: (0721) 702022
Email: pmb@teknokrat.ac.id