<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/cours-polytech-peip2-algo/default.xsl"?>
<fr:tree xmlns:fr="http://www.forester-notes.org" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xml="http://www.w3.org/XML/1998/namespace" root="true" base-url="/cours-polytech-peip2-algo/">
  <fr:frontmatter>
    <fr:authors>
      <fr:author>
        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
      </fr:author>
    </fr:authors>
    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/index/</fr:uri>
    <fr:display-uri>index</fr:display-uri>
    <fr:route>/cours-polytech-peip2-algo/index/</fr:route>
    <fr:title text="Cours d'algorithmique et complexité">Cours d'algorithmique et complexité</fr:title>
  </fr:frontmatter>
  <fr:mainmatter>
    <fr:tree show-metadata="false">
      <fr:frontmatter>
        <fr:authors>
          <fr:author>
            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
          </fr:author>
        </fr:authors>
        <fr:date>
          <fr:year>2025</fr:year>
          <fr:month>11</fr:month>
          <fr:day>4</fr:day>
        </fr:date>
        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003K/</fr:uri>
        <fr:display-uri>003K</fr:display-uri>
        <fr:route>/cours-polytech-peip2-algo/003K/</fr:route>
        <fr:title text="Structure du cours">Structure du cours</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <html:p>
Ce document est un cours d'algorithmique pour la deuxième année de prépa intégrée à l'école d'ingénieur Polytech Paris-Saclay. Il est conçu à l'aide de l'outil <fr:link href="https://www.forester-notes.org/index/index.xml" type="external">forester</fr:link>, et a une structure qui peut sembler atypique. Il est en effet constitué de nombreuses "notes atomiques" (c'est-à-dire des notes présentant chacune une seule idée), constituant l'ensemble des connaissances attendues. Le document que vous lisez regroupe toutes ces notes, qui servent à la fois de cours et de base de données de connaissances. Il est donc attendu que le lecteur puisse lire le cours en sautant d'une note à l'autre, en suivant les liens contenus dans ces dernières, lorsque cela semble pertinent ou nécessaire. Le dernier chapitre de ce document constitue une référence sur les notions importantes que nous allons étudier et utiliser tout au long du cours. Il n'a pas vocation à être lu de bout-en-bout, mais à servir de point d'ancrage auquel se référer tout au long de ce cours. Il ne faudra donc pas hésiter à sauter à ce chapitre au cours de la lecture autant que nécessaire.</html:p>
        <fr:tree show-metadata="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>11</fr:month>
              <fr:day>4</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003L/</fr:uri>
            <fr:display-uri>003L</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/003L/</fr:route>
            <fr:title text="Contribuer">Contribuer</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Les contributions sont bienvenues, de la part de tout le monde! Le cours entier est en ligne sur <fr:link href="https://github.com/thibautbenjamin/cours-polytech-peip2-algo" type="external">github</fr:link>, et il suffit d'ouvrir une merge request pour proposer un changement. Si vous ne savez pas comment faire, vous pouvez contacter <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link></html:p>
          </fr:mainmatter>
        </fr:tree>
      </fr:mainmatter>
    </fr:tree>
    <html:p>
      <html:strong>
        <fr:link href="/cours-polytech-peip2-algo/Cours/" title="Cours d'algorithmique PEIP2" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Cours/" display-uri="Cours" type="local">La page du cours</fr:link>
      </html:strong>
    </html:p>
    <html:p>
      <html:strong>
        <fr:link href="/cours-polytech-peip2-algo/001V/" title="Recueil des TD/TP" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001V/" display-uri="001V" type="local">La page des TD/TP</fr:link>
      </html:strong>
    </html:p>
    <html:p>
      <html:strong>
        <fr:link href="/cours-polytech-peip2-algo/003M/" title="Les diapositives de cours" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003M/" display-uri="003M" type="local">La page des slides de cours</fr:link>
      </html:strong>
    </html:p>
    <html:p>
      <html:strong>
        <fr:link href="/cours-polytech-peip2-algo/006J/" title="Recueil d'examens" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006J/" display-uri="006J" type="local">Recueil d'examens passés</fr:link>
      </html:strong>
    </html:p>
    <html:p>
      <html:strong>
        <fr:link href="/cours-polytech-peip2-algo/005T/" title="Cours d'informatique Option S3" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/005T/" display-uri="005T" type="local">La page du cours d'option S3</fr:link>
      </html:strong>
    </html:p>
  </fr:mainmatter>
  <fr:backmatter>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="References">References</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Context">Context</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Backlinks">Backlinks</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Related">Related</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>12</fr:month>
              <fr:day>10</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006J/</fr:uri>
            <fr:display-uri>006J</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/006J/</fr:route>
            <fr:title text="Recueil d'examens">Recueil d'examens</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Cette page est un recueil d'examens sur lesquels vous entraîner.</html:p>
            <html:p>
              <html:strong>
                <html:span class="link local">
                  <html:a href="/cours-polytech-peip2-algo/bafkrmibi6dzp4jokhei3c6rvurjxjd62s3u4haq7yqnczu7jyhhrsxunhi.pdf">2025</html:a>
                </html:span>
              </html:strong>
            </html:p>
          </fr:mainmatter>
        </fr:tree>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>12</fr:month>
              <fr:day>7</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/005T/</fr:uri>
            <fr:display-uri>005T</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/005T/</fr:route>
            <fr:title text="Cours d'informatique Option S3">Cours d'informatique Option S3</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Cette page est consacrée au matériel du cours d'option informatique qui fait suite au cours d'informatique du semestre 3. Ce cours constitue une petite introduction au sujet de la vérification de programmes.</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmieagbkhfr3uklxb6gs3mhkq3lzphqecpbhr2wucpwysw3kox7a3lq.pdf">Cours 1</html:a></html:span></html:strong>: Présentation, et terminaison des boucles</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmig4z5ce4e264rvqcjc76e4bi4itpnuu3m7xq7r432wmbs2x57ehby.pdf">Cours 2</html:a></html:span></html:strong>: Contrats de fonctions et terminaison des fonctions récursives</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmidm6lfhkkjxhrlc5yszm6d4nkd763rp7maw7wqt7gwbd46urlakvy.pdf">Cours 3</html:a></html:span></html:strong>: Invariants de boucles et preuves de programmes itératifs</html:p>
            <html:p><html:strong><fr:link href="/cours-polytech-peip2-algo/006K/" title="Preuves d'implémentations du tri par insertion" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006K/" display-uri="006K" type="local">TP1</fr:link></html:strong>: Preuves d'implémentations du tri par insertion <html:strong><fr:link href="https://www.why3.org/try/?name=isqrt.c&amp;lang=micro-C&amp;code=A7OO1ypredicate/ytrieJusque/7n1intza7WYrrzn7o7y4forallzi7rzj7tz07Ryqso7xj7Mzf72m74lppl7YwNYY2trieYZl7WYoZWAopZ4lengthAqq7IIwNN2voidyinsertion/pj1tabRrW7I7Jc6requiresSSoVeii7IwHkkbAoobkA7sAz1kHk5ensureskAkkkkmH0ifoqA7SyAj7Ib9H2else77HY1valRg72jAbAjuCHlzjlnnn7wH3whiledm7zR7FleQddmhh7YI7LS5variantoeHqyinvariant/guKosbjjlHlluAziPAzkB7tghospbfuAaam74lpplRHeeekeAnBeeioeesnsadeemdkppldHdddkdAnBdeeohoqeeffmelppleHeeekfffqsffhBhofVWaHnnjnSpppXXbHqnsBpBplD79HllnkljmHmNtCBNNuEytriInsertionAux/QOiuFrauFHUuGq7TyOgHoooPuFhhuHHmuFuFoo7rkmHmuMqhHuFlquFe7o7b9HuGA77LVleeBj7sz1cHuEAmmmmoDQNtNNQytriInsertionRec/AmQlPrlPHVQqBXBRAkkgHmRuBAoooHZqqcjoNcNNcytriInsertionIteratif/mdlcrlcHfcqcckkgHmmmuMYQHoZZjjjH1forqezi7yiiquMfqqA7KKI7LfuNoBQBoA7qAklHmuHuLfcQkjkbHkkqenAsgAgApgBHuOgggAkhDPNt" type="external">correction</fr:link></html:strong></html:p>
            <html:p><html:strong><fr:link href="/cours-polytech-peip2-algo/006Q/" title="Preuves d'implémentations du tri par sélection" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006Q/" display-uri="006Q" type="local">TP2</fr:link></html:strong>: Preuves d'implémentations du tri par sélection <html:strong><fr:link href="https://www.why3.org/try/?name=isqrt.c&amp;lang=micro-C&amp;code=A7iA5includeA7xA3stdio7tAzhA7zNN7OO1ypredicate/ytrieJusque/7n1intza7WYrrzn7o7y4forallzi7rzjdz07RyqsoZj7Mzf72m74lppl7YwNYY2trieYZl7WYoZWAopZ4lengthAqq7IIwNNNlyindiceMin/pr1tabSrzkkrW7I7Jc6requiresq7Syfii7IwHmmQUgBQBi7wHm5ensuresuCOB7tBlkqkkuCf72o747Typp4resultuCHeeggoggdHVSOlpH1forVnzinnnqkkqqA7KKI7Lf5variantoA7sAonHoyinvariant/kdosmnHnnnoeimmHmmTVBTjjqkiTVBVoTTppdTH0ifVoojlippl7YI7LsVmZD79DtH4returnoqNqNNN2void5echangegQhuHrj7rrZuHHRuKz0TlYuIAgguIHkkkkikkAkkkHkuIqVhUuH1oldAknnh7YIwHjjoookkkAknnjjHjjuMzkB7tbbqbbgg7o7FlnB7AyeqqBqZuMmboYYYBhnnnYHU1tmp7ynneuNHqqqhoppfnHqqqoom7wN79NNuRytriSelection/egiuSrznuSHuUuSqXSAkkuSHmuSuDoooHuHqhVZz0Zq7xeqqAuHLfuHo7sonHouHkuOosmnHnnuEfc7rkbHmmuMzjnAzkB7teeoaiqnqduOf72l74lppluQHUzmTuKXlbdseXHuKnnonsknD79NtNNNuPytriSelectionAux/BlgkuQrjjrhuQHRuQquQuQiieHmmRVgsj7wHnnuVjjeAkiHmmuWQnAS7teeo7xiqnqduWfOl74lppluWHduUj7sgXHouQuQWhWHuHBqlSi7o7b9H2else77LuXzm7yuSBifOgsheHuSnnonsknHuTBnnonA7qAz1qjlD79NtNNuSytriSelectionRec/BjdiuSrluSHSuUqUuSAkkgHbqqeAz0sAlnNdN" type="external">correction</fr:link></html:strong></html:p>
            <html:p><html:strong><fr:link href="/cours-polytech-peip2-algo/006R/" title="Preuves d'implémentations du tri par sélection" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006R/" display-uri="006R" type="local">TP3 (Bonus)</fr:link></html:strong>: Preuves d'implémentations du tri fusion <html:strong><fr:link href="https://www.why3.org/try/?name=isqrt.c&amp;lang=micro-C&amp;code=A7OO1ypredicate/ytrieJusque/7n1intza7WYrrzn7o7y4forallzi7rzj7tz07Ryqso7xj7Mzf72m74lppl7YwNYY2trieYZl7WYoZWAopZ4lengthAqq7IIwNN2void4fusionpjytabGauche/Rr5lGauchejrytabDroite/pr5lDroitepr6resultat7WYI7JZ6requiresk7SycAgg7IwHmmhmmAmfmHmmooi7olpApjp7qppjjHjjVokoHoooonoHo5ensuresoohoHdRUz07wHp4gauchepppHp4droitepppH3whilejm7xW7FlkqV7I7Lb5variantBklA7sAjTTokAoAiaHjyinvariant/cuCishbHnnnolsjnHnnYQmfimHmmuFeV7ridHmmuAzanAzbB7tgboUYTXolofuAd72o74muJphuAHaaapaAjBaUiodSaaoloaaacoamuJphaH0ifBUXoVkkkpb7YI7Lgqem7yjpjgHsA7KKwD79H2else77LimiiifpfhHsAiDiHlrDrHuMcfXOuMLuQuMBnp7smuOHnuOPTosm7wHnnduMb7qkmHmmBgpmk7o7c8ojouOeHjjuMmQ7rdmHmmuMzanAzbB7tbYoTZuMVolofuMd72o74muOphuQHaaapaAjBaUiodVaaoloaaacoamuPphaHmqkm7yYpWmHsuPHmsD79HuPARYbYuPLSuPBnp7smOHnPTVosm7wHnnduQm7qamHmmBgpmuR7ouPojoheHjjuPAmQ7rBdmHmmuPzanAzb7tbYoTZuPVolofuPd72o74muQphuQHaaapaAjaUiodVaaoloaaacoamuPphaHmqkm7ympemHsuPHmsD79NtNNNuDytriFusion/BQuK1tabuErznuNHPuGUXouOuFiiuOHkuFuFAoooHouJk7wHuFBmqhz17o7b9HuGA77LYzm7yk7uz2fHHnuJB72luSH1forcnzihRjq7xkqqA7KKI7LVVoB7sBonHouLkUosmnHcco74fQppaD79HuUZk7rBhubHHXuRBiSBYBnhHUilfdZaqUiiiooAULVUmmmsnmHnUjUoslmllHbbmUeUpmA7qAnYDTHTXiUBeejUHHuDmSmoslsllpqekDiNtN7OpNuRgBhRmuRrhuRHSuRquRuRkkfHmmm7zPQHouRuRjjjHytriFusionAux/BqqYksinNYN7Ju" type="external">correction</fr:link></html:strong></html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmia6mboh2uhqcfuuuv6x3sd35has7ftzm42eujmhvyftnuhru5vje4.pdf">Sujet d'examen</html:a></html:span></html:strong> 🔒</html:p>
            <html:p>
              <html:strong>
                <html:span class="link local">
                  <html:a href="/cours-polytech-peip2-algo/bafkrmih6r65z76fd4peasn2d34dw3ktta3mod6xdtliyppif6f3yr3bk6u.pdf">Sujet d'examen annexe</html:a>
                </html:span>
              </html:strong>
            </html:p>
            <html:strong>
              <fr:link href="https://www.why3.org/try/?name=isqrt.c&amp;lang=micro-C&amp;code=A2voidyincrementerTableau" type="external">fichier Wh3</fr:link>
            </html:strong>
          </fr:mainmatter>
        </fr:tree>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>11</fr:month>
              <fr:day>4</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003M/</fr:uri>
            <fr:display-uri>003M</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/003M/</fr:route>
            <fr:title text="Les diapositives de cours">Les diapositives de cours</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Cette page recense les diapositives de cours.</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmieidqupiubmozwhz2d7sbpwj245yfnpsuorg7eazyh4d7qcmj6hje.pdf">Amphi 1</html:a></html:span></html:strong>: Introduction et rappels de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource></html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmicjpxidbzbt344glt4ezog2bxuws45nfjzlgkvnzmfqnapwhlshei.pdf">Amphi 2</html:a></html:span></html:strong>: Les bases de la complexité et premiers algorithmes de tri</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmieiplol6gqokyyrtebd3df2a4dubnqzogcabvbwh5blmvbs6qk3vq.pdf">Amphi 3</html:a></html:span></html:strong>: Récursivité et complexité des fonctions récursives</html:p>
            <html:p><html:strong><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmidta25kcr7z7nml3siyktj2a5rhac2nzs4wgfqxgnlfssxkmxueqm.pdf">Amphi 4</html:a></html:span></html:strong>: Sujets d'algorithmique plus avancés</html:p>
          </fr:mainmatter>
        </fr:tree>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
              <fr:contributor>
                <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
              </fr:contributor>
              <fr:contributor>
                <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
              </fr:contributor>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>11</fr:month>
              <fr:day>4</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Cours/</fr:uri>
            <fr:display-uri>Cours</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/Cours/</fr:route>
            <fr:title text="Cours d'algorithmique PEIP2">Cours d'algorithmique PEIP2</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                  <fr:contributor>
                    <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                  </fr:contributor>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>10</fr:month>
                  <fr:day>7</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0001/</fr:uri>
                <fr:display-uri>0001</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/0001/</fr:route>
                <fr:title text="Rappels d'algorithmique et bases de la programmation">Rappels d'algorithmique et bases de la programmation</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>Ce chapitre joue rôle multiple. Tout d'abord il a pour but de rappeler les notions d'algorithmique vues dans les cours précédents et de faire un panorama global des sujets auxquels un cours d'algorithmique s'intéresse. Ensuite, il sert à établir les objectifs de ce cours, et exposer les "règles du jeu" en établissant les limites que nous étudierons dans ce cours.</html:p>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>7</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0002/</fr:uri>
                    <fr:display-uri>0002</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/0002/</fr:route>
                    <fr:title text="Qu'est-ce qu'un algorithme?">Qu'est-ce qu'un algorithme?</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>Ce cours est consacré aux algorithmes. La question de définir les algorithmes, et d'étudier leurs limite dépasse les attendus de ce cours. Il est néanmoins intéressant de commencer par une brève discussion pour comprendre de quoi l'on parle.</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0003/</fr:uri>
                        <fr:display-uri>0003</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0003/</fr:route>
                        <fr:title text="Algorithme (Définition informelle)">Algorithme (Définition informelle)</fr:title>
                        <fr:taxon>Définition</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Un <html:em>algorithme</html:em> est une séquence d'opérations élémentaires à effectuer afin d'obtenir un résultat précis.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0004/</fr:uri>
                        <fr:display-uri>0004</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0004/</fr:route>
                        <fr:title text="Algorithmes et recettes de cuisine">Algorithmes et recettes de cuisine</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Une analogie que l'on donne couramment est celle d'une recette de cuisine: La recette donne typiquement une série d'instruction que le cuisinier va suivra afin de réaliser son plat (Ex: Faire bouillir de l'eau, ajouter une pincée de sel, ajouter 500g de pates, laisser bouillir pendant 12 min, égouter les pates). Cette analogie nous permet aussi de comprendre ce que l'on entend par "opération élémentaire": un cuisinier débutant aura besoin de la recette pour faire cuire les pates, tandis qu'un cuisinier chevroné se contentera d'une seule étape: "faire cuire des pates".</html:p>
                        <html:p>Contrairement à ce que l'analogie des recettes de cuisine laisse penser, on s'intéresse ici à des algorithmes permettant de réaliser la même opération sur différentes données. Par exemple, lorsque l'on parle d'algorithme pour trier un tableau, on voudra utilier le même algorithme pour trier le tableau
