Selection sort

Title Text

Selection sort es un algoritmo de ordenamiento que funciona buscando en un arreglo de elementos el indice con el valor más pequeño, luego es copiado a un nuevo arreglo y así sucesivamente hasta haber pasado por todos los elementos.

def find_smallest(array):
	smallest = array[0]
    smallest_index = 0
    for i in range(1, len(array)):
    	if array[i] < smallest:
        	smallest = array[i]
            smallest_index = i
    return smallest_index
    
def selection_sort(array):
	new_array = []
    for i in range(len(array)):
    	smallest = find_smallest(array)
        new_array.append(array.pop(smallest))
    return new_array

Title Text

Selection sort

By Maricela Sanchez

Selection sort

  • 657