<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: owivans</title>
    <description>The latest articles on DEV Community by owivans (@owivans).</description>
    <link>https://dev.to/owivans</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F668056%2Ff475ed68-55f1-48de-843b-0b42df23213f.jpeg</url>
      <title>DEV Community: owivans</title>
      <link>https://dev.to/owivans</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/owivans"/>
    <language>en</language>
    <item>
      <title>Introducción a Big O Notation</title>
      <dc:creator>owivans</dc:creator>
      <pubDate>Fri, 12 Jan 2024 18:45:44 +0000</pubDate>
      <link>https://dev.to/owivans/introduccion-a-big-o-notation-3lp</link>
      <guid>https://dev.to/owivans/introduccion-a-big-o-notation-3lp</guid>
      <description>&lt;h2&gt;
  
  
  ¿Sabes cuál es la complejidad del algoritmo de búsqueda binaria?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmcnmvs3blv14qdygoagr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmcnmvs3blv14qdygoagr.gif" alt="-"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bien, si dudaste, veamos de cerca la respuesta…&lt;/p&gt;

&lt;p&gt;Cuando hablamos de rendimiento y optimización, es importante tener una métrica para determinar qué tan bueno es un algoritmo en algunos casos y qué tan malo puede ser para otros. Para esto existe &lt;strong&gt;&lt;em&gt;Big O notation&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Big O notation&lt;/em&gt;&lt;/strong&gt; nos permite dar una nomenclatura o simbología a la complejidad de los algoritmos. Pongamos como ejemplo un algoritmo de búsqueda, del cual queremos saber su velocidad. Es necesario tener en cuenta que no podemos hablar de tiempo, ya que eso depende del hardware en el que se ejecute: en una MacBook, el mismo algoritmo funcionará más rápido que en un smartphone de gama baja.&lt;/p&gt;