<fr:tex display="inline"><![CDATA[
\begin {array}{|c|c|c|c|}
\hline 
5 & 8 & 2 & 10 \\
\hline 
\end {array}
]]></fr:tex>
et le tableau
<fr:tex display="inline"><![CDATA[
\begin {array}{|c|c|c|c|}
\hline 
7 & 25 & 4 & 9 \\
\hline 
\end {array}
]]></fr:tex>.
On dit alors que le tableau est une <html:em>entrée</html:em> de l'algorithme.
</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0005/</fr:uri>
                        <fr:display-uri>0005</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0005/</fr:route>
                        <fr:title text="Les opérations élémentaires">Les opérations élémentaires</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>La définition informelle d'algorithme que l'on a donné a ses limites: on n'a pas défini ce que sont les opérations élémentaires. Donner une définition exacte est l'objet d'un cours de <fr:link href="https://fr.wikipedia.org/wiki/Théorie_de_la_calculabilité" type="external">théorie de la calculabilité</fr:link>. Pour notre usage, on se limitera à l'intuition que les opérations élémentaires sont les opérations qu'un ordinateur peut réaliser de manière très simple et très rapide, comme par exemple additionner deux nombres. On verra que selon les cas, on pourra prendre quelques libertés et considérer des opérations plus complexes comme élémentaire, tout en restant conscient du temps que ces dernière prennent.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>7</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0008/</fr:uri>
                    <fr:display-uri>0008</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/0008/</fr:route>
                    <fr:title text="La complexité des algorithmes">La complexité des algorithmes</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>De manière générale, étant donné un algorithme on s'intéresse à savoir s'il va s'exécuter en pratique même lorsqu'on l'appelle sur des entrées de grande taille. Si l'algorithme que l'on a écrit est correct, la validité du résultat ne dépend pas de la taille de ses entrées, et donc, si l'algorithme est correct et qu'il renvoie un résultat, ce résultat sera correct, même sur des données de grande taille. En revanche, il est possible que l'on n'arrive pas à obtenir de résultat. Cela peut être dû à deux problèmes:
<html:ol><html:li>L'algorithme prend trop de temps à s'exécuter: il faudrait attendre très longtemps pour obtenir un résultat: Si c'est plusieurs heures, on peut l'envisager. Si c'est plusieurs années, il est peut être encore possible de résoudre le problème en passant sur une machine plus puissante. Au delà de plusieurs siècles on n'a plus vraiment de solution, et dans les pire cas, il faudrait attendre plus longtemps que l'âge de l'univers!</html:li>
<html:li>L'algorithme est trop gourmand en ressource: il est possible que l'algorithme remplisse complètement la mémoire vive de notre ordinateur, et est contraint de s'arrêter sans produire de résultat, faute de mémoire disponible. Dans les cas les plus bénins, on peut utiliser une machine plus puissante, mais dans les cas les plus extrêmes, l'aglorithme peut demander plus de RAM que tout ce qui a été produit depuis le début de l'humanité!</html:li></html:ol></html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0006/</fr:uri>
                        <fr:display-uri>0006</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0006/</fr:route>
                        <fr:title text="Complexité en temps et en espace">Complexité en temps et en espace</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>La complexité en temps est l'évaluation quantitative du temps que va prendre un algorithme pour s'exécuter lorsque ses entrées deviennent très grandes, et la complexité en espace est l'évaluation quantitative de la mémoire dont un algorithme va avoir besoin pour s'exécuter lorsque ses entrées deviennent très grandes.</html:p>
                        <html:p>Il est souvent possible de jongler avec ces deux paramètres. On se trouve régulièrement face à un choix, où quitte à utiliser plus de mémoire, l'on peut diminuer le temps d'exécution, ou inversement, l'on peut diminuer la consommation mémoire au prix d'un algorithme plus lent à s'exécuter. Il n'y a pas toujours de "bon choix", tout dépend des contraintes auxquelles on fait face (de quelle machine on dispose, de combien de temps on a).</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0009/</fr:uri>
                        <fr:display-uri>0009</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0009/</fr:route>
                        <fr:title text="Complexité asymptotique">Complexité asymptotique</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On parle en général de complexité "lorsque les entrées deviennent très grande", ce que l'on résume souvent par le mot <html:em>asymptotique</html:em>. Sur une machine moderne, et avec des petites entrées, la majorité des algorithmes s'exécutent très rapidement, et il n'y a pas beaucoup d'intérêt à évaluer la complexité. En revanche lorsque l'on répète les opérations un grand nombre de fois et que les entrées que l'on traite deviennent très grandes, des différences importantes peuvent se faire sentir, et c'est là que les paramètres peuvent devenir limitant.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000A/</fr:uri>
                        <fr:display-uri>000A</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000A/</fr:route>
                        <fr:title text="Complexité en temps">Complexité en temps</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Dans ce cours, on s'intéresse principalement à la complexité en temps, même s'il est utile de garder en tête la notion complexité mémoire, et la possibilité de jongler entre les deux. Par la suite, lorsque l'on parle de complexité sans plus de précision, il s'agira toujours de complexité en temps.</html:p>
                        <html:p>Il est très difficile de calculer exactement a priori combien de temps un algorithme va mettre pour s'exécuter suivant la taille de ses entrées. C'est pourquoi on utilise un proxy. C'est à dire que l'on va compter à la place  le nombre d'opérations élémentaires qu'un algorithme doit effectuer, et on va contenter de l'approximation que plus on doit effectuer d'opérations élémentaires, plus l'algorithme va prendre de temps à s'exécuter</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0007/</fr:uri>
                            <fr:display-uri>0007</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0007/</fr:route>
                            <fr:title text="Complexité d'un algorithme">Complexité d'un algorithme</fr:title>
                            <fr:taxon>Définition</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>La <html:em>complexité</html:em> d'un algorithme est le nombre d'opérations élémentaire que cet algorithme doit réaliser en fonction de ses entrées.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000B/</fr:uri>
                        <fr:display-uri>000B</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000B/</fr:route>
                        <fr:title text="Limites à la notion de complexité">Limites à la notion de complexité</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Dans la réalité, toutes les opérations élémentaires ne prennent pas nécessairement le même temps exactement. Avec un peu d'habitude, vous verrez qu'il est souvent plus pertinent de définir quelles vont être les opérations coûteuses et limitantes, et de se concentrer à compter ces opérations, plutôt que de compter absolument toutes les opérations. Cela va de paire avec le fait que l'on ne s'intéresse pas en général au compte exact des opérations, mais on souhaite en avoir un <fr:link href="/cours-polytech-peip2-algo/000U/" title="Un peu de mathématiques: Les ordres de grandeurs" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000U/" display-uri="000U" type="local">ordre de grandeur</fr:link></html:p>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                      <fr:contributor>
                        <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                      </fr:contributor>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>8</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000R/</fr:uri>
                    <fr:display-uri>000R</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/000R/</fr:route>
                    <fr:title text="Terminaison et correction des algorithmes">Terminaison et correction des algorithmes</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>
                      <html:img src="https://imgs.xkcd.com/comics/random_number.png" />
                    </html:p>
                    <html:p>
Il existe trois notions fondamentales en algorithmique : <fr:link href="/cours-polytech-peip2-algo/005R/" title="Implémentation mémoisée des suites de Fibonacci" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/005R/" display-uri="005R" type="local">la terminaison</fr:link>, la <fr:link href="/cours-polytech-peip2-algo/0068/" title="Correction partielle d'un algorithme" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0068/" display-uri="0068" type="local">correction partielle</fr:link> et la <fr:link href="/cours-polytech-peip2-algo/0006/" title="Complexité en temps et en espace" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0006/" display-uri="0006" type="local">complexité</fr:link>.
</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>12</fr:month>
                          <fr:day>1</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/005R/</fr:uri>
                        <fr:display-uri>005R</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/005R/</fr:route>
                        <fr:title text="Implémentation mémoisée des suites de Fibonacci">Implémentation mémoisée des suites de Fibonacci</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Pour cette exercice, on utilisera les grands entiers. L'objectif ici est d'implémenter l'algorithme de calcul des suites de Fibonacci grâce à la mémoisation. On rappelle que pour cela on placera les valeurs dans un tableau de grands entiers <html:code>memo</html:code>, de telle sorte que <html:code>memo[n]</html:code> contienne la valeur de <html:code>fibonacci(n)</html:code> si ce dernier a déjà été calculé, ou <fr:tex display="inline"><![CDATA[-1]]></fr:tex> sinon.
<html:ol><html:li>Ecrire une fonction <html:code>fibonacciMemoAux</html:code> prenant en argument un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau de grands entiers <html:code>memo</html:code> contenant le calcul mémoisé, et renvoyant le <fr:tex display="inline"><![CDATA[n^e]]></fr:tex> nombre de Fibonacci, calculé de manière récursive avec mémoisation. Pensez à bien ajouter le résultat de votre calcul au tableau de mémoisation, si celui n'a pas déjà été mémoisé.</html:li>
<html:li>Ecrire une fonction <html:code>fibonacciMemo</html:code> prenant en argument un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et renvoyant un grand entier égal au <fr:tex display="inline"><![CDATA[n^e]]></fr:tex> nombre de Fibonacci calculé avec mémoisation, en appelant la fonction précédente. Pour cela il faudra créer un tableau de mémoisation de la bonne taille et l'initialiser correctement.</html:li>
<html:li>Rappeler la complexité de cette fonction vue en amphi.</html:li>
<html:li>Mesurer le temps mis par cette fonction sur des entrées de tailles diverses et tracer une courbe. Arrêtez vous dès que la fonction dépasse 10 secondes.</html:li></html:ol></html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                          </fr:author>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>12</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0068/</fr:uri>
                        <fr:display-uri>0068</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0068/</fr:route>
                        <fr:title text="Correction partielle d'un algorithme">Correction partielle d'un algorithme</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>12</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0069/</fr:uri>
                            <fr:display-uri>0069</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0069/</fr:route>
                            <fr:title text="Immersion dans le concept de correction partielle">Immersion dans le concept de correction partielle</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Imaginons que vous êtes un grand paresseux, tellement paresseux que vous avez la flemme de faire une addition ! Votre ami sympa vous donne une calculatrice pour faire les additions à votre place. Bien sûr, vous êtes tout content. Vous commencez alors : vous tapez <fr:tex display="inline"><![CDATA[2+2]]></fr:tex> et la calculatrice vous répond <fr:tex display="inline"><![CDATA[−48]]></fr:tex>. Qu'en pensez-vous ? Est-ce une calculatrice fiable ?</html:p>
                            <html:p>Lorsque l'on écrit un algorithme, il faut s'assurer que celui-ci fasse exactement ce qu'on veut. Par exemple, qu'un aspirateur aspire la poussière (mais pas qu'il sèche le linge !). C'est tout le principe de la <html:em>correction partielle</html:em></html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                                  </fr:author>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>12</fr:month>
                                  <fr:day>7</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006A/</fr:uri>
                                <fr:display-uri>006A</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/006A/</fr:route>
                                <fr:title text="Correction partielle">Correction partielle</fr:title>
                                <fr:taxon>Définition informelle</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Prouver la correction partielle d'un algorithme, c'est affirmer que l'algorithme renvoie toujours le bon résultat (autrement dit, la bonne réponse).</html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <html:p>Cette définition est imprécise. Pour la rendre complète, il faudrait être capable de définir exactement ce qu'un algorithme est censé faire ("le bon résultat"). C'est l'objet d'un champ d'étude appelé spécification des logiciels.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>12</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006B/</fr:uri>
                            <fr:display-uri>006B</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/006B/</fr:route>
                            <fr:title text="Les invariants de boucle pour la correction partielle">Les invariants de boucle pour la correction partielle</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Prouver la correction des algorithmes est un sujet très vaste et complexe, qui constitue un champ d'étude à lui tout seul. On ne va donner ici qu'un tout petit exemple de méthode pour aider à prouver la correction partielle d'un algorithme: les invariants de boucles. Il s'agit d'une méthode qui comme son nom l'indique est particulièrement utile en présence de boucles.</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                                  </fr:author>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>12</fr:month>
                                  <fr:day>7</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006C/</fr:uri>
                                <fr:display-uri>006C</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/006C/</fr:route>
                                <fr:title text="Invariants de boucle">Invariants de boucle</fr:title>
                                <fr:taxon>Définition</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Un invariant de boucle est une propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> associée à une boucle, et qui vérifiée au début et à la fin de chaque passage de la boucle.</html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                                  </fr:author>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>12</fr:month>
                                  <fr:day>7</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006D/</fr:uri>
                                <fr:display-uri>006D</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/006D/</fr:route>
                                <fr:title text="Les invariants de boucle en pratique">Les invariants de boucle en pratique</fr:title>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Trouver un invariant de boucle <fr:tex display="inline"><![CDATA[P]]></fr:tex> permet de prouver la correction partielle d'un programme avec un procédé proche du raisonnement par récurrence en mathématiques:
<html:ul><html:li><html:strong>Initialisation</html:strong> : on vérifie que la propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> est vraie avant d'entrer dans la boucle</html:li>
<html:li><html:strong>Hérédité</html:strong> : on suppose que la propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> est vraie à l'issue de la i-ème opération et on vérifie qu'elle reste vraie à la (i+1)-ème itération.</html:li>
<html:li><html:strong>Conclusion</html:strong> :  la propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> est donc vraie en sortant de la boucle</html:li></html:ul>
En pratique, lorsque l'on dit que <fr:tex display="inline"><![CDATA[P]]></fr:tex> est un invariant pour la boucle, cela veut dire qu'il satisfait l'initialisation et l'hérédité, et on en déduit donc immédiatement la conclusion.</html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                                  </fr:author>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>12</fr:month>
                                  <fr:day>7</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006E/</fr:uri>
                                <fr:display-uri>006E</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/006E/</fr:route>
                                <fr:title text="Invariant de boucle">Invariant de boucle</fr:title>
                                <fr:taxon>Exemple</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>On considère le programme suivant:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[#include <iostream>
using namespace std;

// Renvoie le minimum d'un tableau de taille n
int minimum(int tab[],int n){
    //On suppose que tab est de taille n
    int mini = tab[0];
    for(int i=1;i<n;i++){
            if(tab[i]<mini){
                mini = tab[i];
            }
    }
    return mini;
}]]>
</html:code></html:pre>
<html:ol><html:li>On choisit la propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> suivante:
       <html:div><fr:tex display="inline"><![CDATA[P]]></fr:tex> = <html:code>mini</html:code> contient le minimum parmi les <fr:tex display="inline"><![CDATA[i]]></fr:tex> première entrées du tableau</html:div></html:li>

<html:li>Au début du premier passage dans la boucle (lorsque <html:code>i=1</html:code>), la propriété <fr:tex display="inline"><![CDATA[P]]></fr:tex> est vérifiée, car <html:code>mini = tab[0]</html:code>, qui est le minimum parmi la première entrée du tableau.</html:li>

<html:li>Supposons que <fr:tex display="inline"><![CDATA[P]]></fr:tex> est vraie pour au début de l'entrée dans la <fr:tex display="inline"><![CDATA[k^e]]></fr:tex> itération de la boucle. A ce moment, la variable <html:code>i</html:code> vaut <fr:tex display="inline"><![CDATA[k]]></fr:tex>. L'affectation assure que <html:code>mini</html:code> qu'à la fin de la <fr:tex display="inline"><![CDATA[k^e]]></fr:tex> itération <html:code>mini</html:code> contient le minimum entre la valeur de <html:code>mini</html:code> et <html:code>tab[k]</html:code>, ce qui est le minimum parmi les <fr:tex display="inline"><![CDATA[k+1]]></fr:tex>. On remarque également que la variable <html:code>i</html:code> vaut maintenant <fr:tex display="inline"><![CDATA[k+1]]></fr:tex>, et on a bien toujours <fr:tex display="inline"><![CDATA[P]]></fr:tex></html:li>

