Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
14 Hrs
49 Min
54 Seg

Notaci贸n big O

23/24

Reading

The Big O notation or also known as the Big O notation is the mathematical expression of how long it takes to execute an algorithm as a function of the input length, usually talking about the worst case.

...

Register or login to read the rest of the content.

Contributions 5

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Hay un curso de BigO muy bueno

Otros algoritmos de b煤squeda muy famosos que usan O(n log n) son los binarios. Cualquier algoritmo binario tiene esta notaci贸n, lo cual la hace muy eficiente, pero para que esto funcione, la data necesita estar ordenada.

La notaci贸n Big O es un concepto fundamental en ciencias de la computaci贸n y an谩lisis de algoritmos. Se utiliza para describir el rendimiento o complejidad de un algoritmo, especialmente en t茅rminos de su tiempo de ejecuci贸n o espacio de memoria requerido, a medida que el tama帽o de la entrada aumenta. Importancia: * Permite comparar la eficiencia de diferentes algoritmos. * Ayuda a predecir el comportamiento de un algoritmo con grandes conjuntos de datos. * Es crucial para optimizar el rendimiento de aplicaciones y sistemas.
La notaci贸n Big O en JavaScript se refiere a una forma de analizar y comparar el rendimiento y la eficiencia de los algoritmos y las funciones en t茅rminos de su tiempo de ejecuci贸n y uso de memoria. * **Notaci贸n Big O**: Es una forma de describir la complejidad temporal o espacial de un algoritmo en funci贸n del tama帽o de entrada.

O(1)

<const getLast = items => items[items.length-1];

console.log(getLast(['a', 'b', 'c', 'd'])); //> d(1 iteraci贸n)
console.log(getLast(['a', 'b', 'c', 'd', 'e', 'f', 'g'])); //> g(1 iteraci贸n)> 

O(N)

<const findIndex = (items, match) => {
  for (let i = 0, total = items.length; i < total; i++)
    if (items[i] == match)
      return i;
   return -1;
};

const array= ['a', 'b', 'c', 'd'];
console.log(findIndex(array, 'a')); // 0  (1 iteraci贸n)
console.log(findIndex(array, 'd')); // 3  (4 iteraciones)
console.log(findIndex(array, 'e')); // -1 (4 iteraciones)> 

O(N虏)

<const buildSquareMatrix = items => {
  let matrix = [];
  for (let i = 0, total = items.length; i < total; i++){ 
    matrix[i] = [];
    for (let j = 0, total = items.length; j < total; j++)
      matrix[i].push(items[j]);
  }
  return matrix;
};


console.log(buildSquareMatrix(['a', 'b', 'c'])); 

/* 9 iteraciones para 3 elementos, retorna:
[
  ['a', 'b', 'c'],
  ['a', 'b', 'c'],
  ['a', 'b', 'c']
]

*/ > 

O(n log n)

<const quickSort = list => {
  if (list.length < 2) 
    return list;
  let pivot = list[0];
  let left  = []; 
  let right = [];
  for (let i = 1, total = list.length; i < total; i++){
    if (list[i] < pivot)
      left.push(list[i]);
    else
      right.push(list[i]);
  }
  return [
    ...quickSort(left), 
    pivot, 
    ...quickSort(right)
  ];
};

console.log(quickSort( ['q','a','z','w','s','x','e','d','c','r']));
// ["a", "c", "d", "e", "q", "r", "s", "w", "x", "z"]>