<?xml version="1.0" encoding="UTF-8"?>

<upm-export>
	<title>Enseignement de l&#039;informatique et du numérique au lycée Boissy d&#039;Anglas</title>
	<link>https://icn-isn-boissy.yj.fr/wp</link>
	<description></description>
	<pubDate>Wed May 6 12:47:53 2026 / +0000  GMT</pubDate>
	<generator>Universal Post Manager 1.1.2 [ www.ProfProjects.com ] </generator>
	<language></language>
	
			<item>
			<title>Tri par sélection</title>
			<link>https://icn-isn-boissy.yj.fr/wp/?p=1538</link>
			<pubDate>Wed May 6 12:47:53 2026 / +0000  GMT</pubDate>
			<guid isPermaLink="false">https://icn-isn-boissy.yj.fr/wp/?p=1538</guid>
			<content-encoded><![CDATA[<!-- wp:paragraph -->
<p>Pour simplifier nous allons trier une liste de 9 valeurs </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>[ 8, 6, 3, 9, 2, 1,  4, 5, 7 ]</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>pour commencer l'explication , utilisons 2 listes</p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://www.podcastscience.fm/wp-content/uploads/2014/09/fig2_tri_selection.png" alt="Tri par sélection"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong><em>A faire:  </em></strong>sur le document réponse Libre Office.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left"><strong><em>Réaliser</em></strong> le même schéma avec  [ 5, 12, 3, 7, 4 ]  sur le document réponse Libre Office. En fin de document vous pouvez découper les numéros pour faire une simulation à la main.</p>
<!-- /wp:paragraph -->

<!-- wp:file {"id":1659,"href":"https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/07/fichier-reponse-tri.odt"} -->
<div class="wp-block-file"><a id="wp-block-file--media-fd45bb9d-8d7a-4fd4-ae87-5b780f499760" href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/07/fichier-reponse-tri.odt">fichier-reponse-tri</a><a href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/07/fichier-reponse-tri.odt" class="wp-block-file__button" download aria-describedby="wp-block-file--media-fd45bb9d-8d7a-4fd4-ae87-5b780f499760">Télécharger</a></div>
<!-- /wp:file -->

<!-- wp:paragraph -->
<p>Combien de comparaison? pour trier [ 8, 6, 3, 9, 2, 1, 4, 5, 7 ]</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>pour sélectionner l'élément le plus petit on liste les 9 valeurs et on fait 8 comparaisons,  pour le deuxième on fait 7 comparaisons, pour le troisième 6 comparaisons et ainsi de suite. D'où  nombre de comparaison= 8+7+6+....+1=36.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Par extension si notre liste est constituée de n valeurs, le nombre de comparaison = (n-1)+(n-2)+(n-3)+ .....+3+2+1 en factorisant         nombre de comparaison=n*(n-1) /2  soit n²/2-n/2 . </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> On dit que l'algorithme de tri par sélection a donc une complexité en O(<em>n</em>²). On parle aussi de complexité quadratique. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="voici-une-implementation-sous-python-avec-2-tableaux-ou-listes-comme-le-graphique-ci-dessus">Voici une implémentation sous python avec 2 tableaux ou listes comme le graphique ci dessus</h2>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>def tri_selection(tableau):
    '''tri d'un tableau, l'argument <strong>tableau</strong> est un tableau ou liste, la fonction renvoie un autre tableau ou liste <strong>resultat</strong>'''
    resultat = &#91;] 
    longueur = len(tableau)                 
    
    while len(resultat) != longueur:        
        minimum = tableau&#91;0]                   
        
        for i in range(1, len(tableau)):        
            if minimum &gt; tableau&#91;i]:                
                minimum = tableau&#91;i]                    
        resultat.append(minimum)                
        tableau.remove(minimum)                 
    return resultat </code></pre>
<!-- /wp:code -->

<!-- wp:file {"id":3576,"href":"https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2022/02/tri-selection-2-listes.tar"} -->
<div class="wp-block-file"><a id="wp-block-file--media-a3d6b5ba-bd38-49a0-abf3-0b53181a7363" href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2022/02/tri-selection-2-listes.tar">tri-selection-2-listes</a><a href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2022/02/tri-selection-2-listes.tar" class="wp-block-file__button" download aria-describedby="wp-block-file--media-a3d6b5ba-bd38-49a0-abf3-0b53181a7363">Télécharger</a></div>
<!-- /wp:file -->

<!-- wp:heading -->
<h2 id="voici-l-algorithme-du-tri-par-selection-ici-une-seule-liste">voici l'algorithme du tri par sélection ( ici une seule liste )</h2>
<!-- /wp:heading -->

<!-- wp:list -->
<ul><li> PROCEDURE tri_Selection ( Tableau a[1:n])</li><li>&nbsp; &nbsp;   POUR i VARIANT DE 1   A    (n -  1)  FAIRE</li><li>&nbsp; &nbsp; &nbsp; &nbsp;     TROUVER [j] LE PLUS PETIT ELEMENT DE [i +  1:n];</li><li>&nbsp; &nbsp; &nbsp; &nbsp;     ECHANGER [j] ET [i];</li><li> FIN PROCEDURE;</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>en python à essayer </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>def tri_selection(tab):
   print(tab)
   for i in range(len(tab)):#boucle sur toute la liste
      # Trouver le min
       min = i
       for j in range(i+1, len(tab)):
           if tab&#91;min] &gt; tab&#91;j]:
               min = j

       tmp = tab&#91;i]
       print('tmp',tmp)#affiche tmp pour visualiser l'algo
       tab&#91;i] = tab&#91;min]
       print ('tab1',tab)#affiche la liste tab pour visualiser l'algo
       tab&#91;min] = tmp
       print('tab2',tab)#affiche la liste tab pour visualiser l'algo
   return tab
# Programme principale pour tester le code ci-dessus
tab = &#91;98, 22, 15, 32, 2, 74, 63, 70]#changer les valeurs de la liste pour un autre essai

tri_selection(tab)

print ("Le tableau trié est:")
print (tab)</code></pre>
<!-- /wp:code -->

<!-- wp:file {"id":2731,"href":"https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/06/tri_selection-1.zip"} -->
<div class="wp-block-file"><a id="wp-block-file--media-42c97c7a-3138-469b-b729-d39738db39e5" href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/06/tri_selection-1.zip">tri_selection</a><a href="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/06/tri_selection-1.zip" class="wp-block-file__button" download aria-describedby="wp-block-file--media-42c97c7a-3138-469b-b729-d39738db39e5">Télécharger</a></div>
<!-- /wp:file -->

<!-- wp:paragraph -->
<p>vous pouvez trouver des explications supplémentaire ici:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>site de <a href="https://www.podcastscience.fm/dossiers/2014/09/04/les-tris/">podcastscience </a>, site de <a href="https://pixees.fr/informatiquelycee/n_site/nsi_prem_tri_algo.html">David Roche</a> et sur le site <a href="http://lwh.free.fr/pages/algo/tri/tri.htm">http://lwh.free.fr</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>
Retour vers <a href="https://icn-isn-boissy.yj.fr/wp/2019/06/19/algorithmes-de-tri/">article algorithme de tri</a></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"right","id":1665,"width":95,"height":33} -->
<div class="wp-block-image"><figure class="alignright is-resized"><img src="https://icn-isn-boissy.yj.fr/wp/wp-content/uploads/2019/07/by-nc-sa.eu_.png" alt="" class="wp-image-1665" width="95" height="33"/></figure></div>
<!-- /wp:image -->]]></content-encoded>
			<excerpt-encoded><![CDATA[]]></excerpt-encoded>
			<wp-post_id>1538</wp-post_id>
			<wp-post_date>2019-06-19 10:47:41</wp-post_date>
			<wp-post_date_gmt>2019-06-19 08:47:41</wp-post_date_gmt>
				</item>
</upm-export>
