2026-rff_mp/MarkinAM/1/plot.py

62 lines
2.0 KiB
Python
Raw Normal View History

2026-05-25 06:57:30 +00:00
# -*- coding: utf-8 -*-
"""
Created on Sat May 23 07:31:00 2026
@author: 79080
"""
import matplotlib.pyplot as plt
import numpy as np
data = {
("LinkedList", "shuffled", "insert"): 7.027040939,
("HashTable", "shuffled", "insert"): 0.0335156,
("BST", "shuffled", "insert"): 0.0416449599,
("LinkedList", "shuffled", "find"): 0.06288604,
("HashTable", "shuffled", "find"): 0.000380139,
("BST", "shuffled", "find"): 0.004672663999,
("LinkedList", "shuffled", "delete"): 0.02015744,
("HashTable", "shuffled", "delete"): 0.00018072,
("BST", "shuffled", "delete"): 0.00052726,
("LinkedList", "sorted", "insert"): 6.9302003,
("HashTable", "sorted", "insert"): 0.0654692,
("BST", "sorted", "insert"): 9.4514979003174,
("LinkedList", "sorted", "find"): 0.0654692,
("HashTable", "sorted", "find"): 0.0003763999,
("BST", "sorted", "find"): 0.11124382,
("LinkedList", "sorted", "delete"): 0.02090885999,
("HashTable", "sorted", "delete"): 0.0001772999,
("BST", "sorted", "delete"): 0.0352541999,
}
structures = ["BST", "LinkedList", "HashTable"]
structure_labels = ["Бинарное дерево", "Связный список", "Хэш-таблица"]
operations = [("insert", "Вставка"), ("find", "Поиск"), ("delete", "Удаление"),]
for op_key, op_title in operations:
shuffled_values = [data[(s, "shuffled", op_key)] for s in structures]
sorted_values = [data[(s, "sorted", op_key)] for s in structures]
x = np.arange(len(structures))
width = 0.40
plt.figure(figsize=(10, 5))
plt.bar(x - width / 2, shuffled_values, width, label="Случайный")
plt.bar(x + width / 2, sorted_values, width, label="Отсортированный")
plt.title(op_title)
plt.ylabel("Время (сек)")
plt.xticks(x, structure_labels)
plt.legend()
plt.grid(axis="y", alpha=0.3)
plt.tight_layout()
plt.savefig(f"{op_key}_chart.svg", format="svg")
plt.show()