Skip to content
Snippets Groups Projects
Commit 00ae36bb authored by nilsl99's avatar nilsl99
Browse files

Changed the marker

parent 2f97bfaf
Branches
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
from Aufgabe02 import HeapSort, InsertionSort, CountingSort
from time import perf_counter_ns as time
import random
import matplotlib.pyplot as plt
```
%% Cell type:markdown id: tags:
# Counting Sort
%% Cell type:code id: tags:
``` python
max_num = 99
num_list = range(max_num + 1)
n_list = [100*i+10 for i in range(100)]
t_list = [0]*len(n_list)
for i, n in enumerate(n_list):
for j in range(10):
array = random.choices(num_list, k=n)
t0 = time()
sorted_array = CountingSort(array, k=max_num)
t1 = time()
t_list[i] += t1 - t0
t_list_ms = [t/1e+6 for t in t_list]
```
%% Cell type:code id: tags:
``` python
t_list_alt = [0]*len(n_list)
for i, n in enumerate(n_list):
for j in range(10):
array = random.choices(num_list, k=n)
t0 = time()
sorted_array = CountingSort(array)
t1 = time()
t_list_alt[i] += t1 - t0
t_list_alt_ms = [t/1e+6 for t in t_list_alt]
```
%% Cell type:code id: tags:
``` python
fig = plt.figure(figsize=(10,7), dpi=100)
ax = fig.add_subplot(111)
fig.suptitle("CountingSort", fontsize=24)
ax.set_title("Dauer von 10 Sortiervorgängen")
ax.set_xlabel("Anzahl der zu sortierenden Elemente")
ax.set_ylabel("Zeit in Millisekunden")
ax.grid("both")
ax.plot(n_list, t_list_ms, label="Maximum gegeben")
ax.plot(n_list, t_list_ms, "or", fillstyle="none", label="Maximum gegeben")
# ax.plot(n_list, t_list_alt_ms, label="Maximum nicht gegeben")
# ax.legend()
fig.tight_layout()
plt.savefig("CountingSortGraph.png", dpi=200)
plt.show()
```
%% Output
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment