{"id":580,"date":"2022-05-02T17:07:40","date_gmt":"2022-05-02T15:07:40","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/?p=580"},"modified":"2022-05-03T11:06:25","modified_gmt":"2022-05-03T09:06:25","slug":"dichotomie","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/2022\/05\/02\/dichotomie\/","title":{"rendered":"Dichotomie"},"content":{"rendered":"\n<p><a href=\"https:\/\/colab.research.google.com\/drive\/1ByJPMTl8Hk0yViq_3ZgdeVXcAgN3PbBQ?usp=sharing\">https:\/\/colab.research.google.com\/drive\/1ByJPMTl8Hk0yViq_3ZgdeVXcAgN3PbBQ?usp=sharing<\/a><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-background\" style=\"background-color:#b5e3ff\"><strong>Recherche S\u00e9quentielle :<\/strong><\/p>\n\n\n\n<p><strong>Ecrivons une fonction qui recherche une valeur val dans un tableau tab. La fonction doit renvoyer True si la valeur est pr\u00e9sente False si elle est absente.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def rechercher(tab,val):\n  for x in tab:\n    if val==x:\n      return True\n  return False<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tab=[i for i in range(100000001)]<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"261\" height=\"71\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-content\/uploads\/sites\/8\/2022\/05\/image.png\" alt=\"\" class=\"wp-image-583\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-background\" style=\"background-color:#c0e7ff\"><strong>Recherche dichotomique<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def dichotomie(tab,val):\n    debut = 0\n    fin = len(tab) - 1\n    while debut &lt;= fin:\n        m = (debut + fin) \/\/ 2\n        if val== tab[m]:\n            return True\n        if val &gt; tab[m]:\n            debut = m + 1\n        else:\n            fin = m - 1\n    return False<\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-background\" style=\"background-color:#d2eeff\"><strong>Comparaison<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\n\ntab=[i for i in range(100000000)]\n\ndebut1=time.time()\nrechercher(tab,10000000)\nduree1=time.time()-debut1\nprint(duree1)\n\ndebut2=time.time()\ndichotomie(tab,10000000)\nduree2=time.time()-debut2\nprint(duree2)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"233\" height=\"52\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-content\/uploads\/sites\/8\/2022\/05\/image-1.png\" alt=\"\" class=\"wp-image-584\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/colab.research.google.com\/drive\/1ByJPMTl8Hk0yViq_3ZgdeVXcAgN3PbBQ?usp=sharing Recherche S\u00e9quentielle : Ecrivons une fonction qui recherche une valeur val dans un tableau tab. La fonction doit renvoyer True si la valeur est pr\u00e9sente False si elle est absente. Recherche dichotomique Comparaison<\/p>\n","protected":false},"author":7,"featured_media":591,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/posts\/580"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/comments?post=580"}],"version-history":[{"count":4,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":593,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/posts\/580\/revisions\/593"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/media\/591"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/media?parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/categories?post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/anna\/wp-json\/wp\/v2\/tags?post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}