<html:li>On en conclut que <fr:tex display="inline"><![CDATA[P]]></fr:tex> est vraie à la sortie de la boucle. En sortie de la boucle, <html:code>i=n</html:code>, et donc on vient de prouver qu'en sortie de boucle on a <fr:tex display="inline"><![CDATA[P]]></fr:tex> "<html:code>mini</html:code> contient le minimum parmi les <fr:tex display="inline"><![CDATA[n]]></fr:tex> première entrée du tableau". Comme le tableau est de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, il s'agit bien du minimum de tout le tableau.</html:li></html:ol>
On vient de prouver la correction partielle de cet algorithme.
</html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/abdounourmisbah/" title="Abdounour Misbah" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/abdounourmisbah/" display-uri="abdounourmisbah" type="local">Abdounour Misbah</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>12</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/006F/</fr:uri>
                            <fr:display-uri>006F</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/006F/</fr:route>
                            <fr:title text="Correction totale">Correction totale</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>La <html:em>correction totale</html:em> d'un algorithme est sa terminaison plus sa correction partielle. On a présenté ici les deux comme séparées, mais en pratique, il est courant que pour prouver la terminaison, on ait besoin d'une partie de la correction partielle et vice et versa, ce sont deux choses que l'on étudie souvent conjointement.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
              </fr:mainmatter>
            </fr:tree>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                  <fr:contributor>
                    <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                  </fr:contributor>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>10</fr:month>
                  <fr:day>8</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000S/</fr:uri>
                <fr:display-uri>000S</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/000S/</fr:route>
                <fr:title text="Premiers exemples: algorithmes itératifs, tableaux, et algorithmes de tri">Premiers exemples: algorithmes itératifs, tableaux, et algorithmes de tri</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>Cette section introduit les premiers exemples d'algorithmes, et les utilise comme exemple pour présenter les premières analyses de complexité. Pour bien comprendre cette section, il ne faudra hésiter à se référer aux <fr:link href="/cours-polytech-peip2-algo/000U/" title="Un peu de mathématiques: Les ordres de grandeurs" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000U/" display-uri="000U" type="local">notions mathématiques</fr:link> utilisées pour l'analyse de complexité. On passe ensuite aux tableaux, pour lesquels on présente la syntaxe, quelques programmes pour lesquels on profite pour faire des analyses de complexité. Finalement, on présente quelques algorithmes de tris, qui sont un très bon exemple pour s'entraîner aux calculs de complexité.</html:p>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                      <fr:contributor>
                        <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                      </fr:contributor>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>27</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000T/</fr:uri>
                    <fr:display-uri>000T</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/000T/</fr:route>
                    <fr:title text="On commence en douceur: boucles et conditionnelles">On commence en douceur: boucles et conditionnelles</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>Commençons avec les premiers exemples d'algorithmes que nous allons analyser.</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001G/</fr:uri>
                        <fr:display-uri>001G</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001G/</fr:route>
                        <fr:title text="Calcul de la somme de entiers positifs">Calcul de la somme de entiers positifs</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On va comparer deux algorithmes pour calculer la somme de deux entiers positifs</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001H/</fr:uri>
                            <fr:display-uri>001H</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001H/</fr:route>
                            <fr:title text="Calcul de la somme de deux entiers positifs (directement)">Calcul de la somme de deux entiers positifs (directement)</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[// Entrées: Deux entiers x et y
// Sortie: La somme des deux entrées
int somme (int x , int y){
  return x + y;
}]]>
</html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001I/</fr:uri>
                            <fr:display-uri>001I</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001I/</fr:route>
                            <fr:title text="Calcul de la somme de deux entiers positifs (avec une boucle)">Calcul de la somme de deux entiers positifs (avec une boucle)</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[// Entrées: Deux entiers x et y positifs
// Sortie: La somme des deux entrées
int somme (int x , int y){
  while (y  > 0){
    x = x + 1;
    y = y - 1;
  }
  return x;
}]]>
</html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Lorsque les deux nombres donnés sont positifs, les deux algorithmes permettent effectivement de calculer la somme des deux nombres. Pour évaluer la complexité, on va compter le nombre d'additions effectué par chacuns des deux algorithmes. Le premier algorithme effectue une seule addition <html:code>x+y</html:code> pour renvoyer le résultat, il est donc en temps constant. Le second algorithme effectue deux additions par passage dans la boucle (<html:code>x = x + 1</html:code> et <html:code>y = y - 1</html:code>). A chaque passage dans la boucle, la variable <html:code>y</html:code> est décrémentée de <fr:tex display="inline"><![CDATA[1]]></fr:tex>, et on s'arrête lorsque l'on atteint <fr:tex display="inline"><![CDATA[0]]></fr:tex>. Il y a donc autant de passages dans la boucle que la valeur initiale de <html:code>y</html:code>. On dira que le second algorithme est en <fr:tex display="inline"><![CDATA[\mathcal {O}(y)]]></fr:tex>, ou encore linéaire en son second argument.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001K/</fr:uri>
                        <fr:display-uri>001K</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001K/</fr:route>
                        <fr:title text="Calcul du produit de deux entiers positifs">Calcul du produit de deux entiers positifs</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Comparer les deux algorithmes suivant pour calculer le produit de deux nombres entiers positifs, et évaluer leur complexité.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001L/</fr:uri>
                            <fr:display-uri>001L</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001L/</fr:route>
                            <fr:title text="Calcul du produit de deux entiers positifs (directement)">Calcul du produit de deux entiers positifs (directement)</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[// Entrées: Deux entiers x et y
// Sortie: Le produit des deux entrées
int produit (int x , int y){
  return x * y;
}]]>
</html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001M/</fr:uri>
                            <fr:display-uri>001M</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001M/</fr:route>
                            <fr:title text="Calcul de la somme de deux entiers positifs (avec une boucle)">Calcul de la somme de deux entiers positifs (avec une boucle)</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[// Entrées: Deux entiers x et y positifs
// Sortie: Le produit des deux entrées
int produit (int x , int y){
  int result;
  while (y  > 0){
    result = result + x;
    y = y - 1;
  }
  return result;
}]]>
</html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001N/</fr:uri>
                        <fr:display-uri>001N</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001N/</fr:route>
                        <fr:title text="Algorithme mystère (ou de l'importance de bien spécifier les algorithmes que l'on écrit)">Algorithme mystère (ou de l'importance de bien spécifier les algorithmes que l'on écrit)</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On considère l'algorithme suivant:</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001O/</fr:uri>
                            <fr:display-uri>001O</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001O/</fr:route>
                            <fr:title text="Mysère">Mysère</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[// Entrées: Un entier n >= 1
// Sortie: Un booléen mystère
bool mystere (int n){
  int i = 2;
  bool r = true;
  while (i < n && r){
    if (n%i == 0) {
      r = false;
    }
    i = i+1;
  }
  return r;
}]]></html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p><html:ol><html:li>Que renvoie cet algorithme?</html:li>
<html:li>Quelle est sa complexité?</html:li>
<html:li>Comment l'améliorer, et quelle est la complexité resultante?</html:li></html:ol>
Remarquez qu'il est beaucoup plus difficile de comprendre un algorithme lorsqu'on ne sais pas ce qu'il est censé faire, ni à quoi correspondent les variables mises en jeu. Cela illustre la remarque suivante</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001Y/</fr:uri>
                            <fr:display-uri>001Y</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001Y/</fr:route>
                            <fr:title text="Conventions de nommage">Conventions de nommage</fr:title>
                            <fr:taxon>Remarque</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Il est important de donner des noms raionnables aux variables, de manière à indiquer ce qu'elles sont censées représenter. Cela rend l'algorithme bien plus compréhensible.
<html:img src="https://imgs.xkcd.com/comics/x.png" /></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                          <fr:contributor>
                            <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                          </fr:contributor>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001P/</fr:uri>
                        <fr:display-uri>001P</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001P/</fr:route>
                        <fr:title text="Enumérations">Enumérations</fr:title>
                        <fr:taxon>Recueil d'exercices</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Voici maintenant une collection d'exercices visant à énumérer tous les nombres satisfaisant certaines propriétés.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001Q/</fr:uri>
                            <fr:display-uri>001Q</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001Q/</fr:route>
                            <fr:title text="Enumération des entiers pairs">Enumération des entiers pairs</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire un algorithme prenant en entrée un entier <html:code>n</html:code> positif et qui affiche tous les entiers pairs de taille inférieur ou égale à <html:code>n</html:code></html:li>
<html:li>Analyser la complexité de cet algorithme</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001R/</fr:uri>
                            <fr:display-uri>001R</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001R/</fr:route>
                            <fr:title text="Enumération des carrés parfaits">Enumération des carrés parfaits</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire un algorithme prenant en entrée un entier <html:code>n</html:code> positif et qui affiche tous les entiers carrés parfaits taille inférieur ou égale à <html:code>n</html:code></html:li>
<html:li>Analyser la complexité de cet algorithme</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001S/</fr:uri>
                            <fr:display-uri>001S</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001S/</fr:route>
                            <fr:title text="Enumération des nombres triangulaires">Enumération des nombres triangulaires</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:strong>Rappel:</html:strong> Un nombre triangulaire est un nombre de la forme <fr:tex display="inline"><![CDATA[1+2+\ldots +n]]></fr:tex>
<html:ol><html:li>Ecrire un algorithme prenant en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> positif et qui affiche tous les nombres triangulaires de taille inférieur ou égale à <fr:tex display="inline"><![CDATA[n]]></fr:tex></html:li>
<html:li>Analyser la complexité de cet algorithme</html:li></html:ol></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001T/</fr:uri>
                        <fr:display-uri>001T</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001T/</fr:route>
                        <fr:title text="Calcul de logarithme">Calcul de logarithme</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>
                          <html:ol><html:li>Ecrire un algorithme qui prend en entrée deux nombres entiers <fr:tex display="inline"><![CDATA[b,n]]></fr:tex> avec <fr:tex display="inline"><![CDATA[n > 1]]></fr:tex> et qui retourne la partie entière de <fr:tex display="inline"><![CDATA[\log _b(n)]]></fr:tex> à l'aide d'une boucle.</html:li>
<html:strong>Indice:</html:strong> On rappelle que c'est le plus grand entier <fr:tex display="inline"><![CDATA[q]]></fr:tex> tel que <fr:tex display="inline"><![CDATA[b ^ q \leq  n]]></fr:tex>.
<html:li>Quelle est la complexité de cet algorithme?</html:li></html:ol>
                        </html:p>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>27</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001U/</fr:uri>
                    <fr:display-uri>001U</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/001U/</fr:route>
                    <fr:title text="Tableaux">Tableaux</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>Les tableaux sont un <fr:link href="/cours-polytech-peip2-algo/000F/" title="Les types de données composés" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000F/" display-uri="000F" type="local">type de données composé</fr:link> permettant de représenter des ensembles ordonnées d'éléments, tous de même type. D'un point de vue des données représentées, ils ressemblent aux listes (<html:mark>TODO</html:mark>), mais ils diffèrent par le coût des différentes opérations que l'on peut faire dessus. La remarque suivante <html:mark>TODO</html:mark> donne une comparaison détaillée entre les tableaux et les listes.</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>1</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0023/</fr:uri>
                        <fr:display-uri>0023</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0023/</fr:route>
                        <fr:title text="Les opérations de base sur les tableaux">Les opérations de base sur les tableaux</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les tableaux sont des structures de données avec une taille statique, c'est-à-dire que lorsque l'on initialise un tableau, on doit à l'avance déclarer la taille que ce tableau aura, et celle ci ne changera jamais. Les tableaux permettent, en une seule opération d'accéder et de modifier une valeur placée en <fr:tex display="inline"><![CDATA[i^\textnormal {ème}]]></fr:tex> position pour tout entier <fr:tex display="inline"><![CDATA[i]]></fr:tex> inférieur à la taille du tableau.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0024/</fr:uri>
                            <fr:display-uri>0024</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0024/</fr:route>
                            <fr:title text="A partir de où commence-t-on à compter">A partir de où commence-t-on à compter</fr:title>
                            <fr:taxon>Remarque</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>En informatique, il est courrant de commencer à partir de <fr:tex display="inline"><![CDATA[0]]></fr:tex>, et donc, étant donné un tableau <fr:tex display="inline"><![CDATA[
\begin {array}{|c|c|c|}
\hline 
42 & 6 & 7 \\
\hline 
\end {array}
]]></fr:tex>, on dira que le nombre <fr:tex display="inline"><![CDATA[42]]></fr:tex> est en position <fr:tex display="inline"><![CDATA[0]]></fr:tex>, le nombre <fr:tex display="inline"><![CDATA[6]]></fr:tex> en position <fr:tex display="inline"><![CDATA[1]]></fr:tex>, et le nombre <fr:tex display="inline"><![CDATA[7]]></fr:tex> en position <fr:tex display="inline"><![CDATA[2]]></fr:tex>.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>1</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0022/</fr:uri>
                        <fr:display-uri>0022</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0022/</fr:route>
                        <fr:title text="Syntaxe pour manipuler les tableaux">Syntaxe pour manipuler les tableaux</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On utilisera la syntaxe de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> pour manipuler les tableaux</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0025/</fr:uri>
                            <fr:display-uri>0025</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0025/</fr:route>
                            <fr:title text="Déclaration et initialisation">Déclaration et initialisation</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Pour initialiser un tableau, par exemple un tableau d'élements de type <html:code>int</html:code> de taille <fr:tex display="inline"><![CDATA[9]]></fr:tex> s'appelant <html:code>monTableau</html:code>, on utilisera la syntaxe suivante

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[  int monTableau[9];]]>
</html:code></html:pre>
Bien sur, on peut adapter cet exemple, en changeant le type <html:code>int</html:code> en un autre primitif, et en changeant la taille et le nom du tableau. On peut également initialiser un tableau en même temps qu'on le déclare. Par exemple, le code suivant déclare le tableau <html:code>monTableau</html:code>, et initialise sa valeur à <fr:tex display="inline"><![CDATA[
\begin {array}{|c|c|c|c|c|c|c|c|c|}
\hline 
9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1\\
\hline 
\end {array}
]]></fr:tex>

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[   int monTableau[9] = {9,8,7,6,5,4,3,2,1};]]></html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0026/</fr:uri>
                            <fr:display-uri>0026</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0026/</fr:route>
                            <fr:title text="Accès à une position et affectation">Accès à une position et affectation</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fois un tableau déclaré, on peut accéder aux valeur stockées dans ce tableau. Par exemple, si l'on a déclaré un tableau s'appelant <html:code>monTableau</html:code> de taille <fr:tex display="inline"><![CDATA[9]]></fr:tex>, on pourra accéder à la position <fr:tex display="inline"><![CDATA[2]]></fr:tex> de ce tableau en écrivant

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[monTableau[2]]]>
</html:code></html:pre>
On pourra aussi modifier la valeur de la position <fr:tex display="inline"><![CDATA[2]]></fr:tex> de ce tableau, pour par exemple lui affecter la valeur 1729 en écrivant

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[monTableau[2] = 1729;]]>
</html:code></html:pre></html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>1</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0027/</fr:uri>
                                <fr:display-uri>0027</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/0027/</fr:route>
                                <fr:title text="Manipulations de tableaux">Manipulations de tableaux</fr:title>
                                <fr:taxon>Exercice</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>
                                  <html:ol><html:li>Ecrire un programme qui initialise un tableau s'appelant <html:code>monTableau</html:code> de taille <fr:tex display="inline"><![CDATA[5]]></fr:tex>, contenant initialement les valeurs <fr:tex display="inline"><![CDATA[
\begin {array}{|c|c|c|c|c|}
\hline 
0&1&2&3&4\\
\hline 
\end {array}
]]></fr:tex></html:li>
<html:li>A l'aide d'une boucle, écrire une fonction <html:code>incrementeTout</html:code> qui prend en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et tableau d'entier de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie une copie du tableau dans laquelle toutes les valeurs ont été incrémente de <fr:tex display="inline"><![CDATA[1]]></fr:tex>.</html:li>
<html:li>On appelle la fonction <html:code>incrementeTout(5,monTableau)</html:code>, quel est le tableau renvoyé en résultat?</html:li></html:ol>
                                </html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>1</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001W/</fr:uri>
                                <fr:display-uri>001W</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/001W/</fr:route>
                                <fr:title text="Accès hors des bornes du tableau">Accès hors des bornes du tableau</fr:title>
                                <fr:taxon>Remarque</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Si l'on a déclaré un tableau <html:code>monTableau</html:code> de taille <fr:tex display="inline"><![CDATA[24]]></fr:tex>, l'on pourra accéder et affecter sans problème toutes les positions de <fr:tex display="inline"><![CDATA[0]]></fr:tex> à <fr:tex display="inline"><![CDATA[23]]></fr:tex> dans ce tableau. En revanche, on considerera qu'essayer d'accéder ou d'affecter toute position supérieure ou égale à <fr:tex display="inline"><![CDATA[24]]></fr:tex> est une erreur (même si parfois le programme ne détecte pas cette erreur).</html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>1</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001X/</fr:uri>
                                <fr:display-uri>001X</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/001X/</fr:route>
                                <fr:title text="Valeur non initialisée">Valeur non initialisée</fr:title>
                                <fr:taxon>Remarque</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>On considérera qu'essayer d'accéder à une valeur avant qu'elle ait été initialisée est une erreur, même si en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> c'est accepté et cela renvoie une valeur par défaut associé au type de donnée du tableau. Par exemple, on considérera le code suivant comme incorrect pour ce cours, même s'il s'agit d'un code <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> valide

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[int[8] monTableau;
if(monTableau[4] == 5){ // On considère cette ligne comme étant une erreur, car monTableau[4] n'a jamais été affecté.
  return 0;
}
return;]]>
</html:code></html:pre></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0028/</fr:uri>
                            <fr:display-uri>0028</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0028/</fr:route>
                            <fr:title text="Matrices et tableaux multidimensionels">Matrices et tableaux multidimensionels</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>On peut représenter des matrices, c'est à dire des tableaux à double-entrée, comme des tableaux de tableaux. Pour déclarer et initialiser la matrice
<fr:tex display="block"><![CDATA[
\begin {pmatrix}
1&2&3&4 \\
5&6&7&8 \\
9&10&11&12
\end {pmatrix}
]]></fr:tex>
on pourra écrire

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[    int matrice[3][4] = {
        {1, 2, 3, 4},
        {5, 6, 7, 8},
        {9, 10, 11, 12}
    };]]></html:code></html:pre>
Pour ensuite accéder à l'élément dans la ligne <fr:tex display="inline"><![CDATA[0]]></fr:tex> et la colone <fr:tex display="inline"><![CDATA[2]]></fr:tex>, on écrira

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[    matrice[0][2] // Cette valeur est 3]]></html:code></html:pre>
Et pareillement pour l'affectaction. On peut aussi généraliser ce principe aux tableaux à <fr:tex display="inline"><![CDATA[n]]></fr:tex> dimensions, que l'on peut voir comme des tableaux de tableaux de tableaux... La syntaxe est similaire à celle des matrices, avec plus de crochets.
</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>1</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0029/</fr:uri>
                        <fr:display-uri>0029</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0029/</fr:route>
                        <fr:title text="Algorithmes classiques sur les tableaux">Algorithmes classiques sur les tableaux</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>L'objectif de cette section est de se familiariser avec les tableaux, grâce à plusieurs algorithmes classiques sur ces derniers. Beaucoup de ces algorithmes sont donnés en exercices.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0030/</fr:uri>
                            <fr:display-uri>0030</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0030/</fr:route>
                            <fr:title text="Trouver le maximum dans un tableau d'entiers">Trouver le maximum dans un tableau d'entiers</fr:title>
                            <fr:taxon>Algorithme</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
// Entrée : Un entier n &gt; 0 et un tableau d'entier tableau de taille n
// Sortie : Un entier représentant le maximum contenu dans tableau
int maximum (int n, int tableau[]){
  int max = tableau [0];
  // A la fin de la boucle i, max contient le maximum
  // de tableau situé entre les indices 0 et i
  for (int i = 1; i &lt; n; i++ ){
    if (max &lt; tableau[i]){
      max = tableau[i];
    }
  }
  return max;
}
</html:code></html:pre>
<html:strong>Complexité</html:strong>: Pour analyser la complexité de cet algorithme, on compte le nombre de comparaison. A chaque passage dans la boucle, on effectue exactement une comparaison (<html:code>max &lt; tableau[i]</html:code>), et on fait <fr:tex display="inline"><![CDATA[n-1]]></fr:tex> passages dans la boucle. Cette fonction fera donc toujours exactement <fr:tex display="inline"><![CDATA[n-1]]></fr:tex> comparaisons, ce qui donne une complexité en <fr:tex display="inline"><![CDATA[\mathcal {O}(n)]]></fr:tex> (<fr:link href="/cours-polytech-peip2-algo/0017/" title="Linéaire" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0017/" display-uri="0017" type="local">complexité linéaire</fr:link>).
</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0031/</fr:uri>
                            <fr:display-uri>0031</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0031/</fr:route>
                            <fr:title text="Minimum d'un tableau">Minimum d'un tableau</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>minimum</html:code> qui prend en argument un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie le minimum de ce tableau</html:li>
<html:li>Ecrire une fonction <html:code>minimumParmi</html:code> qui prend en argument deux entiers <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n]]></fr:tex> tels que <fr:tex display="inline"><![CDATA[k<n]]></fr:tex>, et un tableau de taille au moins <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie le minimum parmis tous les éléments de ce tableau situé entre les positions <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n-1]]></fr:tex>.</html:li>
<html:li>Ecrire une fonction <html:code>indiceMinimum</html:code> qui prend en argument deux entiers <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n]]></fr:tex> tels que <fr:tex display="inline"><![CDATA[k<n]]></fr:tex>, et un tableau de taille au moins <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie la position à laquelle se situe minimum parmis tous les éléments de ce tableau situé entre les positions <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n-1]]></fr:tex>.</html:li>
<html:li>Donner une estimation de la complexité de chacune de ces fonctions.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0032/</fr:uri>
                            <fr:display-uri>0032</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0032/</fr:route>
                            <fr:title text="Crible d'Erathostene">Crible d'Erathostene</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:mark>TODO</html:mark>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003E/</fr:uri>
                            <fr:display-uri>003E</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003E/</fr:route>
                            <fr:title text="Vérifier si un tableau est trié">Vérifier si un tableau est trié</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:mark>TODO</html:mark>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>2</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003F/</fr:uri>
                        <fr:display-uri>003F</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/003F/</fr:route>
                        <fr:title text="Représentation en mémoire des tableaux">Représentation en mémoire des tableaux</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les tableaux que l'on utilise en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> sont statiques. C'est à dire que lors de l'initialisation, on déclare la taille du tableau, et le tableau ne changera jamais de taille. Cela permet au système d'exploitation, lors de la création d'un tableau, de réserver à l'avance une zone de la bonne taille dans la mémoire, qui servira à représenter notre tableau.
</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>20</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004N/</fr:uri>
                            <fr:display-uri>004N</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/004N/</fr:route>
                            <fr:title text="Représentation mémoire d'un tableau de taille 5">Représentation mémoire d'un tableau de taille 5</fr:title>
                            <fr:taxon>Exemple</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>On peut représenter graphiquement la représentation en mémoire d'un tableau <html:code>a</html:code> de taille <fr:tex display="inline"><![CDATA[5]]></fr:tex> comme ceci:
<fr:resource hash="ab8a7b290b1347031c4963fee784857b"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/ab8a7b290b1347031c4963fee784857b.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{5}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,4} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{a[\i]}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {Autres\\variables};
\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Pour savoir comment accéder au tableau, le programme crée une variable séparée qui sert à stocker l'addresse de la mémoire où le tableau a été créé.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>20</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004O/</fr:uri>
                            <fr:display-uri>004O</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/004O/</fr:route>
                            <fr:title text="Représentation mémoire d'un tableau de taille 5">Représentation mémoire d'un tableau de taille 5</fr:title>
                            <fr:taxon>Exemple</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>On peut améliorer la <fr:link href="/cours-polytech-peip2-algo/004N/" title="Représentation mémoire d'un tableau de taille 5" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004N/" display-uri="004N" type="local">représentation graphique</fr:link> du tableau <html:code>a</html:code> de taille <fr:tex display="inline"><![CDATA[5]]></fr:tex> en ajoutant le pointeur, comme ceci:
<fr:resource hash="1281ab85f7c4a33121288d2caf7988d9"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/1281ab85f7c4a33121288d2caf7988d9.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{5}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,4} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{a[\i]}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Au moment de la déclaration, le système réserve une zone de la bonne taille, constitué de cases contigues en mémoire. Cela permet de rapidement accéder à n'importe laquelle des cases du tableau. En effet, connaissant la valeur de <html:code>a</html:code>, pointant vers l'adresse mémoire correspondant au début du tableau, accéder à une autre position dans le tableau se fait grâce à un simple décalage, une opération arithmétique. Cela justifie que les tableaux ont un accès en <fr:link href="/cours-polytech-peip2-algo/001J/" title="Constant" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001J/" display-uri="001J" type="local">temps constant</fr:link>.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>20</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003X/</fr:uri>
                            <fr:display-uri>003X</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003X/</fr:route>
                            <fr:title text="Passage par valeur des tableaux">Passage par valeur des tableaux</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Lorsque l'on passe un tableau en argument d'une fonction, le tableau est <fr:link href="/cours-polytech-peip2-algo/003O/" title="Passage par valeur" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003O/" display-uri="003O" type="local">passé par valeur</fr:link>. Cela signifie que la fonction crée une variable locale dans le tableau et copie la valeur du tableau dans sa variable locale. Afin d'éviter de recopier toutes les cases du tableau pour appeler la fonction (ce qui induirait un coût <fr:link href="/cours-polytech-peip2-algo/0017/" title="Linéaire" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0017/" display-uri="0017" type="local">linéaire</fr:link>), <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> part du principe que la "valeur" d'un tableau est la case mémoire contenant l'adresse de la position à laquelle le tableau est stocké.</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>20</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003V/</fr:uri>
                                <fr:display-uri>003V</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/003V/</fr:route>
                                <fr:title text="Modification en place des tableaux">Modification en place des tableaux</fr:title>
                                <fr:taxon>Exemple</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Une conséquence de la <fr:link href="/cours-polytech-peip2-algo/003F/" title="Représentation en mémoire des tableaux" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003F/" display-uri="003F" type="local">représentation en mémoire des tableaux</fr:link> est que si une fonction effectue une modification sur un tableau via un accès à la zone mémoire contenant les données, cette modification sera visible à l'extérieure de la fonction également.</html:p>
                                <fr:tree show-metadata="false">
                                  <fr:frontmatter>
                                    <fr:authors>
                                      <fr:author>
                                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                      </fr:author>
                                    </fr:authors>
                                    <fr:date>
                                      <fr:year>2025</fr:year>
                                      <fr:month>11</fr:month>
                                      <fr:day>4</fr:day>
                                    </fr:date>
                                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004P/</fr:uri>
                                    <fr:display-uri>004P</fr:display-uri>
                                    <fr:route>/cours-polytech-peip2-algo/004P/</fr:route>
                                    <fr:title text="Modification en place d'un tableau">Modification en place d'un tableau</fr:title>
                                    <fr:taxon>Algorithme</fr:taxon>
                                  </fr:frontmatter>
                                  <fr:mainmatter>
                                    <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[void echangerPremiers (int x[]){
  int y = x[0];
  x[0] = x[1];
  x[1] = y;
}

int main (){
  int a[2] = {0,1};
  echangerPremiers (a);
  // a ce point du programme,
  // a = {1,0}
  return 0;
}]]>
</html:code></html:pre></html:p>
                                  </fr:mainmatter>
                                </fr:tree>
                                <fr:tree show-metadata="false">
                                  <fr:frontmatter>
                                    <fr:authors>
                                      <fr:author>
                                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                      </fr:author>
                                    </fr:authors>
                                    <fr:date>
                                      <fr:year>2025</fr:year>
                                      <fr:month>11</fr:month>
                                      <fr:day>20</fr:day>
                                    </fr:date>
                                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004Q/</fr:uri>
                                    <fr:display-uri>004Q</fr:display-uri>
                                    <fr:route>/cours-polytech-peip2-algo/004Q/</fr:route>
                                    <fr:title text="Modification en place d'un tableau">Modification en place d'un tableau</fr:title>
                                    <fr:taxon>Illustration</fr:taxon>
                                  </fr:frontmatter>
                                  <fr:mainmatter>
                                    <html:p>On peut illustrer graphiquement l'algorithme précédent grâce à une série de schémas représentant la mémoire à différents moments de l'exécution du programme.
<html:ol><html:li>Dans la fonction <html:code>main</html:code>, avant appel à la fonction <html:code>echangerPremiers</html:code>, on a créé le tableau suivant en mémoire:
<fr:resource hash="a2aac317ee0c8db601bd7ee1f2c12ff0"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/a2aac317ee0c8db601bd7ee1f2c12ff0.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{\i}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {Autres\\variables};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>Au moment de l'appel à la fonction <html:code>echangerPremiers</html:code>, une copie de la variable <html:code>a</html:code> est crée, que l'on note ici <html:code>x</html:code>, c'est la variable locale à la fonction <html:code>echangerPremiers</html:code> qui représente la valeur de son argument
<fr:resource hash="6e61c42bd526a4418ec544d74ad58f90"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/6e61c42bd526a4418ec544d74ad58f90.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{\i}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

  \draw[thick] (\base+\n*\cellw+3*\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (x) at (\base+\n*\cellw+3*\cellw+0.8,\y+0.45) {\texttt{x}};

  \fill[gray!20] (\base+\n*\cellw+4*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (x) to[out=-90, in=-90, looseness=0.35] (\base,\y);


\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>La fonction <html:code>echangerPremiers</html:code> performe l'échange des deux premiers éléments dans la zone mémoire pointée par <html:code>x</html:code>
<fr:resource hash="d5a1615c111999eb452dd1de3071dadf"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/d5a1615c111999eb452dd1de3071dadf.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
  }
  \node at (\base+0.8,\y+0.45) {\texttt{1}};
  \node at (\base+\cellw+0.8,\y+0.45) {\texttt{0}};

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

  \draw[thick] (\base+\n*\cellw+3*\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (x) at (\base+\n*\cellw+3*\cellw+0.8,\y+0.45) {\texttt{x}};

  \fill[gray!20] (\base+\n*\cellw+4*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (x) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>Après appel à la fonction <html:code>echangerPremiers</html:code>, la variable <html:code>x</html:code> est effacée. Remarquez que la variable <html:code>a</html:code> pointe toujours vers la même zone mémoire, dans laquelle les valeurs <html:code>0</html:code> et <html:code>1</html:code> ont été échangées:
<fr:resource hash="2f7ab7f02652dffdde14562766e2c7ee"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/2f7ab7f02652dffdde14562766e2c7ee.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
  }
  \node at (\base+0.8,\y+0.45) {\texttt{1}};
  \node at (\base+\cellw+0.8,\y+0.45) {\texttt{0}};

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {Autres\\variables};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li></html:ol></html:p>
                                  </fr:mainmatter>
                                </fr:tree>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>11</fr:month>
                      <fr:day>2</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003G/</fr:uri>
                    <fr:display-uri>003G</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/003G/</fr:route>
                    <fr:title text="Algorithmes de tri itératifs">Algorithmes de tri itératifs</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>Etant donné un tableau contenant des nombres entiers, on souhaite trier ce tableau, c'est à dire changer la position des éléments dans le tableau, de manière à ce que ces derniers soient rangés par ordre croissant. Les algorithmes de tris sont de très bons exemples pour travailler sur la complexité des algorithmes, car il en existe de nombreux différents, qui ont tous des spécificités propres.</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>2</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0033/</fr:uri>
                        <fr:display-uri>0033</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0033/</fr:route>
                        <fr:title text="Tri par sélection">Tri par sélection</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>L'objectif de cet exercice est d'implémenter le tri par sélection</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0034/</fr:uri>
                            <fr:display-uri>0034</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0034/</fr:route>
                            <fr:title text="Le principe du tri par sélection">Le principe du tri par sélection</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Le <fr:link href="https://fr.wikipedia.org/wiki/Tri_par_sélection" type="external">tri par sélection</fr:link> est certainement l'algorithme de tri le plus intuitif. On trie le tableau en d'abord le plus petit élément dans la première case, puis le deuxième plus petit dans la deuxième case, puis le troisième plus petit dans la troisième case etc. Concrètement, à l'étape <fr:tex display="inline"><![CDATA[i]]></fr:tex>, on aura déjà rangé par ordre croissant tous les <fr:tex display="inline"><![CDATA[i-1]]></fr:tex> plus petits éléments du tableau dans les <fr:tex display="inline"><![CDATA[i-1]]></fr:tex> premières cases du tableau. On va alors parcourir toutes les cases restantes dans le tableau, pour trouver l'indice du minimum des cases restante, et échanger la valeur de la case <fr:tex display="inline"><![CDATA[i]]></fr:tex> courante avec la valeur de la case contenant le minimum. A la fin de l'étape <fr:tex display="inline"><![CDATA[i]]></fr:tex>, on aura ainsi placé le <fr:tex display="inline"><![CDATA[i^{\textnormal {ème}}]]></fr:tex> plus petit élément dans la case <fr:tex display="inline"><![CDATA[i]]></fr:tex>.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0035/</fr:uri>
                            <fr:display-uri>0035</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0035/</fr:route>
                            <fr:title text="Illustrations du tri par sélection">Illustrations du tri par sélection</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les animations suivantes peuvent aider à comprendre le tri par sélection. La première est tirée de la page wikipedia, la seconde a été réalisée à l'aide du logiciel <fr:link href="/cours-polytech-peip2-algo/0036/" title="Sound of sorting" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0036/" display-uri="0036" type="local">sound of sorting</fr:link> <html:mark>TODO</html:mark></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0031/</fr:uri>
                            <fr:display-uri>0031</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0031/</fr:route>
                            <fr:title text="Minimum d'un tableau">Minimum d'un tableau</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>minimum</html:code> qui prend en argument un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie le minimum de ce tableau</html:li>
<html:li>Ecrire une fonction <html:code>minimumParmi</html:code> qui prend en argument deux entiers <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n]]></fr:tex> tels que <fr:tex display="inline"><![CDATA[k<n]]></fr:tex>, et un tableau de taille au moins <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie le minimum parmis tous les éléments de ce tableau situé entre les positions <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n-1]]></fr:tex>.</html:li>
<html:li>Ecrire une fonction <html:code>indiceMinimum</html:code> qui prend en argument deux entiers <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n]]></fr:tex> tels que <fr:tex display="inline"><![CDATA[k<n]]></fr:tex>, et un tableau de taille au moins <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui renvoie la position à laquelle se situe minimum parmis tous les éléments de ce tableau situé entre les positions <fr:tex display="inline"><![CDATA[k]]></fr:tex> et <fr:tex display="inline"><![CDATA[n-1]]></fr:tex>.</html:li>
<html:li>Donner une estimation de la complexité de chacune de ces fonctions.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0037/</fr:uri>
                            <fr:display-uri>0037</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0037/</fr:route>
                            <fr:title text="Echange de deux cases dans un tableau">Echange de deux cases dans un tableau</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction qui prend en argument un tableau d'entiers, et deux entiers <fr:tex display="inline"><![CDATA[i]]></fr:tex> et <fr:tex display="inline"><![CDATA[j]]></fr:tex> tout deux strictement inférieurs à la taille du tableau, et qui échange le contenu des positions <fr:tex display="inline"><![CDATA[i]]></fr:tex> et <fr:tex display="inline"><![CDATA[j]]></fr:tex> dans le tableau.</html:li>
<html:li>Evaluer la complexité de cette fonction.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0038/</fr:uri>
                            <fr:display-uri>0038</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0038/</fr:route>
                            <fr:title text="Le tri par sélection">Le tri par sélection</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>triselection</html:code> prenant en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau d'entier de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et effectuant le tri par sélection de ce tableau.</html:li>
