-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparison.py
58 lines (55 loc) · 1.7 KB
/
Comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from bubbleSort import bubble_sort
from bucketSort import bucket_sort
from combSort import comb_sort
from countingSort import counting_sort
from heapSort import heap_sort
from insertionSort import insertion_sort
from LSDradixSort import lsd_radix_sort
from mergeSort import merge_sort
from pigeonholeSort import pigeonhole_sort
from quickSort import quick_sort
from selectionSort import selection_sort
from shellSort import shell_sort
from random import randint
how_many = 1000
lower_integer = 0
upper_integer = 999
if __name__ == "__main__":
array = []
for i in range(how_many):
array.append(randint(lower_integer, upper_integer))
temp = array[:]
bubble_sort(temp)
temp = array[:]
bucket_sort(temp, how_many // 100)
temp = array[:]
comb_sort(temp)
temp = array[:]
counting_sort(temp)
temp = array[:]
heap_sort(temp)
temp = array[:]
insertion_sort(temp)
temp = array[:]
shell_sort(temp)
temp = array[:]
lsd_radix_sort(temp)
temp = array[:]
pigeonhole_sort(temp)
temp = array[:]
selection_sort(temp)
temp = array[:]
(comparisons, array_accesses, additional_space) = merge_sort(temp)
print("Merge sort:")
print("No. comparisons: " + str(comparisons) +
", no. array accesses: " +
str(array_accesses) + ", no. additional space required: "
+ str(additional_space))
temp = array[:]
(comparisons, array_accesses) = quick_sort(temp, 0, len(temp) - 1, 0, 0)
additional_space = 0
print("Quick sort:")
print("No. comparisons: " + str(comparisons) +
", no. array accesses: " +
str(array_accesses) + ", no. additional space required: "
+ str(additional_space))