From 854074ed0dfd37d2297019c9408ebdcc27841dfa Mon Sep 17 00:00:00 2001 From: anikinvd Date: Fri, 22 May 2026 17:51:14 +0000 Subject: [PATCH] [1] Add plots --- .../docs/data/1-st-exercise/plot_results.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 anikinvd/docs/data/1-st-exercise/plot_results.py diff --git a/anikinvd/docs/data/1-st-exercise/plot_results.py b/anikinvd/docs/data/1-st-exercise/plot_results.py new file mode 100644 index 0000000..0efafc6 --- /dev/null +++ b/anikinvd/docs/data/1-st-exercise/plot_results.py @@ -0,0 +1,38 @@ +import pandas as pd +import matplotlib.pyplot as plt +import numpy as np + +df = pd.read_csv('experiment_results.csv') + +mean_times = df.groupby(['Structure', 'Mode'])[['Insert (sec)', 'Search (sec)', 'Delete (sec)']].mean().reset_index() + +structures = mean_times['Structure'].unique() +modes = mean_times['Mode'].unique() + +fig, axes = plt.subplots(1, 3, figsize=(15, 5)) +operations = ['Insert (sec)', 'Search (sec)', 'Delete (sec)'] +titles = ['Insertion', 'Search', 'Deletion'] + +for ax, op, title in zip(axes, operations, titles): + x = np.arange(len(structures)) + width = 0.35 + + random_vals = [] + sorted_vals = [] + for s in structures: + random_row = mean_times[(mean_times['Structure'] == s) & (mean_times['Mode'] == 'random')] + sorted_row = mean_times[(mean_times['Structure'] == s) & (mean_times['Mode'] == 'sorted')] + random_vals.append(random_row[op].values[0] if not random_row.empty else 0) + sorted_vals.append(sorted_row[op].values[0] if not sorted_row.empty else 0) + + ax.bar(x - width/2, random_vals, width, label='Random order') + ax.bar(x + width/2, sorted_vals, width, label='Sorted order') + ax.set_xticks(x) + ax.set_xticklabels(structures) + ax.set_ylabel('Time (seconds)') + ax.set_title(title) + ax.legend() + +plt.tight_layout() +plt.savefig('performance_comparison.png', dpi=150) +plt.show() \ No newline at end of file