<html:li>Evaluer la complexité de cette fonction, en fonction de <fr:tex display="inline"><![CDATA[n]]></fr:tex>.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer un tableau puis le trier et afficher les résultat pour vérifier qu'ils sont effectivement triés.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer des tableaux de différentes tailles, et <fr:link href="/cours-polytech-peip2-algo/0045/" title="Calculer le temps mis pour exécuter une fonction" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0045/" display-uri="0045" type="local">afficher le temps</fr:link> mis par la fonction de tri, en fonction de la taille du tableau en entrée sur une courbe.</html:li>
<html:li>Comparer la courbe obtenue avec la complexité théorique attendue.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>2</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0039/</fr:uri>
                        <fr:display-uri>0039</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0039/</fr:route>
                        <fr:title text="Tri par insertion">Tri par insertion</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>L'objectif de cet exercice est d'implémenter le tri par insertion</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003A/</fr:uri>
                            <fr:display-uri>003A</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003A/</fr:route>
                            <fr:title text="Le principe du tri par insertion">Le principe du tri par insertion</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Le <fr:link href="https://fr.wikipedia.org/wiki/Tri_par_insertion" type="external">tri par insertion</fr:link> consistant à trier d'abord les deux premières cases du tableau, puis à trier les 3 premières cases en insérant la 3e à la bonne place, puis la 4e en l'insérant à la bonne place, etc. Concrètement avant l'étape <fr:tex display="inline"><![CDATA[i]]></fr:tex>, on aura trié les <fr:tex display="inline"><![CDATA[i-1]]></fr:tex> premières cases du tableau. On va alors regarder la case en position <fr:tex display="inline"><![CDATA[i]]></fr:tex> et comparer son contenu avec toutes les cases des positions <fr:tex display="inline"><![CDATA[0,...,i-1]]></fr:tex>, jusqu'à trouver la position <fr:tex display="inline"><![CDATA[k]]></fr:tex> à laquelle cette case doit être insérée, pour que le tableau soit trié. Finalement, on va insérer une la valeur de la case <fr:tex display="inline"><![CDATA[i]]></fr:tex> en position <fr:tex display="inline"><![CDATA[k]]></fr:tex>, et pour se faire, il faudra aussi décaler toutes les valeurs dans les positions <fr:tex display="inline"><![CDATA[k,...,i-1]]></fr:tex> de <fr:tex display="inline"><![CDATA[1]]></fr:tex> vers la droite. Cela termine l'étape <fr:tex display="inline"><![CDATA[i]]></fr:tex>, à l'issue de laquelle on aura effectivement trié les <fr:tex display="inline"><![CDATA[i]]></fr:tex> premières cases du tableau.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003B/</fr:uri>
                            <fr:display-uri>003B</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003B/</fr:route>
                            <fr:title text="Illustrations du tri par insertion">Illustrations du tri par insertion</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les animations suivantes peuvent aider à comprendre le tri par sélection. La première est tirée de la page wikipedia, la seconde a été réalisée à l'aide du logiciel <fr:link href="/cours-polytech-peip2-algo/0036/" title="Sound of sorting" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0036/" display-uri="0036" type="local">sound of sorting</fr:link> <html:mark>TODO</html:mark></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003C/</fr:uri>
                            <fr:display-uri>003C</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003C/</fr:route>
                            <fr:title text="Insertion dans un tableau trié">Insertion dans un tableau trié</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>inserer</html:code> qui prend en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex>, un tableau de taille <fr:tex display="inline"><![CDATA[\ge  n]]></fr:tex> dont les <fr:tex display="inline"><![CDATA[n]]></fr:tex> premières entrées sont triées, et qui insère le contenu de la position <fr:tex display="inline"><![CDATA[n]]></fr:tex> à la bonne position, de manière à ce qu'neusite les <fr:tex display="inline"><![CDATA[n+1]]></fr:tex> prmières entrées du tableau soient triées</html:li>
<html:li>Evaluer la complexité de cette fonction.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003D/</fr:uri>
                            <fr:display-uri>003D</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003D/</fr:route>
                            <fr:title text="Le tri par insertion">Le tri par insertion</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>triInsertion</html:code> qui prend en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui effectue le tri par insertion sur ce tableau.</html:li>
<html:li>Evaluer la complexité de cet algorithme en fonction de <fr:tex display="inline"><![CDATA[n]]></fr:tex>.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer un tableau puis le trier et afficher les résultat pour vérifier qu'ils sont effectivement triés.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer des tableaux de différentes tailles, et <fr:link href="/cours-polytech-peip2-algo/0045/" title="Calculer le temps mis pour exécuter une fonction" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0045/" display-uri="0045" type="local">afficher le temps</fr:link> mis par la fonction de tri, en fonction de la taille du tableau en entrée sur une courbe.</html:li>
<html:li>Comparer la courbe obtenue avec la complexité théorique attendue.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>12</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0040/</fr:uri>
                        <fr:display-uri>0040</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0040/</fr:route>
                        <fr:title text="Le tri a bulles">Le tri a bulles</fr:title>
                        <fr:taxon>Exercice</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>L'objectif de cet exercice est d'implémenter le tri à bulles</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>12</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0041/</fr:uri>
                            <fr:display-uri>0041</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0041/</fr:route>
                            <fr:title text="Le principe du tri à bulles">Le principe du tri à bulles</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Le <fr:link href="https://fr.wikipedia.org/wiki/Tri_à_bulles" type="external">tri à bulles</fr:link> consiste à parcourir le tableau en faisant "remonter" les valeur les plus grandes du tableau au fur et à mesure. A chaque étape du parcours, on compare la case courante à la case suivante, et si la case courante est plus grande que la case suivante, on échange les deux, puis on passe à la case suivante et on recommence l'opération. On peut se convaincre qu'après un parcours complet du tableau, la plus grande valeur se trouvera toujours en dernière position. On effectue ensuite autant de parcours que nécessaire pour que le tableau soit trié.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>12</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0042/</fr:uri>
                            <fr:display-uri>0042</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0042/</fr:route>
                            <fr:title text="Illustrations du tri par sélection">Illustrations du tri par sélection</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les animations suivantes peuvent aider à comprendre le tri par sélection. La première est tirée de la page wikipedia, la seconde a été réalisée à l'aide du logiciel <fr:link href="/cours-polytech-peip2-algo/0036/" title="Sound of sorting" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0036/" display-uri="0036" type="local">sound of sorting</fr:link> <html:mark>TODO</html:mark></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>12</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0043/</fr:uri>
                            <fr:display-uri>0043</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0043/</fr:route>
                            <fr:title text="Le tri à bulles">Le tri à bulles</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>
                              <html:ol><html:li>Ecrire une fonction <html:code>triBulles1</html:code> qui prend en entrée un entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> et un tableau de taille <fr:tex display="inline"><![CDATA[n]]></fr:tex>, et qui effectue le tri à bulles, en parcourant le tableau entier <fr:tex display="inline"><![CDATA[n]]></fr:tex> fois.</html:li>
<html:li>Améliorer l'algorithme précédent, et écrire une fonction <html:code>triBulles2</html:code>: Après la <fr:tex display="inline"><![CDATA[k^e]]></fr:tex> itération, les <fr:tex display="inline"><![CDATA[k]]></fr:tex> plus grands éléments de ce tableau sont à la bonne position, on peut donc arrêter le parcours à la position <fr:tex display="inline"><![CDATA[k]]></fr:tex></html:li>
<html:li>Ecrire une dernière amélioration <html:code>triBulles3</html:code> qui s'arrête dès que l'on fait un parcours qui ne fait aucun échange, même si l'on n'a pas fait <fr:tex display="inline"><![CDATA[n]]></fr:tex> itérations.</html:li>
<html:li>Evaluer la complexité de ces 3 algorithmes en fonction de <fr:tex display="inline"><![CDATA[n]]></fr:tex>.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer un tableau puis le trier avec chacunes des 3 fonctions et et afficher les résultat pour vérifier qu'ils sont effectivement triés.</html:li>
<html:li>En utilisant le <fr:link href="/cours-polytech-peip2-algo/0044/" title="Remplir un tableau avec des valeurs aléatoires" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0044/" display-uri="0044" type="local">générateur de tableau aléatoires</fr:link>, générer des tableaux de différentes tailles, et <fr:link href="/cours-polytech-peip2-algo/0045/" title="Calculer le temps mis pour exécuter une fonction" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0045/" display-uri="0045" type="local">afficher le temps</fr:link> mis par les fonctions <html:code>triBulles1</html:code>, <html:code>triBulles2</html:code> et <html:code>triBulles3</html:code> en fonction de la taille des tableaux en entrée sur une courbe.</html:li>
<html:li>Comparer les courbes obtenues entre elles, et  avec la complexité théorique attendue.</html:li></html:ol>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
              </fr:mainmatter>
            </fr:tree>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>11</fr:month>
                  <fr:day>20</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004R/</fr:uri>
                <fr:display-uri>004R</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/004R/</fr:route>
                <fr:title text="La récursivité">La récursivité</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>Ce chapitre est consacré à la récursivité. La récursivité est un concept important de l'informatique, qui aide à mettre au point des algorithmes et à programmer. La récursivité permet souvent de rendre les algorithmes plus clairs et concis, mais elle aide aussi souvent à écrire des algorithmes plus efficaces, avec une complexité moins élevée. L'analyse de complexité des fonctions récursives fait intervenir des suites satisfaisant des relations de récurrence.</html:p>
              </fr:mainmatter>
            </fr:tree>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                  <fr:contributor>
                    <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                  </fr:contributor>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>10</fr:month>
                  <fr:day>27</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000V/</fr:uri>
                <fr:display-uri>000V</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/000V/</fr:route>
                <fr:title text="Notions de référence">Notions de référence</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>Ce chapitre constitue une référence sur  les notions importantes que nous allons étudier et utiliser tout au long du cours. Il n'a pas vocation à être lu de bout-en-bout, mais à servir de point d'ancrage auquel se référer tout au long de la lecture de ce cours. Il ne faudra donc pas hésiter à sauter à ce chapitre au cours de la lecture autant que nécessaire.</html:p>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>7</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000C/</fr:uri>
                    <fr:display-uri>000C</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/000C/</fr:route>
                    <fr:title text="Écrire des algorithmes">Écrire des algorithmes</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>
                      <html:img src=" https://imgs.xkcd.com/comics/(.png" />
                    </html:p>
                    <html:p>Pour écrire des algorithmes, on utilisera un langage de programmation. De nombreux cours d'algorithmique s'appuyent sur du <html:em>pseudo-code</html:em>: un language fictif, dont l'objectif est d'être suffisamment générique et vague pour ne pas dépendre de manière trop spécifique d'un choix de language de programmation. Pour ce cours j'ai fait le choix d'utiliser le language <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>. Une raison pour ce choix est la continuité pédagogique: les cours précédents à Polytech Paris-Saclay étaient déjà en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>. Une autre raison est que le pseudo-code est un language très peu spécifié, avec une syntaxe floue. Cela peut rapidement ammener à des confusions, et rajoute de la friction à l'apprentissage. Cependant le choix de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> n'est pas un choix central pour l'enseignement
<html:ul><html:li>Pour les besoin du cours, on se limitera à un très petit sous ensemble du langage <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource></html:li>
<html:li>On ne mettra pas fortement l'accent sur la justesse exacte de la syntaxe</html:li></html:ul>
Le reste de cette section présente les caractéristiques du sous-ensemble de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> que nous utiliserons
</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000D/</fr:uri>
                        <fr:display-uri>000D</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000D/</fr:route>
                        <fr:title text="Les types de données">Les types de données</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Selon le proverbe, il ne faut pas mélanger les torchons et les serviettes. Ce sont là des types de données. Ils servent à se rappeler de quelle nature est l'objet qu'une variable doit représenter, afin d'éviter de faire des opérations n'ayant pas de sens, comme additionner une chaîne de caractères avec un nombre.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000E/</fr:uri>
                            <fr:display-uri>000E</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000E/</fr:route>
                            <fr:title text="Les types de données de base">Les types de données de base</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les types de données de base de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> que nous allons utiliser sont les booléens <html:code>bool</html:code> (qui ne peuvent prendre que 2 valeurs, <html:code>true</html:code> et <html:code>false</html:code>), les entiers <html:code>int</html:code>, et les caractères <html:code>char</html:code> (comme par exemple <html:code>'a'</html:code>, <html:code>'*'</html:code>, <html:code>'5'</html:code>...). Pour les besoins de ce cours, nous allons ignorer les limitations liées aux dépassement arithémtiques, et, sauf mention explicite du contraire, nous considérerons que les valeurs de type <html:code>int</html:code> peuvent être n'importe quel nombre entier. Nous ignorerons également que les caractères sont aussi des entiers, et considéreront donc par exemple qu'additionner deux caractères n'a pas de sens.</html:p>
                            <html:p>Il existe en réalité beaucoup de types de données de base en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>, en particulier les nombres flottants, permettant de représenter des nombres décimaux, mais ils ne nous seront pas utiles dans ce cours.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>7</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000F/</fr:uri>
                            <fr:display-uri>000F</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000F/</fr:route>
                            <fr:title text="Les types de données composés">Les types de données composés</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Aux types de données de base s'ajoutent d'autres types de données composés, que l'on construit à partir de ces types primitifs <html:ul><html:li><fr:link href="/cours-polytech-peip2-algo/001U/" title="Tableaux" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001U/" display-uri="001U" type="local">Les tableaux</fr:link></html:li>
<html:li>Les listes <html:mark>TODO</html:mark></html:li>
<html:li>Les arbres <html:mark>TODO</html:mark></html:li>
<html:li>Les chaînes de caractères <html:mark>TODO</html:mark></html:li></html:ul></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Notons l'absence de <fr:link href="/cours-polytech-peip2-algo/003U/" title="Les pointeurs" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003U/" display-uri="003U" type="local">pointeurs</fr:link>: On y fera quelques mentions, mais ce n'est pas le point central de ce cours. Les types de données composés présentés ci-dessus sont secrètement des pointeurs: une valeur de ce type est une adresse mémoire contenant les données prescrites.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000G/</fr:uri>
                        <fr:display-uri>000G</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000G/</fr:route>
                        <fr:title text="Variables et affectations">Variables et affectations</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les variables permettent de stocker des valeur que l'on a besoin de manipuler lors de l'exécution de l'aglorithme. Elles sont déclarées en étant précédées de leur type de donnée comme dans l'exemple suivant

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[int x;]]></html:code></html:pre>
Pour affecter une valeur à une variable on utilisera le symbole <html:code>=</html:code>. Ainsi, l'extrait de code suivant déclare une variable <html:code>x</html:code> de type <html:code>int</html:code> et lui affecte la valeur <html:code>5</html:code>

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[int x;
x = 5;]]></html:code></html:pre>
On pourra abréger ce code en 1 seule ligne, en echaînant la déclaration et l'affectation, comme suit

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[int x = 5;]]></html:code></html:pre>
On considérera qu'essayer d'accéder à une valeur qui a été déclarée mais à laquelle aucune valeur n'a été affectée est une erreur, même si <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> ne lève pas d'erreur et renvoie une valeur.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001Y/</fr:uri>
                            <fr:display-uri>001Y</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001Y/</fr:route>
                            <fr:title text="Conventions de nommage">Conventions de nommage</fr:title>
                            <fr:taxon>Remarque</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Il est important de donner des noms raionnables aux variables, de manière à indiquer ce qu'elles sont censées représenter. Cela rend l'algorithme bien plus compréhensible.
<html:img src="https://imgs.xkcd.com/comics/x.png" /></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000H/</fr:uri>
                        <fr:display-uri>000H</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000H/</fr:route>
                        <fr:title text="Fonctions, méthodes, procédures">Fonctions, méthodes, procédures</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On pourra définir des algorithmes auxilliaires permettant de nous aider à résoudre un problème concret. L'on écrira ces algorithmes sous forme de fonctions (que l'on appellera aussi sans distinction méthodes ou procédures). On commencera toujours la définition d'une fonction en indiquant son type de retour, son nom, ainsi que ses arguments avec leur type. Si une fonction ne renvoie pas d'argument, on remplacera le type de retour par le mot-clé <html:code>void</html:code>. Pour indiquer la valeur qu'une fonction renvoie, on utilisera le mot clé <html:code>return</html:code>.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003I/</fr:uri>
                            <fr:display-uri>003I</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003I/</fr:route>
                            <fr:title text="Une fonction">Une fonction</fr:title>
                            <fr:taxon>Exemple</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Le code suivant définit une fonction <html:code>majuscule</html:code> prenant une caractère et retournant un caractère

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[char majuscule (char caractère){
  /* Le code de la fonction est ici */
  return caractère
}]]></html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>2</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003H/</fr:uri>
                            <fr:display-uri>003H</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003H/</fr:route>
                            <fr:title text="Passage par valeur et passage par référence">Passage par valeur et passage par référence</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Par défaut, les appels de fonction en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> se font en <fr:link href="/cours-polytech-peip2-algo/003O/" title="Passage par valeur" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003O/" display-uri="003O" type="local">passage par valeur</fr:link>, mais il est également possible de les déclarer en <fr:link href="/cours-polytech-peip2-algo/003P/" title="Passage par référence" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003P/" display-uri="003P" type="local">passage par référence</fr:link>. La valeur des <fr:link href="/cours-polytech-peip2-algo/000F/" title="Les types de données composés" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000F/" display-uri="000F" type="local">type de donné composé</fr:link> auxquels on s'intéresse est son adresse. Donc passer un argument d'un type composé à une fonction ressemble à un passage par référence.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000I/</fr:uri>
                        <fr:display-uri>000I</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000I/</fr:route>
                        <fr:title text="Valeurs de base et comparaison">Valeurs de base et comparaison</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les valeurs de base sont les valeurs d'un <fr:link href="/cours-polytech-peip2-algo/000E/" title="Les types de données de base" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000E/" display-uri="000E" type="local">type de base</fr:link>. Les trois principaux moyens d'obtenir une valeur de base sont les suivant:
