Selection Sort Program in Python



def findMinIndex(A, start):  
    min_index = start  
  
    start += 1  
  
    while start < len(A):  
        if A[start] < A[min_index]:  
            min_index = start  
  
        start += 1  
  
    return min_index  
  
def selectionSort(A):  
    i = 0  
  
    while i < len(A):  
        min_index = findMinIndex(A, i)  
  
        if i != min_index:  
            A[i], A[min_index] = A[min_index], A[i]  
          
        i += 1  
  
A = [5, 2, 6, 7, 2, 1, 0, 3]  
  
selectionSort(A)  
  
for num in A:  
    print(num, end=' ')

Source: Interviewbit.com

Recent Posts

See All

Tuning using HyperOpt in python

HyperOpt provides an optimization interface that accepts an evaluation function and parameter space, and can calculate the loss function value of a point in the parameter space. The user also specifie