Pseudocódigo
Lección 4 de 9 del curso Ordenamiento por mezcla - Serie de DSA de Coddy.
mergeSort(array):
if length(array) <= 1:
return array
mid = length(array) / 2
left = mergeSort(array[0..mid])
right = mergeSort(array[mid..end])
return merge(left, right)
merge(left, right):
result = []
while left and right both still have elements:
if left[0] <= right[0]:
move the front of left into result
else:
move the front of right into result
append whatever remains of left
append whatever remains of right
return resultDos funciones trabajan juntas:
- mergeSort continúa dividiendo el arreglo hasta que las piezas están trivialmente ordenadas, luego confía en merge para combinarlas.
- merge recorre dos listas ordenadas a la vez, tomando siempre el elemento frontal más pequeño, de modo que la lista combinada se mantenga ordenada.
Pruébalo tú mismo
Esta lección no incluye un desafío de código.
Esta lección incluye un breve cuestionario. Empieza la lección para responderlo y registrar tu progreso.
Todas las lecciones de Ordenamiento por mezcla - Serie de DSA
2El algoritmo
¿Cómo funciona?PseudocódigoImplementación (parte 1)Implementación (parte 2)Practica por tu cuenta: Compilador de C online