Skip to content

Commit

Permalink
deploy: 4e8de44
Browse files Browse the repository at this point in the history
  • Loading branch information
javlintor committed Feb 11, 2024
1 parent 36f32fc commit d86dbbe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
41 changes: 36 additions & 5 deletions _sources/notebooks/ejercicio2023/algoritmos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@
" def asigna_lista_ordenada_inversa(self, n: int):\n",
" self.lista = list(range(n, 0, -1))\n",
"\n",
" def asigna_lista_ordenada_inversa(self, n: int):\n",
" def asigna_lista_orden_aleatorio(self, n: int):\n",
" self.lista = list(random.randrange(n) for _ in range(n))"
],
"metadata": {
"id": "tK5aHXp5_Uyq"
},
"execution_count": 20,
"execution_count": 36,
"outputs": []
},
{
Expand All @@ -177,17 +177,48 @@
{
"cell_type": "code",
"source": [
"from typing import Literal\n",
"from typing import Literal, Callable\n",
"import time\n",
"import pandas as pd\n",
"\n",
"class AlgoritmoOrdenacion3(AlgoritmoOrdenacion2):\n",
"\n",
" def calcula_complejidad_temporal(self, n_max: int, intentos: int, tipo: Literal[\"burbuja\", \"mezcla\"]):\n",
" pass"
" diccionario_algoritmo_ordenacion = {\n",
" 'burbuja': self.ordena_burbuja,\n",
" 'mezcla': self.ordena_mezcla\n",
" }\n",
" algoritmo_ordenacion = diccionario_algoritmo_ordenacion[tipo]\n",
" registro_tiempos = {}\n",
" for i in range(n_max):\n",
" self.asigna_lista_ordenada(2**i)\n",
" tiempo_lista_ordenada = self.calcula_tiempo_algoritmo(algoritmo_ordenacion, intentos)\n",
" self.asigna_lista_ordenada_inversa(2**i)\n",
" tiempo_lista_ordenada_inversa = self.calcula_tiempo_algoritmo(algoritmo_ordenacion, intentos)\n",
" self.asigna_lista_orden_aleatorio(2**i)\n",
" tiempo_lista_orden_aleatorio = self.calcula_tiempo_algoritmo(algoritmo_ordenacion, intentos)\n",
" registro_tiempos[2**i] = {\n",
" \"tiempo_lista_ordenada\": tiempo_lista_ordenada,\n",
" \"tiempo_lista_ordenada_inversa\": tiempo_lista_ordenada_inversa,\n",
" \"tiempo_lista_orden_aleatorio\": tiempo_lista_orden_aleatorio,\n",
" }\n",
"\n",
" return pd.DataFrame.from_dict(registro_tiempos, orient='index')\n",
"\n",
" def calcula_tiempo_algoritmo(self, algoritmo: Callable, intentos: int):\n",
" tiempos = []\n",
" for _ in range(intentos):\n",
" inicio = time.time()\n",
" algoritmo()\n",
" final = time.time()\n",
" tiempos.append(final - inicio)\n",
"\n",
" return sum(tiempos) / intentos"
],
"metadata": {
"id": "sSf7qDB1Aj6B"
},
"execution_count": null,
"execution_count": 49,
"outputs": []
},
{
Expand Down
37 changes: 34 additions & 3 deletions notebooks/ejercicio2023/algoritmos.html
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ <h1>Ejercicio: Algoritmos de ordenación<a class="headerlink" href="#ejercicio-a
<span class="k">def</span> <span class="nf">asigna_lista_ordenada_inversa</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lista</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span>

<span class="k">def</span> <span class="nf">asigna_lista_ordenada_inversa</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">asigna_lista_orden_aleatorio</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lista</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randrange</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
</pre></div>
</div>
Expand All @@ -558,12 +558,43 @@ <h1>Ejercicio: Algoritmos de ordenación<a class="headerlink" href="#ejercicio-a
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span><span class="p">,</span> <span class="n">Callable</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>

<span class="k">class</span> <span class="nc">AlgoritmoOrdenacion3</span><span class="p">(</span><span class="n">AlgoritmoOrdenacion2</span><span class="p">):</span>

<span class="k">def</span> <span class="nf">calcula_complejidad_temporal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n_max</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">intentos</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">tipo</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;burbuja&quot;</span><span class="p">,</span> <span class="s2">&quot;mezcla&quot;</span><span class="p">]):</span>
<span class="k">pass</span>
<span class="n">diccionario_algoritmo_ordenacion</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;burbuja&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ordena_burbuja</span><span class="p">,</span>
<span class="s1">&#39;mezcla&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ordena_mezcla</span>
<span class="p">}</span>
<span class="n">algoritmo_ordenacion</span> <span class="o">=</span> <span class="n">diccionario_algoritmo_ordenacion</span><span class="p">[</span><span class="n">tipo</span><span class="p">]</span>
<span class="n">registro_tiempos</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_max</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">asigna_lista_ordenada</span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">i</span><span class="p">)</span>
<span class="n">tiempo_lista_ordenada</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">calcula_tiempo_algoritmo</span><span class="p">(</span><span class="n">algoritmo_ordenacion</span><span class="p">,</span> <span class="n">intentos</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">asigna_lista_ordenada_inversa</span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">i</span><span class="p">)</span>
<span class="n">tiempo_lista_ordenada_inversa</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">calcula_tiempo_algoritmo</span><span class="p">(</span><span class="n">algoritmo_ordenacion</span><span class="p">,</span> <span class="n">intentos</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">asigna_lista_orden_aleatorio</span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">i</span><span class="p">)</span>
<span class="n">tiempo_lista_orden_aleatorio</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">calcula_tiempo_algoritmo</span><span class="p">(</span><span class="n">algoritmo_ordenacion</span><span class="p">,</span> <span class="n">intentos</span><span class="p">)</span>
<span class="n">registro_tiempos</span><span class="p">[</span><span class="mi">2</span><span class="o">**</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;tiempo_lista_ordenada&quot;</span><span class="p">:</span> <span class="n">tiempo_lista_ordenada</span><span class="p">,</span>
<span class="s2">&quot;tiempo_lista_ordenada_inversa&quot;</span><span class="p">:</span> <span class="n">tiempo_lista_ordenada_inversa</span><span class="p">,</span>
<span class="s2">&quot;tiempo_lista_orden_aleatorio&quot;</span><span class="p">:</span> <span class="n">tiempo_lista_orden_aleatorio</span><span class="p">,</span>
<span class="p">}</span>

<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">registro_tiempos</span><span class="p">,</span> <span class="n">orient</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">calcula_tiempo_algoritmo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">algoritmo</span><span class="p">:</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">intentos</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">tiempos</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">intentos</span><span class="p">):</span>
<span class="n">inicio</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">algoritmo</span><span class="p">()</span>
<span class="n">final</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">tiempos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">final</span> <span class="o">-</span> <span class="n">inicio</span><span class="p">)</span>

<span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="n">tiempos</span><span class="p">)</span> <span class="o">/</span> <span class="n">intentos</span>
</pre></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit d86dbbe

Please sign in to comment.