Sunday, March 16, 2014

Extra# 3 cn! sorting algorithm

Using random class, i just make a very simple sorting algorithm that has the time complexity T(n) = O(cn!).

import random
a = [random.randint(0, 10) for n in range(10)]
print('initial list', a)
while not all([a[i] <= a[i+1] for i in range(len(a) - 1)]):
    random.shuffle(a)
print('sorted list', a)

No comments:

Post a Comment