Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 17, 2021 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e914a708e13f1bd3166660dd04072eb8 to your computer and use it in GitHub Desktop.
Save parzibyte/e914a708e13f1bd3166660dd04072eb8 to your computer and use it in GitHub Desktop.
def merge_sort(arreglo):
longitud = len(arreglo)
mitad = longitud//2 # El doble / es para dividir y redondear hacia abajo
# Condición de salida de recursividad es que el arreglo mida 1 o 0
if longitud <= 1:
return arreglo
mitad_izquierda = arreglo[:mitad]
mitad_derecha = arreglo[mitad:]
mitad_izquierda = merge_sort(mitad_izquierda)
mitad_derecha = merge_sort(mitad_derecha)
return merge(mitad_izquierda, mitad_derecha)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment