{"id":158,"date":"2022-01-25T10:59:57","date_gmt":"2022-01-25T09:59:57","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/?p=158"},"modified":"2022-01-25T11:01:27","modified_gmt":"2022-01-25T10:01:27","slug":"quelques-algorithmes-simples","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/2022\/01\/25\/quelques-algorithmes-simples\/","title":{"rendered":"Quelques algorithmes simples"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img src=\"https:\/\/siecledigital.fr\/wp-content\/uploads\/2018\/02\/algorithme-definition-explication-940x550.jpg\" alt=\"d\u00e9finition algorithme explication avec les applications\" \/><\/figure>\n\n\n\n<p>Un&nbsp;<strong>algorithme<\/strong>&nbsp;est une suite finie et non ambigu\u00eb d&rsquo;instructions et d\u2019op\u00e9rations permettant de r\u00e9soudre  un type de probl\u00e8mes. Il est dit&nbsp;correct&nbsp;lorsque, pour chaque instance du probl\u00e8me, il se termine en produisant la bonne sortie, c&rsquo;est-\u00e0-dire qu&rsquo;il r\u00e9sout le probl\u00e8me pos\u00e9.<\/p>\n\n\n\n<p><strong>2) Tri par insertion ,par s\u00e9lection<\/strong><\/p>\n\n\n\n<p><strong>Le tri par insertion<\/strong> : l&rsquo;algorithme va chercher une valeur inf\u00e9rieur \u00e0 la derni\u00e8re en analysant la liste , des qu&rsquo;il la trouver <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"982\" height=\"214\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-1.png\" alt=\"\" class=\"wp-image-159\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-1.png 982w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-1-300x65.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-1-768x167.png 768w\" sizes=\"(max-width: 982px) 100vw, 982px\" \/><\/figure>\n\n\n\n<p> Puis il va la prendre , pour la ramener en arri\u00e8re jusqu&rsquo;\u00e0 trouver une valeur sup\u00e9rieur \u00e0 celle s\u00e9lectionner<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"983\" height=\"217\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-2.png\" alt=\"\" class=\"wp-image-160\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-2.png 983w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-2-300x66.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-2-768x170.png 768w\" sizes=\"(max-width: 983px) 100vw, 983px\" \/><\/figure>\n\n\n\n<p><strong>Le tri par s\u00e9lection<\/strong> : Il va prendre la 1er valeur , est il va analyser la liste jusqu&rsquo;\u00e0  trouver la valeur la plus inf\u00e9rieur \u00e0 celle s\u00e9lectionner ici la valeur la plus inf\u00e9rieur \u00e0 6 c&rsquo;est 2 donc il finis d&rsquo;analyser si il trouve pas de valeurs encore plus petite . <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"977\" height=\"212\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-3.png\" alt=\"\" class=\"wp-image-161\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-3.png 977w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-3-300x65.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-3-768x167.png 768w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/figure>\n\n\n\n<p>Les deux valeurs s&rsquo;\u00e9change ! puis il continue avec les autres valeurs de la liste une par une . Attention s&rsquo;il ne trouve pas de valeurs inf\u00e9rieur \u00e0 celle s\u00e9lectionner il la laisse et passe a la valeur suivante !<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"994\" height=\"224\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-4.png\" alt=\"\" class=\"wp-image-162\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-4.png 994w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-4-300x68.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-content\/uploads\/sites\/3\/2022\/01\/image-4-768x173.png 768w\" sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/figure>\n\n\n\n<p><strong>Voici  un exemple type<\/strong> insertion puis s\u00e9lection <strong>: <\/strong><\/p>\n\n\n\n<h2 class=\"has-text-align-center\">Par Insertion : <\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def tri_insertion(tableau):\n    for i in range(1,len(tableau)):\n        en_cours = tableau[i]\n        j = i\n        #d\u00e9calage des \u00e9l\u00e9ments du tableau }\n        while j&gt;0 and tableau[j-1]&gt;en_cours:\n            tableau[j]=tableau[j-1]\n            j = j-1\n        #on ins\u00e8re l'\u00e9l\u00e9ment \u00e0 sa place\n        tableau[j]=en_cours<\/pre>\n\n\n\n<p>Traduction en Pseudo code pour mieux comprendre : <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ROCEDURE tri_Selection ( Tableau a[1:n])\n    POUR i VARIANT DE 1 A n - 1 FAIRE\n        TROUVER [j] LE PLUS PETIT ELEMENT DE [i + 1:n];\n        ECHANGER [j] ET [i];\nFIN PROCEDURE;<\/pre>\n\n\n\n<h2 class=\"has-text-align-center\">Par S\u00e9lection : <\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def tri_selection(tableau):\n    nb = len(tableau)\n    for en_cours in range(0,nb):    \n        plus_petit = en_cours\n        for j in range(en_cours+1,nb) :\n            if tableau[j] &lt; tableau[plus_petit] :\n                plus_petit = j\n        if min is not en_cours :\n            temp = tableau[en_cours]\n            tableau[en_cours] = tableau[plus_petit]\n            tableau[plus_petit] = temp<\/pre>\n\n\n\n<p>Traduction Pseudo Code pour mieux comprendre : <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ROCEDURE tri_Selection ( Tableau a[1:n])\n    POUR i VARIANT DE 1 A n - 1 FAIRE\n        TROUVER [j] LE PLUS PETIT ELEMENT DE [i + 1:n];\n        ECHANGER [j] ET [i];\nFIN PROCEDURE;<\/pre>\n\n\n\n<p>Source : http:\/\/lwh.free.fr\/pages\/algo\/tri\/tri_selection.html<\/p>\n\n\n\n<p>http:\/\/lwh.free.fr\/pages\/algo\/tri\/tri_insertion.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un&nbsp;algorithme&nbsp;est une suite finie et non ambigu\u00eb d&rsquo;instructions et d\u2019op\u00e9rations permettant de r\u00e9soudre un type de probl\u00e8mes. Il est dit&nbsp;correct&nbsp;lorsque, pour chaque instance du probl\u00e8me, il se termine en produisant la bonne sortie, c&rsquo;est-\u00e0-dire qu&rsquo;il r\u00e9sout le probl\u00e8me pos\u00e9. 2) Tri par insertion ,par s\u00e9lection Le tri par insertion : l&rsquo;algorithme va chercher une valeur [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/posts\/158"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":2,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":164,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/posts\/158\/revisions\/164"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/zakaria\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}