&lt;p&gt;Otro factor a tener en mente es que la mayoría de los algoritmos cambian su rendimiento dependiendo la cantidad de datos que va a procesar. Es decir, algunos algoritmos de búsqueda lo hacen bien cuando el tamaño del input es pequeño, pero pierden efectividad si incrementa y viceversa. Tenemos que considerar el tamaño de los datos, así como el análisis de su posible crecimiento o el peor escenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Big O notation&lt;/em&gt;&lt;/strong&gt; es utilizado en ciencias computacionales para describir el &lt;strong&gt;rendimiento complejidad&lt;/strong&gt; de un algoritmo. Generalmente describe el peor escenario, es decir, el máximo tiempo en la mayor cantidad de repeticiones que el algoritmo tiene que ejecutar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faocw0mk7ttz5djxkurwt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faocw0mk7ttz5djxkurwt.png" alt="Ilustración del libro “grokking algorithms”"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algunos ejemplos populares de expresiones Big O notation son:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(1) — notación constante&lt;/strong&gt;&lt;br&gt;
Esta expresión indica tiempo constante, lo que significa que el algoritmo se ejecutará con el mismo rendimiento sin importar el tamaño del input. Esto no quiere decir que sólo tendrá un input, más bien no se verá afectado por la cantidad de datos que estemos manejando.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findByIndex(food, index) {
  return food[index];
}
var food = ['🍿', '🍔', '🍩', '🍗'];
console.log(findByIndex(food, 2));   🍩
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;O(n) — notación lineal&lt;/strong&gt;&lt;br&gt;
Esta es la expresión de crecimiento lineal, la complejidad del algoritmo aumenta de manera proporcional al tamaño del input.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function selectedFood(food) {
  food.forEach(objectFood =&amp;gt; 
       console.log(objectFood, objectFood)
  );
}
const food = ['🍿', '🍔', '🍩', '🍗'];
selectedFood(food); // 🍿🍿​​​​​ 🍔🍔​​​​​ ​​​​🍩🍩​​​​​ ​​​​​🍗🍗​​​​​
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;O(n2) — notación cuadrática&lt;/strong&gt;&lt;br&gt;
Indica que el crecimiento en complejidad es proporcional al cuadrado del tamaño del input. Estos algoritmos suelen ser los menos eficientes, no se recomiendan para datos grandes y normalmente se dan cuando usamos ciclos for o iteraciones anidadas; es decir, si dentro de cada iteración de un arreglo lo vuelves a iterar, tendrás un algoritmo de complejidad cuadrada. Estos pueden llegar a complejidades cúbicas o factoriales.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(array){
  array = array.slice();
  for (let i = 0; i &amp;lt; array.length; i++) {
    for (let j = 0; j &amp;lt; array.length - 1; j++) {
      if (array[j] &amp;gt; array[j + 1]) {
        [array[j], array[j + 1]] = [array[j + 1], array[j]];
      }
    }
  }
  return array;
}
var array = [ 4, 3, 2, 1];
console.log(bubbleSort(array)); // [ 1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;O(log n) — notación logarítmica&lt;/strong&gt;&lt;br&gt;
Indica que el tiempo aumenta linealmente, mientras que n sube exponencialmente. Entonces, si se tarda 1 segundo en calcular 10 elementos, se necesitarán 2 para 100, 3 para 1000 y así sucesivamente.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function binarySearch(array, element, start = 0, end = (array.length - 1)) {
  if (end &amp;lt; start) return -1;
  var middle = Math.floor((start + end) / 2);
  return element === array[middle]
    ? middle
    : element &amp;lt; array[middle]
      ? binarySearch(array, element, start, middle - 1)
      : binarySearch(array, element, middle + 1, end);
}
var unsortedArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log("Index of 2: ", binarySearch(unsortedArray, 2));    // Index of 2: 1
console.log("22 not found: ", binarySearch(unsortedArray, 22)); // 22 not found: -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bien, teniendo en cuenta estas expresiones, quiero mostrarles un resumen visual de &lt;strong&gt;Aditya Y. Bhargav&lt;/strong&gt; en su libro &lt;a href="https://www.manning.com/books/grokking-algorithms" rel="noopener noreferrer"&gt;grokking algorthims&lt;/a&gt;, que muestra una comparativa genial de tiempo y tamaño de ejecución de lo que acabamos de ver:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiduel9qj10gx9zruolc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiduel9qj10gx9zruolc.png" alt="Ilustración del libro “grokking algorithms”"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;En conclusión, ahora ya sabes que cuando te pregunten “¿cuál es la complejidad de un algoritmo?” esperan que mediante una expresión indiques cómo el tamaño afecta al rendimiento del mismo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0511a2zhmxyftk37kir4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0511a2zhmxyftk37kir4.gif" alt="-"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nos leemos luego.&lt;/p&gt;

</description>
      <category>bigonotation</category>
      <category>algorithms</category>
      <category>javascript</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>asd</title>
      <dc:creator>owivans</dc:creator>
      <pubDate>Wed, 20 Sep 2023 02:53:17 +0000</pubDate>
      <link>https://dev.to/owivans/asd-68b</link>
      <guid>https://dev.to/owivans/asd-68b</guid>
      <description>&lt;p&gt;asd&lt;/p&gt;

</description>
    </item>
    <item>
      <title>NodeJS with Kafka: Build Async Programs with ease</title>
      <dc:creator>owivans</dc:creator>
      <pubDate>Wed, 20 Sep 2023 02:52:32 +0000</pubDate>
      <link>https://dev.to/owivans/nodejs-with-kafka-build-async-programs-with-ease-43fh</link>
      <guid>https://dev.to/owivans/nodejs-with-kafka-build-async-programs-with-ease-43fh</guid>
      <description>&lt;p&gt;asdasdasdasd&lt;/p&gt;

</description>
    </item>
    <item>
      <title>sdsd</title>
      <dc:creator>owivans</dc:creator>
      <pubDate>Wed, 20 Sep 2023 01:49:38 +0000</pubDate>
      <link>https://dev.to/owivans/test-3d3b</link>
      <guid>https://dev.to/owivans/test-3d3b</guid>
      <description>&lt;p&gt;sdsdasd&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
