Selection sort
  • Best Case, O(n^2)
  • Worst Case, Ω(n^2)
  • Memory Complexity, O(1)
  • #!/usr/bin/python
    
    import random
    
    def select_sort(l):
        n = len(l)
    
        for i in range(n-1):
            min_index = i
    	# Find the minimum element in unsorted array
            for j in range(i+1, n):
                if l[j] < l[min_index]:
                    min_index = j
            l[i], l[min_index] = l[min_index], l[i]
    
    def get_list():
        random.seed()
    
        l = []
        for i in range(10):
            l.append(random.choice(range(10)))
    
        return l
    
    def main():
        l = get_list()
        print(l)
    
        select_sort(l)
        print(l)
    
    if __name__ == '__main__':
        main()