def selection_sort(A, show_progress=False):
    """
    The selection sort algorithm sorts an array by repeatedly
    finding the minimum element (considering ascending order)
    from unsorted part and putting it at the beginning.
    The algorithm maintains two subarrays in a given array.

    1) The subarray which is already sorted.
    2) Remaining subarray which is unsorted.

    In every iteration of selection sort, the minimum element
    (considering ascending order) from the unsorted subarray
    is picked and moved to the sorted subarray.
    """

    #Iterate the array as many times as there are items-1
    for k in range(len(A)-1):
        if show_progress:
            print(A)

        #Reference value for comparison
        ref = k

        #Find the smallest item of the array and put it in the front
        for i in range(k+1, len(A)):
            if A[i] < A[ref]:
                ref = i

        A[ref], A[k] = A[k], A[ref]

    if show_progress:
        print(A)

    return A