-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
32 lines (25 loc) · 1.06 KB
/
plotter.py
File metadata and controls
32 lines (25 loc) · 1.06 KB
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
from util import *
import matplotlib.pyplot as plt
from sorting import Sorter
sorter = Sorter()
sorting_functions = {'Selection': sorter.selection_sort, 'Insertion': sorter.insertion_sort,
'Bubble': sorter.bubble_sort, 'Heap': sorter.heap_sort,
'Quick': sorter.quick_sort,'Merge': sorter.merge_sort}
results = {'Selection': [], 'Insertion': [], 'Bubble': [], 'Heap': [], 'Quick': [], 'Merge': []}
array_sizes = []
def _start():
for i in range(0, 10):
array_sizes.append(100 * i)
args = get_almost_sorted_case(100 * i, 500 * i)
print("Test case: ", i, "\t n = ", 100 * i)
for function in sorting_functions:
t = measure_algorithm(args[:], sorting_functions.get(function))
print(function, ": ", t)
results.get(function).append(t)
plt.xlabel("n (number of elements in array)")
plt.ylabel("t (time taken to sort)")
for function in sorting_functions:
plt.plot(array_sizes, results.get(function), label=function)
plt.legend()
plt.show()
_start()