Added Analysis and answer for Questiontask

This commit is contained in:
Bernhard Schoeffel 2025-04-13 00:17:19 +02:00
parent 1853c4d126
commit 04b6cddb39

View File

@ -54,7 +54,6 @@ def swap(z: MemoryArray, i: int, j: int):
z[Literal(i)] = z[Literal(j)]
z[Literal(j)].set(tmp)
# toSort[] --> Array to be sorted,
# left --> Starting index,
# right --> Ending index
@ -162,11 +161,10 @@ def analyze_complexity(fn, sizes):
for size in sizes:
MemoryManager.purge() # Speicher zurücksetzen
random_array = MemoryArray.create_random_array(size, -100, 100)
other_array = MemoryArray([-1] * size)
fn(random_array, other_array)
fn(random_array, Literal(0), random_array.length().pred())
MemoryManager.save_stats(size)
MemoryManager.plot_stats(["cells", "adds", "compares"])
MemoryManager.plot_stats(["cells", "adds", "compares", "reads", "writes"])
if __name__ == '__main__':
@ -181,9 +179,14 @@ if __name__ == '__main__':
quickSortIterative(toSort, Literal(0), toSort.length().pred())
print(toSort)
analyze_complexity(quickSortIterative, [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
'''
for filename in ["data/seq0.txt", "data/seq1.txt", "data/seq2.txt" ,"data/seq3.txt"]:
# for filename in [ "data/seq1.txt"]:
print(filename)
toSort = MemoryArray.create_array_from_file(filename)
timeMS(quickSortIterative, toSort, Literal(0), toSort.length().pred(), mode=1)
timeMS(quickSortIterative, toSort, Literal(0), toSort.length().pred(), mode=0)
# print(toSort)
'''
print("Kann durch die Modifikation eine besser Laufzeit als nlog(n) erreicht werden? Nein! nlog(n) ist das Minimum. Durch die Änderung kann aber der Worst-Case fall von n^2 für z.B. bereits vorsortierte Arrays oder Arrays mit vielen Duplikaten vermieden werden.")