Implement the sorting algorithm you came up with in pseudocode with Python Test the sorting algorithm with a list of 10, 100, 1000 random numbers and compare the result using the %time to time your code and submit your results in code comments


In [ ]:
# input: Array A[1...n], of elements in arbitrary order array size n; 
# operation: sort the list; 
# output:Array A[1...n] of the same elements, but in the increasng order

In [7]:
import random

In [19]:
source_list=[1,5,100,10,2,4]
new_list=[]
while source_list:
    minimum = source_list[0]
    for i in source_list:
        if i < minimum:
            minimum=i
    new_list.append(minimum)
    source_list.remove(minimum)
print(new_list)


[1, 2, 4, 5, 10, 100]

In [13]:
def sorting(source_list):
    new_list=[]
    source_list=[1,5,100,10,2,4]
    while source_list:
        minimum = source_list[0]
        for i in source_list:
            if i < minimum:
                minimum=i
        new_list.append(minimum)
        source_list.remove(minimum)
    return new_list

In [ ]:
#%time:Time execution of a Python statement or expression.

In [15]:
list_10 = random.sample(range(1, 11),10)
list_100 = random.sample(range(1, 101), 100)
list_1000 = random.sample(range(1, 1001), 1000)

In [16]:
%time sorting(list_10)


CPU times: user 16 µs, sys: 1 µs, total: 17 µs
Wall time: 21 µs
Out[16]:
[1, 2, 4, 5, 10, 100]

In [17]:
%time sorting(list_100)


CPU times: user 16 µs, sys: 1 µs, total: 17 µs
Wall time: 21 µs
Out[17]:
[1, 2, 4, 5, 10, 100]

In [18]:
%time sorting(list_1000)


CPU times: user 10 µs, sys: 0 ns, total: 10 µs
Wall time: 11.9 µs
Out[18]:
[1, 2, 4, 5, 10, 100]

In [ ]: