From a8baea68c76691468853c0f200241a1f5521fed2 Mon Sep 17 00:00:00 2001 From: tseremonnikovaaa Date: Fri, 22 May 2026 23:07:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tseremonnikovaaa/task 1/docs/data/main.py | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/tseremonnikovaaa/task 1/docs/data/main.py b/tseremonnikovaaa/task 1/docs/data/main.py index e449334..3fa9403 100644 --- a/tseremonnikovaaa/task 1/docs/data/main.py +++ b/tseremonnikovaaa/task 1/docs/data/main.py @@ -280,4 +280,132 @@ def measure_deletion(struct_type, records): end = time.perf_counter() times.append(end - start) return times +def plot_bar_charts(insert_data, search_data, delete_data): + """Построение столбчатых диаграмм""" + + structures = ['ll', 'ht', 'bst'] + labels = ['Связный список', 'Хеш-таблица', 'Двоичное дерево'] + mode_labels = ['Случайный порядок', 'Отсортированный порядок'] + colors = ['skyblue', 'salmon'] + + x = np.arange(len(structures)) + width = 0.35 + + # График вставки + fig1, ax1 = plt.subplots(figsize=(10, 6)) + means_sh = [sum(insert_data[s]['shuffled'])/len(insert_data[s]['shuffled']) for s in structures] + means_so = [sum(insert_data[s]['sorted'])/len(insert_data[s]['sorted']) for s in structures] + + rects1 = ax1.bar(x - width/2, means_sh, width, label=mode_labels[0], color=colors[0]) + rects2 = ax1.bar(x + width/2, means_so, width, label=mode_labels[1], color=colors[1]) + + ax1.set_ylabel('Время (секунды)') + ax1.set_title('Вставка всех записей (10000 шт.)') + ax1.set_xticks(x) + ax1.set_xticklabels(labels) + ax1.legend() + ax1.set_yscale('log') + + for rect in rects1 + rects2: + h = rect.get_height() + ax1.annotate(f'{h:.4f}', xy=(rect.get_x() + rect.get_width()/2, h), + xytext=(0, 3), textcoords="offset points", ha='center', va='bottom', fontsize=8) + + plt.tight_layout() + plt.savefig('insert_comparison.png', dpi=150) + plt.show() + print(" График вставки сохранён: insert_comparison.png") + + # График поиска + fig2, ax2 = plt.subplots(figsize=(10, 6)) + means_sh = [sum(search_data[s]['shuffled'])/len(search_data[s]['shuffled']) for s in structures] + means_so = [sum(search_data[s]['sorted'])/len(search_data[s]['sorted']) for s in structures] + + rects1 = ax2.bar(x - width/2, means_sh, width, label=mode_labels[0], color=colors[0]) + rects2 = ax2.bar(x + width/2, means_so, width, label=mode_labels[1], color=colors[1]) + + ax2.set_ylabel('Время (секунды)') + ax2.set_title('Поиск (100 существующих + 10 отсутствующих)') + ax2.set_xticks(x) + ax2.set_xticklabels(labels) + ax2.legend() + + for rect in rects1 + rects2: + h = rect.get_height() + ax2.annotate(f'{h:.6f}', xy=(rect.get_x() + rect.get_width()/2, h), + xytext=(0, 3), textcoords="offset points", ha='center', va='bottom', fontsize=8) + + plt.tight_layout() + plt.savefig('search_comparison.png', dpi=150) + plt.show() + print(" График поиска сохранён: search_comparison.png") + + # График удаления + fig3, ax3 = plt.subplots(figsize=(10, 6)) + means_sh = [sum(delete_data[s]['shuffled'])/len(delete_data[s]['shuffled']) for s in structures] + means_so = [sum(delete_data[s]['sorted'])/len(delete_data[s]['sorted']) for s in structures] + + rects1 = ax3.bar(x - width/2, means_sh, width, label=mode_labels[0], color=colors[0]) + rects2 = ax3.bar(x + width/2, means_so, width, label=mode_labels[1], color=colors[1]) + + ax3.set_ylabel('Время (секунды)') + ax3.set_title('Удаление 50 случайных записей') + ax3.set_xticks(x) + ax3.set_xticklabels(labels) + ax3.legend() + + for rect in rects1 + rects2: + h = rect.get_height() + ax3.annotate(f'{h:.6f}', xy=(rect.get_x() + rect.get_width()/2, h), + xytext=(0, 3), textcoords="offset points", ha='center', va='bottom', fontsize=8) + + plt.tight_layout() + plt.savefig('delete_comparison.png', dpi=150) + plt.show() + print(" График удаления сохранён: delete_comparison.png") + + +def plot_attempts_graphs(data, op_name, op_title): + """Построение графиков по 5 попыткам""" + fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5)) + + struct_config = [ + ('ll', 'Связный список', 'red', 'o'), + ('ht', 'Хеш-таблица', 'green', 's'), + ('bst', 'Двоичное дерево', 'blue', '^') + ] + + # Случайный порядок + for struct, label, color, marker in struct_config: + times = data[struct]['shuffled'] + x = range(1, len(times) + 1) + ax1.plot(x, times, marker=marker, color=color, label=label, + linestyle='--', linewidth=1) + ax1.scatter(x, times, color=color, s=60, zorder=5) + + ax1.set_xlabel('Номер попытки') + ax1.set_ylabel('Время (секунды)') + ax1.set_title(f'{op_title} – случайный порядок') + ax1.legend() + ax1.grid(True, linestyle=':', alpha=0.7) + + # Отсортированный порядок + for struct, label, color, marker in struct_config: + times = data[struct]['sorted'] + x = range(1, len(times) + 1) + ax2.plot(x, times, marker=marker, color=color, label=label, + linestyle='--', linewidth=1) + ax2.scatter(x, times, color=color, s=60, zorder=5) + + ax2.set_xlabel('Номер попытки') + ax2.set_ylabel('Время (секунды)') + ax2.set_title(f'{op_title} – отсортированный порядок') + ax2.legend() + ax2.grid(True, linestyle=':', alpha=0.7) + + plt.tight_layout() + plt.savefig(f'{op_name}_5attempts.png', dpi=150) + plt.show() + print(f" График {op_name}_5attempts.png сохранён") +