<html:ul><html:li>Un litéral, qui peut être: <html:ol><html:li><html:code>true</html:code> ou <html:code>false</html:code> de type <html:code>bool</html:code></html:li>
<html:li>un entier <html:code>1</html:code>, <html:code>2</html:code>, <html:code>3</html:code>,... de type <html:code>int</html:code></html:li>
<html:li>un caractère <html:code>'A'</html:code>, <html:code>'*'</html:code>, <html:code>'b'</html:code>,... de type <html:code>char</html:code></html:li></html:ol></html:li>
<html:li>Une variable, dont le type a été déclaré</html:li>
<html:li>Un appel de fonction</html:li></html:ul></html:p>
                        <html:p>Pour comparer des valeurs de base, l'on utilise l'opérateur <html:code>==</html:code>, qui renvoie le booléen <html:code>true</html:code> si les deux valeurs sont égales, et <html:code>false</html:code> si les deux valeurs sont différentes. Ceci est illustré ci-dessous

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[int x = 5;
x == 5 // cette comparaison est vraie]]></html:code></html:pre>

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié"><![CDATA[int x = 6;
x == 5 // cette comparaison est fausse]]></html:code></html:pre></html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>1</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001Z/</fr:uri>
                            <fr:display-uri>001Z</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001Z/</fr:route>
                            <fr:title text="Affectation et comparaison">Affectation et comparaison</fr:title>
                            <fr:taxon>Remarque</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Attention à ne pas comfondre les opérateurs d'affectation <html:code>=</html:code> et de comparaison <html:code>==</html:code>!</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>1</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0020/</fr:uri>
                        <fr:display-uri>0020</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0020/</fr:route>
                        <fr:title text="Comparaison sur les entiers">Comparaison sur les entiers</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Pour les nombres, on utilisera également les opérateurs de comparaison habituels <html:code>&lt;</html:code> ("strictement inférieur à"), <html:code>&lt;=</html:code> ("inférieur ou égal à"), <html:code>&gt;=</html:code> ("supérieur ou égal à") et <html:code>&gt;</html:code> ("strictement supérieur à"). Dans ce cours, on réservera ces opérateurs au type <html:code>int</html:code>, et on considérera qu'ils n'ont pas de sens sur les types <html:code>char</html:code> et <html:code>bool</html:code>, même si c'est accepté en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>.</html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>7</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000J/</fr:uri>
                        <fr:display-uri>000J</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000J/</fr:route>
                        <fr:title text="Branchements conditionnels">Branchements conditionnels</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les branchements conditionnels sont une <fr:link href="/cours-polytech-peip2-algo/000N/" title="Boucles" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000N/" display-uri="000N" type="local">structure de contrôle</fr:link> permettant d'exécuter des parties de code seulement sous certaines conditions. Nous utiliserons deux sortes de conditionnelles
<html:ol><html:li>Les conditions <html:code>if-then-else</html:code></html:li>
<html:li>Les conditions <html:code>switch</html:code></html:li></html:ol></html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>8</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000K/</fr:uri>
                            <fr:display-uri>000K</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000K/</fr:route>
                            <fr:title text="Les branchements conditionnels if-then-else">Les branchements conditionnels <html:code>if-then-else</html:code></fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les branchements conditionnels <html:code>if-then-else</html:code> (en français: <html:code>si</html:code>, <html:code>alors</html:code> et <html:code>sinon</html:code>) permettent comme leur nom l'indique de tester une valeur booléenne (appelée <html:em>condition</html:em>), et de basculer sur une branche ou l'autre du code suivant que la condition est vraie ou fausse. La syntaxe pour utiliser ce genre de branchement conditionnel est la suivante:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (condition) {
  // branche 1
} else {
  // branche 2
}]]></html:code></html:pre>
Ici, <html:code>condition</html:code> est une <fr:link href="/cours-polytech-peip2-algo/000I/" title="Valeurs de base et comparaison" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000I/" display-uri="000I" type="local">valeur booléenne</fr:link>. Si cette valeur est <html:code>true</html:code>, alors le code présent dans la branche 1 est exécuté, et sinon, le code présent dans la branche 2 est exécuté. Notons que l'on peut également ommettre la seconde branche, et écrire simplement:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (condition) {
  // branche 1
}]]></html:code></html:pre>
Dans ce cas, si la valeur <html:code>condition</html:code> est <html:code>true</html:code>, alors le code présent dans la branche 1 est exécuté, et sinon, l'on continue à exécuter le programme sans passer par une seconde branche.</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>1</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0021/</fr:uri>
                                <fr:display-uri>0021</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/0021/</fr:route>
                                <fr:title text="Branchements conditionnels imbriqués">Branchements conditionnels imbriqués</fr:title>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Dans le cas où l'on veut imbriquer des branchements conditionnels, on pourra utiliser l'opérateur <html:code>else if</html:code>:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (condition1) {
  // branche 1
} else if (condition2) {
  // branche 2
} else {
  // branche 3
}]]></html:code></html:pre></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>10</fr:month>
                                  <fr:day>8</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000L/</fr:uri>
                                <fr:display-uri>000L</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/000L/</fr:route>
                                <fr:title text="Conditions booléennes">Conditions booléennes</fr:title>
                                <fr:taxon>Remarque</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>Notons que si <html:code>x</html:code> est une variable booléenne, il est fréquent de voir des élèves écrire la condition suivante:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (x == true) {
  // branche
}]]>
</html:code></html:pre>
La condition <html:code>x == true</html:code> est une valeur booléenne qui vaut <html:code>true</html:code> lorsque <html:code>x</html:code> vaut <html:code>true</html:code>, et qui vaut <html:code>false</html:code> lorsque <html:code>x</html:code> vaut <html:code>false</html:code>. Autrement dit, la valeur booléenne <html:code>x == true</html:code> est égale à la valeur booléenne <html:code>x</html:code>. Pour cette raison on privilégiera plutôt le code équivalent:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (x) {
  // branche
}]]>
</html:code></html:pre></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>8</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000M/</fr:uri>
                            <fr:display-uri>000M</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000M/</fr:route>
                            <fr:title text="Les branchements conditionnels switch-case">Les branchements conditionnels <html:code>switch-case</html:code></fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Lorsque l'on veut faire un branchement avec plus que deux branches, on pourra utiliser un branchement <html:code>switch-case</html:code>, qui évite d'enchaîner pleins de <fr:link href="/cours-polytech-peip2-algo/000K/" title="Les branchements conditionnels if-then-else" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000K/" display-uri="000K" type="local">branchements <html:code>if-then-else</html:code></fr:link>. Par exemple, si <html:code>x</html:code> est une variable de type <html:code>int</html:code>, on pourra écrire:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ switch (x) {
  case 0:
    // branche 1
    break;
  case 1:
    // branche 2
    break;
  case 2:
    // branche 3
    break;
  default:
    // branche 4
}]]></html:code></html:pre>
plutôt que:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ if (x == 0) {
  // branche 1
} else if (x == 1){
  // branche 2
} else if (x == 2){
  // branche 3
} else {
  // branche 4
}]]></html:code></html:pre>
On donne ici un exemple avec 4 branches, mais l'on peut utiliser un branchement <html:code>switch-case</html:code> avec un nombre de branches arbitraire</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>8</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000N/</fr:uri>
                        <fr:display-uri>000N</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000N/</fr:route>
                        <fr:title text="Boucles">Boucles</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les boucles sont une <fr:link href="/cours-polytech-peip2-algo/000O/" title="Structure de contrôle" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000O/" display-uri="000O" type="local">structure de contrôle</fr:link> permettant de répéter d'autres instructions un certain nombre de fois, ou jusqu'à ce qu'une condition booléenne devienne valide. Nous utiliserons deux types de boucles
<html:ol><html:li>Les boucles <html:code>for</html:code></html:li>
<html:li>Les boucles <html:code>while</html:code></html:li></html:ol></html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>8</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000P/</fr:uri>
                            <fr:display-uri>000P</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000P/</fr:route>
                            <fr:title text="Boucles for">Boucles <html:code>for</html:code></fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les boucles <html:code>for</html:code> permettent de répéter les intructions contenues dans le corps de la boucle un nombre certain nombre de fois. Pour ce faire, on définit une variable intermédiaire qui sert de compteur, et que l'on va incrémenter jusqu'à la valeur désirée. La syntaxe pour utiliser une boucle <html:code>for</html:code> est la suivante

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ for(int i = 1; i <= 8; i++){
  // corps de la boucle
}]]></html:code></html:pre>
Dans cet exemple, les intructions contenues dans le corps de la boucles sont répétées 8 fois. Décomposons rapidement les différents éléments de la boucle:
<html:ul><html:li>le code <html:code>int i = 1</html:code> déclare une variable <html:code>i</html:code> de type <html:code>int</html:code> et lui affecte la valeur <html:code>1</html:code></html:li>
<html:li>le code <html:code>i &lt;= 8</html:code> indique que l'on va passer dans la boucle tant que la condition <html:code>i &lt;= 8</html:code> est vraie</html:li>
<html:li>le code <html:code>i++</html:code> donne une instruction à effectuer à la fin de chacun des passages dans la boucle, ici on incrémente la variable <html:code>i</html:code> de <html:code>1</html:code> (le code <html:code>i++</html:code> est équivalent à <html:code>i = i+1</html:code>)</html:li></html:ul>
Notons que dans le corps de la boucle, l'on a accès à la variable <html:code>i</html:code>, et l'on voit sa valeur changer au fil des passages dans la boucle. C'est pourquoi on sera ammené parfois à commencer à compter à partir d'un nombre différent de 1, ou par exemple de 3 en 3. Par exemple, la boucle suivante fait le même nombre d'itérations que la boucle précédente, mais donne des valeurs de la variable <html:code>i</html:code> différentes dans le corps de la boucle pour chacun des passages:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[ for(int i = 5; i <= 32; i = i+3){
  // corps de la boucle
}]]></html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>8</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000Q/</fr:uri>
                            <fr:display-uri>000Q</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000Q/</fr:route>
                            <fr:title text="Boucles while">Boucles <html:code>while</html:code></fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Les boucles <html:code>while</html:code> permettent de répéter les instructions contenues dans le corps de la boucle tant qu'une condition booléenne est vraie. On l'utilise avec la syntaxe suivante:

        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[while (condition) {
  // corps de la boucle
}]]>
</html:code></html:pre>
Notons qu'il n'y a pas de garantie que la boucle s'arrête. Pour que la boucle s'arrête, il faut que le corps de la boucle modifie la condition de manière à la rendre fausse à un moment.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>11</fr:month>
                      <fr:day>4</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003N/</fr:uri>
                    <fr:display-uri>003N</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/003N/</fr:route>
                    <fr:title text="Passage par valeur et passage par référence">Passage par valeur et passage par référence</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>Il existe plusieurs manière de transmettre des arguments à une fonction, et elles ne sont pas équivalentes. Il est donc important de toujours comprendre dans quel cas on se place. En <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>, le défaut est que tous les arguments sont <fr:link href="/cours-polytech-peip2-algo/003O/" title="Passage par valeur" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003O/" display-uri="003O" type="local">passés par valeur</fr:link>, mais il est aussi possible de déclarer un <fr:link href="/cours-polytech-peip2-algo/003P/" title="Passage par référence" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003P/" display-uri="003P" type="local">passage par référence</fr:link>. Il existe également une troisième option couramment utilisée en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>, consistant à passer par <fr:link href="/cours-polytech-peip2-algo/003T/" title="Passage par valeur de pointeur et modification en place" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003T/" display-uri="003T" type="local">valeur un pointeur</fr:link>.</html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>4</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003Q/</fr:uri>
                        <fr:display-uri>003Q</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/003Q/</fr:route>
                        <fr:title text="Passage par valeur et par référence">Passage par valeur et par référence</fr:title>
                        <fr:taxon>Exemple</fr:taxon>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[void echanger (int x, int y){
  int z = x;
  x = y;
  y = z;
}

int main (){
  int a = 0;
  int b = 1;
  echanger (a,b);
  // a ce point du programme,
  // avec un appel par valeur,
  // a = 0, b = 1
  // avec un appel par référence,
  // a = 1, b = 0
  return 0;
}]]>
</html:code></html:pre></html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>4</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003O/</fr:uri>
                        <fr:display-uri>003O</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/003O/</fr:route>
                        <fr:title text="Passage par valeur">Passage par valeur</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Le passage par valeur est le comportement par défaut de <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource>. Au point d'appel d'une fonction, le programme crée une copie locale des valeurs qu'on lui a donnée, et travaille dans la fonction à l'aide de ces copies.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>4</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003R/</fr:uri>
                            <fr:display-uri>003R</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003R/</fr:route>
                            <fr:title text="Passage par valeur">Passage par valeur</fr:title>
                            <fr:taxon>Example</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[void echanger (int x, int y){
  int z = x;
  x = y;
  y = z;
}

int main (){
  int a = 0;
  int b = 1;
  echanger (a,b);
  // a ce point du programme,
  // a = 0, b = 1
  return 0;
}]]>
</html:code></html:pre></html:p>
                            <html:p><html:strong>Illustration</html:strong>: <html:mark>TODO</html:mark></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>4</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003P/</fr:uri>
                        <fr:display-uri>003P</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/003P/</fr:route>
                        <fr:title text="Passage par référence">Passage par référence</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Il est possible en <fr:resource hash="9fd1e57f01dc7c94ca6f284db6e1aabb"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/9fd1e57f01dc7c94ca6f284db6e1aabb.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\newcommand {\CC }{C\nolinebreak \hspace {-.05em}\raisebox {.4ex}{\tiny \bf  +}\nolinebreak \hspace {-.10em}\raisebox {.4ex}{\tiny \bf  +}}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[\CC ]]></fr:resource-source></fr:resource> d'indiquer que certains arguments doivent être passés par référence, en ajoutant un <html:code>&amp;</html:code> devant le nom de la variable lors de la déclaration de la fonction. Lors d'un passage par référence, la variable est transmise au corps de la fonction au moyen de son adresse mémoire. Cela évite de faire une copie des arguments</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>4</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003S/</fr:uri>
                            <fr:display-uri>003S</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003S/</fr:route>
                            <fr:title text="Passage par référence">Passage par référence</fr:title>
                            <fr:taxon>Exemple</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[void echanger (int &x, int &y){
  int z = x;
  x = y;
  y = z;
}

int main (){
  int a = 0;
  int b = 1;
  echanger (a,b);
  // a ce point du programme,
  // a = 1, b = 0
  return 0;
}]]>
</html:code></html:pre></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>11</fr:month>
                          <fr:day>4</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003T/</fr:uri>
                        <fr:display-uri>003T</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/003T/</fr:route>
                        <fr:title text="Passage par valeur de pointeur et modification en place">Passage par valeur de pointeur et modification en place</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>On peut obtenir un comportement similaire à un appel par référence, en faisant un appel par valeur sur une valeur se trouvant être un <fr:link href="/cours-polytech-peip2-algo/003U/" title="Les pointeurs" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003U/" display-uri="003U" type="local">pointeur</fr:link>. Dans ce cas, la valeur de la variable se trouve elle-même être une adresse mémoire. Bien que l'on ne va pas utiliser les pointeurs directement dans ce cours, les <fr:link href="/cours-polytech-peip2-algo/001U/" title="Tableaux" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001U/" display-uri="001U" type="local">tableaux</fr:link> en sont un exemple: la valeur d'une variable de type tableau est en fait l'adresse mémoire de la première case.</html:p>
                        <html:p>Dans ce cas de figure, une fonction peut modifier la structure de donnée qui lui est passée en argument, de manière visible à l'extérieur de la fonction.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>20</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003V/</fr:uri>
                            <fr:display-uri>003V</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003V/</fr:route>
                            <fr:title text="Modification en place des tableaux">Modification en place des tableaux</fr:title>
                            <fr:taxon>Exemple</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une conséquence de la <fr:link href="/cours-polytech-peip2-algo/003F/" title="Représentation en mémoire des tableaux" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003F/" display-uri="003F" type="local">représentation en mémoire des tableaux</fr:link> est que si une fonction effectue une modification sur un tableau via un accès à la zone mémoire contenant les données, cette modification sera visible à l'extérieure de la fonction également.</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>4</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004P/</fr:uri>
                                <fr:display-uri>004P</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/004P/</fr:route>
                                <fr:title text="Modification en place d'un tableau">Modification en place d'un tableau</fr:title>
                                <fr:taxon>Algorithme</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p><html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/themes/prism.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.css" />
        <html:link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.css" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/autoloader/prism-autoloader.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/normalize-whitespace/prism-normalize-whitespace.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/toolbar/prism-toolbar.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/show-language/prism-show-language.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/match-braces/prism-match-braces.min.js" />
        <html:script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/plugins/line-numbers/prism-line-numbers.min.js" />
        <html:script>
                Prism.plugins.NormalizeWhitespace.setDefaults({
                        "remove-trailing": true,
                        "remove-indent": true,
                        "left-trim": true,
                        "right-trim": true,
                });</html:script>
        <html:pre><html:code class="language-cpp rainbow-braces line-numbers" data-prismjs-copy="Copier" data-prismjs-copy-error="Erreur" data-prismjs-copy-success="Copié">
<![CDATA[void echangerPremiers (int x[]){
  int y = x[0];
  x[0] = x[1];
  x[1] = y;
}

int main (){
  int a[2] = {0,1};
  echangerPremiers (a);
  // a ce point du programme,
  // a = {1,0}
  return 0;
}]]>
</html:code></html:pre></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>11</fr:month>
                                  <fr:day>20</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004Q/</fr:uri>
                                <fr:display-uri>004Q</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/004Q/</fr:route>
                                <fr:title text="Modification en place d'un tableau">Modification en place d'un tableau</fr:title>
                                <fr:taxon>Illustration</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>On peut illustrer graphiquement l'algorithme précédent grâce à une série de schémas représentant la mémoire à différents moments de l'exécution du programme.
<html:ol><html:li>Dans la fonction <html:code>main</html:code>, avant appel à la fonction <html:code>echangerPremiers</html:code>, on a créé le tableau suivant en mémoire:
<fr:resource hash="a2aac317ee0c8db601bd7ee1f2c12ff0"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/a2aac317ee0c8db601bd7ee1f2c12ff0.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{\i}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {Autres\\variables};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>Au moment de l'appel à la fonction <html:code>echangerPremiers</html:code>, une copie de la variable <html:code>a</html:code> est crée, que l'on note ici <html:code>x</html:code>, c'est la variable locale à la fonction <html:code>echangerPremiers</html:code> qui représente la valeur de son argument
<fr:resource hash="6e61c42bd526a4418ec544d74ad58f90"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/6e61c42bd526a4418ec544d74ad58f90.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
    \node at (\base+\i*\cellw+0.8,\y+0.45) {\texttt{\i}};
  }

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

  \draw[thick] (\base+\n*\cellw+3*\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (x) at (\base+\n*\cellw+3*\cellw+0.8,\y+0.45) {\texttt{x}};

  \fill[gray!20] (\base+\n*\cellw+4*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (x) to[out=-90, in=-90, looseness=0.35] (\base,\y);


\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>La fonction <html:code>echangerPremiers</html:code> performe l'échange des deux premiers éléments dans la zone mémoire pointée par <html:code>x</html:code>
<fr:resource hash="d5a1615c111999eb452dd1de3071dadf"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/d5a1615c111999eb452dd1de3071dadf.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
  }
  \node at (\base+0.8,\y+0.45) {\texttt{1}};
  \node at (\base+\cellw+0.8,\y+0.45) {\texttt{0}};

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+3*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+3*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

  \draw[thick] (\base+\n*\cellw+3*\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (x) at (\base+\n*\cellw+3*\cellw+0.8,\y+0.45) {\texttt{x}};

  \fill[gray!20] (\base+\n*\cellw+4*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+4*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {};

  \draw[->, thick] (x) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li>
<html:li>Après appel à la fonction <html:code>echangerPremiers</html:code>, la variable <html:code>x</html:code> est effacée. Remarquez que la variable <html:code>a</html:code> pointe toujours vers la même zone mémoire, dans laquelle les valeurs <html:code>0</html:code> et <html:code>1</html:code> ont été échangées:
<fr:resource hash="2f7ab7f02652dffdde14562766e2c7ee"><fr:resource-content><html:img src="/cours-polytech-peip2-algo/2f7ab7f02652dffdde14562766e2c7ee.svg" /></fr:resource-content><fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}\usetikzlibrary {arrows.meta, positioning, calc}]]></fr:resource-source><fr:resource-source type="latex" part="body"><![CDATA[
\begin{tikzpicture}[font=\small]
  % Parameters for drawing
  \def\cellw{1.6}
  \def\cellh{0.9}
  \def\n{2}
  \def\base{0}          % base x-offset
  \def\y{0}             % base y-offset

  % Draw cells for a[0..4]
  \foreach \i in {0,...,1} {
    \draw[thick] (\base+\i*\cellw,\y) rectangle ++(\cellw,\cellh);
  }
  \node at (\base+0.8,\y+0.45) {\texttt{1}};
  \node at (\base+\cellw+0.8,\y+0.45) {\texttt{0}};

  % Zone mémoire à gauche
  \fill[gray!20] (\base-3*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base-3*\cellw,\y) -- (\base,\y);
  \draw[thick,-] (\base-3*\cellw,\cellh) -- (\base,\cellh);
  \node[align=center] at (\base-1.5*\cellw,\y+0.45)
    {Autres\\variables};

  % Zone mémoire à droite
  \fill[gray!20] (\base+\n*\cellw,\y) rectangle ++(\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw,\y) -- (\base+\n*\cellw+\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw,\cellh) -- (\base+\n*\cellw+\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+1.5*\cellw,\y+0.45)
    {};

  \draw[thick] (\base+\n*\cellw+\cellw,\y) rectangle ++(\cellw,\cellh);
  \node (a) at (\base+\n*\cellw+\cellw+0.8,\y+0.45) {\texttt{a}};

  \fill[gray!20] (\base+\n*\cellw+2*\cellw,\y) rectangle ++(3*\cellw,\cellh);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\y) -- (\base+\n*\cellw+5*\cellw,\y);
  \draw[thick,-] (\base+\n*\cellw+2*\cellw,\cellh) -- (\base+\n*\cellw+5*\cellw,\cellh);
  \node[align=center] at (\base+\n*\cellw+3.5*\cellw,\y+0.45)
    {Autres\\variables};

  \draw[->, thick] (a) to[out=-90, in=-90, looseness=0.35] (\base,\y);

\end{tikzpicture}
]]></fr:resource-source></fr:resource></html:li></html:ol></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>4</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003W/</fr:uri>
                            <fr:display-uri>003W</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/003W/</fr:route>
                            <fr:title text="Passage par valeur d'un pointeur et passage par référence">Passage par valeur d'un pointeur et passage par référence</fr:title>
                            <fr:taxon>Attention</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Attention à ne pas confondre passage par valeur d'un pointeur et passage par référence! Il est possible de simuler un passage par référence à l'aide d'un passage par valeur de pointeur, mais ce sont deux concepts différents.</html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
                <fr:tree show-metadata="false">
                  <fr:frontmatter>
                    <fr:authors>
                      <fr:author>
                        <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                      </fr:author>
                      <fr:contributor>
                        <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                      </fr:contributor>
                    </fr:authors>
                    <fr:date>
                      <fr:year>2025</fr:year>
                      <fr:month>10</fr:month>
                      <fr:day>27</fr:day>
                    </fr:date>
                    <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000U/</fr:uri>
                    <fr:display-uri>000U</fr:display-uri>
                    <fr:route>/cours-polytech-peip2-algo/000U/</fr:route>
                    <fr:title text="Un peu de mathématiques: Les ordres de grandeurs">Un peu de mathématiques: Les ordres de grandeurs</fr:title>
                  </fr:frontmatter>
                  <fr:mainmatter>
                    <html:p>On utilise les ordres de grandeur pour mesurer la <fr:link href="/cours-polytech-peip2-algo/0009/" title="Complexité asymptotique" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0009/" display-uri="0009" type="local">complexité asymptotique</fr:link></html:p>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000W/</fr:uri>
                        <fr:display-uri>000W</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000W/</fr:route>
                        <fr:title text="Résumé rapide">Résumé rapide</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:style>
.katex { white-space: nowrap }
th { white-space: nowrap }
td { padding-top: 10px;
     padding-bottom: 10px }
</html:style>
                        <html:p>Les notations que l'on utilise pour évaluer les ordres de grandeurs sont les suivantes: On considère une fonction <fr:tex display="inline"><![CDATA[f,g : \mathbb {N} \to  \mathbb {R}]]></fr:tex>:
<html:table>
  <html:tr>
    <html:th>
    Notation
    </html:th>
    <html:th>
    Signification formelle
    </html:th>
    <html:th>
    Signification informelle
    </html:th>
  </html:tr>
  <html:tr>
    <html:td>
    <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex>
    </html:td>
    <html:td>
    Il existe <fr:tex display="inline"><![CDATA[M > 0]]></fr:tex> et <fr:tex display="inline"><![CDATA[n_0 \in  \mathbb {N}]]></fr:tex> tel que pour tout <fr:tex display="inline"><![CDATA[n \ge  n_0]]></fr:tex>, <fr:tex display="inline"><![CDATA[|f(n)| \le  M |g(n)|]]></fr:tex>
    </html:td>
    <html:td>
    <fr:tex display="inline"><![CDATA[f]]></fr:tex> croît en gros comme <fr:tex display="inline"><![CDATA[g]]></fr:tex> ou moins vite
    </html:td>
  </html:tr>
  <html:tr>
    <html:td>
    <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex>
    </html:td>
    <html:td>
    Il existe <fr:tex display="inline"><![CDATA[m > 0]]></fr:tex> et <fr:tex display="inline"><![CDATA[n_0 \in  \mathbb {N}]]></fr:tex> tel que pour tout <fr:tex display="inline"><![CDATA[n \ge  n_0]]></fr:tex>, <fr:tex display="inline"><![CDATA[|f(n)| \ge  m |g(n)|]]></fr:tex>
    </html:td>
    <html:td>
    <fr:tex display="inline"><![CDATA[f]]></fr:tex> croît en gros comme <fr:tex display="inline"><![CDATA[g]]></fr:tex> ou plus vite
    </html:td>
  </html:tr>
  <html:tr>
    <html:td>
    <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex>
    </html:td>
    <html:td>
    <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex>
    </html:td>
    <html:td>
    <fr:tex display="inline"><![CDATA[f]]></fr:tex> croît en gros comme <fr:tex display="inline"><![CDATA[g]]></fr:tex>
    </html:td>
  </html:tr>
