From 04b6cddb39cc5dd1690878f89dc7624d0563970c Mon Sep 17 00:00:00 2001 From: schoeffelbe82781 Date: Sun, 13 Apr 2025 00:17:19 +0200 Subject: [PATCH] Added Analysis and answer for Questiontask --- schoeffelbe/pr03.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/schoeffelbe/pr03.py b/schoeffelbe/pr03.py index cd467b2..eb0a8cd 100644 --- a/schoeffelbe/pr03.py +++ b/schoeffelbe/pr03.py @@ -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.")