Browse Source

Lecture 2

master
Oliver Hofmann 8 months ago
parent
commit
8bb627a500
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      SoSe24/lec03_sort_alg/merge_plot.py

+ 13
- 4
SoSe24/lec03_sort_alg/merge_plot.py View File

@@ -36,12 +36,21 @@ def merge_sort(z: AlgoDatArray, storage: AlgoDatArray, left: int, right: int):
if __name__ == "__main__":
filename = "../../seq3.txt"
dummy = read_int_sequence("../../seq3.txt")
for right_end in range(1, len(dummy), len(dummy)//100):
n = len(dummy)
step = n // 100

memory_values = []
compare_values = []

for right_end in range(1, n, step):
AlgoDatValue.reset()
z = read_int_sequence_limited(filename, right_end)
storage = AlgoDatArray(z.size)
merge_sort(z, storage, 0, right_end-1)
plt.plot([right_end], [AlgoDatValue.memory], 'bo')
plt.plot([right_end], [AlgoDatValue.compare], 'ro')
memory_values.append(AlgoDatValue.memory)
compare_values.append(AlgoDatValue.compare)

plt.show()
plt.plot(range(1, n, step), memory_values, 'b', label='Memory')
plt.plot(range(1, n, step), compare_values, 'r', label='Compare')
plt.legend()
plt.show()

Loading…
Cancel
Save