</html:table></html:p>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000X/</fr:uri>
                        <fr:display-uri>000X</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/000X/</fr:route>
                        <fr:title text="Grand O">Grand O</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>La notation la plus commune pour mesurer les ordres de grandeur est la notation <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex> ("grand O").</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000Y/</fr:uri>
                            <fr:display-uri>000Y</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000Y/</fr:route>
                            <fr:title text="Grand O">Grand O</fr:title>
                            <fr:taxon>Définition</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Etant donné deux fonctions <fr:tex display="inline"><![CDATA[f,g : \mathbb {N}\to  \mathbb {R}]]></fr:tex>, on écrit <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> si il existe une constante réelle <fr:tex display="inline"><![CDATA[M > 0]]></fr:tex> et un rang <fr:tex display="inline"><![CDATA[n_0 \in  \mathbb {N}]]></fr:tex> tels que pour tout <fr:tex display="inline"><![CDATA[n \ge  n_0]]></fr:tex>, l'on aie <fr:tex display="inline"><![CDATA[|f(n)| \le  M |g(n)|]]></fr:tex></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Conrètement, <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> signifie que asymptotiquement (c'est à dire lorsque <fr:tex display="inline"><![CDATA[n]]></fr:tex> devient très grand), la fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> reste toujours au dessous de la fonction <fr:tex display="inline"><![CDATA[g]]></fr:tex>, à une constante multiplicative près. L'idée d'autoriser une constante multiplicative, est que cela ne change pas la forme de la courbe. Par exemple, si la courbe de <fr:tex display="inline"><![CDATA[g]]></fr:tex> une droite, alors celle de <fr:tex display="inline"><![CDATA[Mg]]></fr:tex> l'est aussi. Si la courbe de <fr:tex display="inline"><![CDATA[g]]></fr:tex> est une parabole, alors la courbe de <fr:tex display="inline"><![CDATA[Mg]]></fr:tex> l'est aussi, etc.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000Z/</fr:uri>
                            <fr:display-uri>000Z</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/000Z/</fr:route>
                            <fr:title text="Grand O">Grand O</fr:title>
                            <fr:taxon>Propriétés</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>La notation <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \mathcal {O}(h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(kg(n))]]></fr:tex></html:li></html:ul></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                          <fr:contributor>
                            <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                          </fr:contributor>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0010/</fr:uri>
                        <fr:display-uri>0010</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0010/</fr:route>
                        <fr:title text="Grand Omega">Grand Omega</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>La notation <fr:tex display="inline"><![CDATA[\Omega ]]></fr:tex> (grand omega) est en quelque sorte l'inverse de la notation <fr:link href="/cours-polytech-peip2-algo/000X/" title="Grand O" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000X/" display-uri="000X" type="local">grand O</fr:link></html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0011/</fr:uri>
                            <fr:display-uri>0011</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0011/</fr:route>
                            <fr:title text="Grand Omega">Grand Omega</fr:title>
                            <fr:taxon>Définition</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Etant donné deux fonctions <fr:tex display="inline"><![CDATA[f,g : \mathbb {N}\to  \mathbb {R}]]></fr:tex>, on écrit <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> si il existe une constante réelle <fr:tex display="inline"><![CDATA[m > 0]]></fr:tex> et un rang <fr:tex display="inline"><![CDATA[n_0 \in  \mathbb {N}]]></fr:tex> tels que pour tout <fr:tex display="inline"><![CDATA[n \ge  n_0]]></fr:tex>, l'on aie <fr:tex display="inline"><![CDATA[|f(n)| \ge  m |g(n)|]]></fr:tex></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Conrètement, <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> signifie que asymptotiquement (c'est à dire lorsque <fr:tex display="inline"><![CDATA[n]]></fr:tex> devient très grand), la fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> reste toujours au dessus de la fonction <fr:tex display="inline"><![CDATA[g]]></fr:tex>, à une constante multiplicative près.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0012/</fr:uri>
                            <fr:display-uri>0012</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0012/</fr:route>
                            <fr:title text="Grand Omega">Grand Omega</fr:title>
                            <fr:taxon>Propriétés</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>La notation <fr:tex display="inline"><![CDATA[\Omega ]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Lien avec <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex>:</html:strong> On a <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> si et seulement si <fr:tex display="inline"><![CDATA[g(n) = \mathcal {O}(f(n))]]></fr:tex></html:li>
<html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \Omega (f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \Omega (h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Omega (h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Omega (kg(n))]]></fr:tex></html:li></html:ul></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                          <fr:contributor>
                            <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                          </fr:contributor>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0013/</fr:uri>
                        <fr:display-uri>0013</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0013/</fr:route>
                        <fr:title text="Grand Theta">Grand Theta</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>La notation <fr:tex display="inline"><![CDATA[\Theta ]]></fr:tex> (grand theta) est une synthèse des notations <fr:link href="/cours-polytech-peip2-algo/000X/" title="Grand O" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000X/" display-uri="000X" type="local">grand O</fr:link> et <fr:link href="/cours-polytech-peip2-algo/0010/" title="Grand Omega" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0010/" display-uri="0010" type="local">grand omega</fr:link></html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0014/</fr:uri>
                            <fr:display-uri>0014</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0014/</fr:route>
                            <fr:title text="Grand Theta">Grand Theta</fr:title>
                            <fr:taxon>Définition</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Etant donné deux fonctions <fr:tex display="inline"><![CDATA[f,g : \mathbb {N}\to  \mathbb {R}]]></fr:tex>, on écrit <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> si il existe deux constantes réelles <fr:tex display="inline"><![CDATA[M > 0]]></fr:tex>, et <fr:tex display="inline"><![CDATA[m > 0]]></fr:tex> et un rang <fr:tex display="inline"><![CDATA[n_0 \in  \mathbb {N}]]></fr:tex> tels que pour tout <fr:tex display="inline"><![CDATA[n \ge  n_0]]></fr:tex>, l'on aie <fr:tex display="inline"><![CDATA[m|g(n)| \le  |f(n)| \le  M |g(n)|]]></fr:tex></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <html:p>Conrètement, <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> signifie que asymptotiquement (c'est à dire lorsque <fr:tex display="inline"><![CDATA[n]]></fr:tex> devient très grand), la fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> est comprise entre deux copies de <fr:tex display="inline"><![CDATA[g]]></fr:tex> multipliées par des constantes différentes. Cela signifie donc que la courbe de <fr:tex display="inline"><![CDATA[f]]></fr:tex> est de même "nature" que celle de <fr:tex display="inline"><![CDATA[g]]></fr:tex>. Par exemple, si la courbe de <fr:tex display="inline"><![CDATA[g]]></fr:tex> est une droite, alors celle de <fr:tex display="inline"><![CDATA[f]]></fr:tex> l'est également, si la courbe de <fr:tex display="inline"><![CDATA[g]]></fr:tex> est une parabole, alors celle de <fr:tex display="inline"><![CDATA[f]]></fr:tex> l'est également, etc.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0015/</fr:uri>
                            <fr:display-uri>0015</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0015/</fr:route>
                            <fr:title text="Grand Theta">Grand Theta</fr:title>
                            <fr:taxon>Propriétés</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>La notation <fr:tex display="inline"><![CDATA[\Theta ]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Lien avec <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex> et <fr:tex display="inline"><![CDATA[\Omega ]]></fr:tex>:</html:strong> On a <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> si et seulement si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex></html:li>
<html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \Theta (f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \Theta (h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Theta (h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Theta (kg(n))]]></fr:tex></html:li></html:ul></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                          <fr:contributor>
                            <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                          </fr:contributor>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001B/</fr:uri>
                        <fr:display-uri>001B</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/001B/</fr:route>
                        <fr:title text="Exercices sur les ordres de grandeur">Exercices sur les ordres de grandeur</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Les exercices suivants permettront de se familiariser avec les notations que l'on utilise pour les ordres de grandeurs.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001C/</fr:uri>
                            <fr:display-uri>001C</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001C/</fr:route>
                            <fr:title text="Propriétés de la notation grand O">Propriétés de la notation grand O</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Prouver les propriétés de la notation grand O rappelées ci-dessous</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>10</fr:month>
                                  <fr:day>27</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/000Z/</fr:uri>
                                <fr:display-uri>000Z</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/000Z/</fr:route>
                                <fr:title text="Grand O">Grand O</fr:title>
                                <fr:taxon>Propriétés</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>La notation <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \mathcal {O}(h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(kg(n))]]></fr:tex></html:li></html:ul></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001D/</fr:uri>
                            <fr:display-uri>001D</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001D/</fr:route>
                            <fr:title text="Propriétés de la notation grand Omega">Propriétés de la notation grand Omega</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Prouver les propriétés de la notation grand Omega rappelées ci-dessous</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>10</fr:month>
                                  <fr:day>27</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0012/</fr:uri>
                                <fr:display-uri>0012</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/0012/</fr:route>
                                <fr:title text="Grand Omega">Grand Omega</fr:title>
                                <fr:taxon>Propriétés</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>La notation <fr:tex display="inline"><![CDATA[\Omega ]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Lien avec <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex>:</html:strong> On a <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> si et seulement si <fr:tex display="inline"><![CDATA[g(n) = \mathcal {O}(f(n))]]></fr:tex></html:li>
<html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \Omega (f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \Omega (h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Omega (h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Omega (kg(n))]]></fr:tex></html:li></html:ul></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                              <fr:contributor>
                                <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                              </fr:contributor>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001E/</fr:uri>
                            <fr:display-uri>001E</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001E/</fr:route>
                            <fr:title text="Propriétés de la notation grand Theta">Propriétés de la notation grand Theta</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Prouver les propriétés de la notation grand Theta rappelées ci-dessous</html:p>
                            <fr:tree show-metadata="false">
                              <fr:frontmatter>
                                <fr:authors>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                                  </fr:author>
                                  <fr:author>
                                    <fr:link href="/cours-polytech-peip2-algo/violettechateau/" title="Violette Chateau" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/violettechateau/" display-uri="violettechateau" type="local">Violette Chateau</fr:link>
                                  </fr:author>
                                </fr:authors>
                                <fr:date>
                                  <fr:year>2025</fr:year>
                                  <fr:month>10</fr:month>
                                  <fr:day>27</fr:day>
                                </fr:date>
                                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0015/</fr:uri>
                                <fr:display-uri>0015</fr:display-uri>
                                <fr:route>/cours-polytech-peip2-algo/0015/</fr:route>
                                <fr:title text="Grand Theta">Grand Theta</fr:title>
                                <fr:taxon>Propriétés</fr:taxon>
                              </fr:frontmatter>
                              <fr:mainmatter>
                                <html:p>La notation <fr:tex display="inline"><![CDATA[\Theta ]]></fr:tex> satisfait les propriétés suivantes
<html:ul><html:li><html:strong>Lien avec <fr:tex display="inline"><![CDATA[\mathcal {O}]]></fr:tex> et <fr:tex display="inline"><![CDATA[\Omega ]]></fr:tex>:</html:strong> On a <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> si et seulement si <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[f(n) = \Omega (g(n))]]></fr:tex></html:li>
<html:li><html:strong>Réflexivité:</html:strong> Toute fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> satisfait <fr:tex display="inline"><![CDATA[f(n) = \Theta (f(n))]]></fr:tex></html:li>
<html:li><html:strong>Transitivité:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[g(n) = \Theta (h(n))]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Theta (h(n))]]></fr:tex></html:li>
<html:li><html:strong>Multiplication par une constante:</html:strong> Si <fr:tex display="inline"><![CDATA[f(n) = \Theta (g(n))]]></fr:tex> et <fr:tex display="inline"><![CDATA[k > 0]]></fr:tex> alors <fr:tex display="inline"><![CDATA[f(n) = \Theta (kg(n))]]></fr:tex></html:li></html:ul></html:p>
                              </fr:mainmatter>
                            </fr:tree>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001F/</fr:uri>
                            <fr:display-uri>001F</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001F/</fr:route>
                            <fr:title text="Seul le plus gros terme compte">Seul le plus gros terme compte</fr:title>
                            <fr:taxon>Exercice</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>On considère une fonction <fr:tex display="inline"><![CDATA[f : \mathbb {N}\to  \mathbb {R}]]></fr:tex>.
<html:ol><html:li>Supposons que <fr:tex display="inline"><![CDATA[f = \mathcal {O}(3n^2 + 650 n + 3000 \log  (n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \mathcal {O}(n^2)]]></fr:tex></html:li>
<html:li>Supposons que <fr:tex display="inline"><![CDATA[f = \Omega (3n^2 + 650 n + 3000 \log  (n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \Omega (n^2)]]></fr:tex></html:li>
<html:li>Supposons que <fr:tex display="inline"><![CDATA[f = \Theta (3n^2 + 650 n + 3000 \log  (n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \Theta (n^2)]]></fr:tex></html:li></html:ol>
<html:strong>indication:</html:strong> On pourra utiliser le fait que <fr:tex display="inline"><![CDATA[\lim \limits _{n\to  0}\frac {\log (n)}{n} = 0]]></fr:tex></html:p>
                            <html:p>
On cherche maintenant à généraliser ce résultat:
<html:ol><html:li>Supposons que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O} (g(n) + h(n))]]></fr:tex> avec <fr:tex display="inline"><![CDATA[h(n) = \mathcal {O}(g(n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \mathcal {O}(g(n))]]></fr:tex></html:li>
<html:li>Supposons que <fr:tex display="inline"><![CDATA[f(n) = \Omega  (g(n) + h(n))]]></fr:tex> avec <fr:tex display="inline"><![CDATA[h(n) = \mathcal {O}(g(n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \Omega (g(n))]]></fr:tex></html:li>
<html:li>Supposons que <fr:tex display="inline"><![CDATA[f(n) = \Theta  (g(n) + h(n))]]></fr:tex> avec <fr:tex display="inline"><![CDATA[h(n) = \mathcal {O}(g(n))]]></fr:tex>. Montrer que <fr:tex display="inline"><![CDATA[f = \Theta (g(n))]]></fr:tex></html:li></html:ol></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                    <fr:tree show-metadata="false">
                      <fr:frontmatter>
                        <fr:authors>
                          <fr:author>
                            <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                          </fr:author>
                        </fr:authors>
                        <fr:date>
                          <fr:year>2025</fr:year>
                          <fr:month>10</fr:month>
                          <fr:day>27</fr:day>
                        </fr:date>
                        <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0016/</fr:uri>
                        <fr:display-uri>0016</fr:display-uri>
                        <fr:route>/cours-polytech-peip2-algo/0016/</fr:route>
                        <fr:title text="Les ordres de grandeurs usuels">Les ordres de grandeurs usuels</fr:title>
                      </fr:frontmatter>
                      <fr:mainmatter>
                        <html:p>Certains ordres de grandeurs ont des noms qu'il est habituels d'utiliser. On présente ici les principaux, avec leur noms, leur définition et la courbe qui leur correspond.</html:p>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001J/</fr:uri>
                            <fr:display-uri>001J</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001J/</fr:route>
                            <fr:title text="Constant">Constant</fr:title>
                            <fr:taxon>Ordre de grandeur</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> telle que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(n)]]></fr:tex> est une dite (asymptotiquement) constante. Sa courbe est contenue entre deux droites horizontales</html:p>
                            <html:p>
                              <fr:resource hash="c9960eccd746d8718c3a35f1c7fc74fe">
                                <fr:resource-content>
                                  <html:img src="/cours-polytech-peip2-algo/c9960eccd746d8718c3a35f1c7fc74fe.svg" />
                                </fr:resource-content>
                                <fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}]]></fr:resource-source>
                                <fr:resource-source type="latex" part="body"><![CDATA[
\begin {tikzpicture}[scale = 0.5]
\fill [gray!20] (-5,2) -- (5,2) -- (5,3) -- (-5,3);
\draw [help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw [->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw [->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\draw [-,thick] (-5,2) -- (5,2);
\draw [-,thick] (-5,3) -- (5,3);

\end {tikzpicture}
]]></fr:resource-source>
                              </fr:resource>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0017/</fr:uri>
                            <fr:display-uri>0017</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0017/</fr:route>
                            <fr:title text="Linéaire">Linéaire</fr:title>
                            <fr:taxon>Ordre de grandeur</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> telle que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(n)]]></fr:tex> est appelée une fonction linéaire. Sa courbe est une droite</html:p>
                            <html:p>
                              <fr:resource hash="2db1b6775c4e732cd5f1bd2c97d7b5ca">
                                <fr:resource-content>
                                  <html:img src="/cours-polytech-peip2-algo/2db1b6775c4e732cd5f1bd2c97d7b5ca.svg" />
                                </fr:resource-content>
                                <fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}]]></fr:resource-source>
                                <fr:resource-source type="latex" part="body"><![CDATA[
\begin {tikzpicture}[scale = 0.5]
\draw [help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw [->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw [->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\draw [-,thick] (-5,-3) -- (2,5);
\end {tikzpicture}
]]></fr:resource-source>
                              </fr:resource>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0018/</fr:uri>
                            <fr:display-uri>0018</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0018/</fr:route>
                            <fr:title text="Quadratique">Quadratique</fr:title>
                            <fr:taxon>Ordre de grandeur</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> telle que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(n^2)]]></fr:tex> est appelée une fonction quadratique. Sa courbe est une parabole</html:p>
                            <html:p>
                              <fr:resource hash="7ce50aa3b596747a159175ab676ac62f">
                                <fr:resource-content>
                                  <html:img src="/cours-polytech-peip2-algo/7ce50aa3b596747a159175ab676ac62f.svg" />
                                </fr:resource-content>
                                <fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}]]></fr:resource-source>
                                <fr:resource-source type="latex" part="body"><![CDATA[
\begin {tikzpicture}[scale = 0.5]
\draw [help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw [->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw [->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\draw  [smooth, samples=100, domain=-5:3, thick] plot(\x , {0.3 * (\x  + 2)^2 - 1});
\end {tikzpicture}
]]></fr:resource-source>
                              </fr:resource>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0019/</fr:uri>
                            <fr:display-uri>0019</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/0019/</fr:route>
                            <fr:title text="Logarithmique">Logarithmique</fr:title>
                            <fr:taxon>Ordre de grandeur</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> telle que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(\log (n))]]></fr:tex> est appelée une fonction logarithmique. Sa courbe ressemble à celle d'un logarithme.</html:p>
                            <html:p>
                              <fr:resource hash="fea428e0ea9828166f3e103eadc2260f">
                                <fr:resource-content>
                                  <html:img src="/cours-polytech-peip2-algo/fea428e0ea9828166f3e103eadc2260f.svg" />
                                </fr:resource-content>
                                <fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}]]></fr:resource-source>
                                <fr:resource-source type="latex" part="body"><![CDATA[
\begin {tikzpicture}[scale = 0.5]
\draw [help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw [->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw [->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\draw  [smooth, samples=100, domain=-1.9:5, thick] plot(\x , {ln (\x  + 2) + 1});
\end {tikzpicture}
]]></fr:resource-source>
                              </fr:resource>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>10</fr:month>
                              <fr:day>27</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001A/</fr:uri>
                            <fr:display-uri>001A</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/001A/</fr:route>
                            <fr:title text="Exponentielle">Exponentielle</fr:title>
                            <fr:taxon>Ordre de grandeur</fr:taxon>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Une fonction <fr:tex display="inline"><![CDATA[f]]></fr:tex> telle que <fr:tex display="inline"><![CDATA[f(n) = \mathcal {O}(\exp (n))]]></fr:tex> est appelée une fonction exponentielle. Sa courbe ressemble à celle d'une fonction exponentielle.</html:p>
                            <html:p>
                              <fr:resource hash="ab6e2905a1ec0391d37c2eae92910bc0">
                                <fr:resource-content>
                                  <html:img src="/cours-polytech-peip2-algo/ab6e2905a1ec0391d37c2eae92910bc0.svg" />
                                </fr:resource-content>
                                <fr:resource-source type="latex" part="preamble"><![CDATA[\usepackage {tikz}]]></fr:resource-source>
                                <fr:resource-source type="latex" part="body"><![CDATA[
\begin {tikzpicture}[scale = 0.5]
\draw [help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw [->,ultra thick] (-5,0)--(5,0) node[right]{$x$};
\draw [->,ultra thick] (0,-5)--(0,5) node[above]{$y$};
\draw  [smooth, samples=100, domain=-5:1.7, thick] plot(\x , {exp (\x )});
\end {tikzpicture}
]]></fr:resource-source>
                              </fr:resource>
                            </html:p>
                          </fr:mainmatter>
                        </fr:tree>
                        <fr:tree show-metadata="false">
                          <fr:frontmatter>
                            <fr:authors>
                              <fr:author>
                                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                              </fr:author>
                            </fr:authors>
                            <fr:date>
                              <fr:year>2025</fr:year>
                              <fr:month>11</fr:month>
                              <fr:day>13</fr:day>
                            </fr:date>
                            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/004G/</fr:uri>
                            <fr:display-uri>004G</fr:display-uri>
                            <fr:route>/cours-polytech-peip2-algo/004G/</fr:route>
                            <fr:title text="Vitesse de croîssance des fonctions usuelles">Vitesse de croîssance des fonctions usuelles</fr:title>
                          </fr:frontmatter>
                          <fr:mainmatter>
                            <html:p>Il est important d'avoir une bonne idée de la vitesse de croissance des différents ordre de grandeurs. La liste suivante les donne donc, en partant du plus lent au plus rapide:
<html:ul><html:li><fr:link href="/cours-polytech-peip2-algo/001J/" title="Constant" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001J/" display-uri="001J" type="local">Constant</fr:link>: Les fonctions constantes ne croîssent pas du tout, difficile de faire plus lent.</html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/0019/" title="Logarithmique" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0019/" display-uri="0019" type="local">Logarithmique</fr:link>: La fonction logarithmique croît très lentement, sans pour autant tendre vers une valeur finie.</html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/0017/" title="Linéaire" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0017/" display-uri="0017" type="local">Linéaire</fr:link>: Les fonctions linéaires peuvent commencer à poser problème.</html:li>
<html:li><fr:tex display="inline"><![CDATA[n\log (n)]]></fr:tex>: C'est une complexité que l'on rencontre souvent, plus élevée que les fonctions linéaires.</html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/0018/" title="Quadratique" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/0018/" display-uri="0018" type="local">Quadratique</fr:link>: En général à partir de là, le programme pose problème.</html:li>
<html:li><fr:tex display="inline"><![CDATA[n^3]]></fr:tex>: Plus on augmente l'exposant, plus ca croît vite.</html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/001A/" title="Exponentielle" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001A/" display-uri="001A" type="local">Exponentielle</fr:link> : Plus rapide que toutes les fonctions puissance.</html:li></html:ul></html:p>
                          </fr:mainmatter>
                        </fr:tree>
                      </fr:mainmatter>
                    </fr:tree>
                  </fr:mainmatter>
                </fr:tree>
              </fr:mainmatter>
            </fr:tree>
          </fr:mainmatter>
        </fr:tree>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors>
              <fr:author>
                <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
              </fr:author>
            </fr:authors>
            <fr:date>
              <fr:year>2025</fr:year>
              <fr:month>10</fr:month>
              <fr:day>27</fr:day>
            </fr:date>
            <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/001V/</fr:uri>
            <fr:display-uri>001V</fr:display-uri>
            <fr:route>/cours-polytech-peip2-algo/001V/</fr:route>
            <fr:title text="Recueil des TD/TP">Recueil des TD/TP</fr:title>
          </fr:frontmatter>
          <fr:mainmatter>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>11</fr:month>
                  <fr:day>5</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003Y/</fr:uri>
                <fr:display-uri>003Y</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/003Y/</fr:route>
                <fr:title text="Liste des TD">Liste des TD</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>
                  <html:ul><html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TD1/" title="TD 1" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TD1/" display-uri="Seance-TD1" type="local">TD 1</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TD2/" title="TD 2" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TD2/" display-uri="Seance-TD2" type="local">TD 2</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TD3/" title="TD 3" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TD3/" display-uri="Seance-TD3" type="local">TD 3</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TD4/" title="TD 4" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TD4/" display-uri="Seance-TD4" type="local">TD 4</fr:link></html:li></html:ul>
                </html:p>
                <html:p><html:strong>Corrections</html:strong>: Merci à <html:strong>Olivier Delfanne</html:strong> pour la prise de notes des corrections des TD. C'est un travail personnel qu'il partage avec l'ensemble de la classe, et ne constituent en aucun cas des corrections officielles.
<html:li><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmibqttedcc66vbeyx6r57qye27csl72f3piycl2w4fc6isyxnvgpmy.zip"><html:strong>Corrections du TD1</html:strong></html:a></html:span></html:li>
<html:li><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmicqevkaa2lwvcb75ckdxpmsf2o2iducoroircqlpmfga6cqt7cpmi.zip"><html:strong>Corrections du TD2</html:strong></html:a></html:span></html:li>
<html:li><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmibrtp2e5sqkfxxret4ymzufypyjdjifakarjyy6w76o34adfvtleq.zip"><html:strong>Corrections du TD3</html:strong></html:a></html:span></html:li>
<html:li><html:span class="link local"><html:a href="/cours-polytech-peip2-algo/bafkrmice22wqgfv26f73ty2qp4rbffujq6kcwvzb6dja223brms3xxzoki.zip"><html:strong>Corrections du TD4</html:strong></html:a></html:span></html:li></html:p>
              </fr:mainmatter>
            </fr:tree>
            <fr:tree show-metadata="false">
              <fr:frontmatter>
                <fr:authors>
                  <fr:author>
                    <fr:link href="/cours-polytech-peip2-algo/thibautbenjamin/" title="Thibaut Benjamin" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/thibautbenjamin/" display-uri="thibautbenjamin" type="local">Thibaut Benjamin</fr:link>
                  </fr:author>
                </fr:authors>
                <fr:date>
                  <fr:year>2025</fr:year>
                  <fr:month>11</fr:month>
                  <fr:day>5</fr:day>
                </fr:date>
                <fr:uri>http://thibautbenjamin.github.io/cours-polytech-peip2-algo/003Z/</fr:uri>
                <fr:display-uri>003Z</fr:display-uri>
                <fr:route>/cours-polytech-peip2-algo/003Z/</fr:route>
                <fr:title text="Liste des TP">Liste des TP</fr:title>
              </fr:frontmatter>
              <fr:mainmatter>
                <html:p>
                  <html:ul><html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TP1/" title="TP 1 : Tri par sélection et tri par insertion" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TP1/" display-uri="Seance-TP1" type="local">TP 1</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TP2/" title="TP2 : Algorithmes de recherche de sous-chaîne" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TP2/" display-uri="Seance-TP2" type="local">TP 2</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TP3/" title="TP 3: Les algorithmes de tris récursifs" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TP3/" display-uri="Seance-TP3" type="local">TP 3</fr:link></html:li>
<html:li><fr:link href="/cours-polytech-peip2-algo/Seance-TP4/" title="TP 4: La course de Fibonacci" uri="http://thibautbenjamin.github.io/cours-polytech-peip2-algo/Seance-TP4/" display-uri="Seance-TP4" type="local">TP 4</fr:link></html:li></html:ul>
                </html:p>
              </fr:mainmatter>
            </fr:tree>
          </fr:mainmatter>
        </fr:tree>
      </fr:mainmatter>
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Contributions">Contributions</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
  </fr:backmatter>
</fr:tree>
