forked from UNN/2026-rff_mp
[4]full
This commit is contained in:
parent
56509603c7
commit
f4e8b9732e
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB |
|
|
@ -1,91 +0,0 @@
|
|||
Структура,Режим,Операция,Время (сек)
|
||||
LinkedList,shuffled,insert,0.154480
|
||||
LinkedList,shuffled,search,0.001006
|
||||
LinkedList,shuffled,delete,0.000890
|
||||
LinkedList,shuffled,insert,1.084111
|
||||
LinkedList,shuffled,search,0.000904
|
||||
LinkedList,shuffled,delete,0.000629
|
||||
LinkedList,shuffled,insert,0.131441
|
||||
LinkedList,shuffled,search,0.001123
|
||||
LinkedList,shuffled,delete,0.000622
|
||||
LinkedList,shuffled,insert,0.163422
|
||||
LinkedList,shuffled,search,0.000789
|
||||
LinkedList,shuffled,delete,0.000530
|
||||
LinkedList,shuffled,insert,0.145036
|
||||
LinkedList,shuffled,search,0.000570
|
||||
LinkedList,shuffled,delete,0.000318
|
||||
LinkedList,sorted,insert,24.938719
|
||||
LinkedList,sorted,search,0.106848
|
||||
LinkedList,sorted,delete,0.096196
|
||||
LinkedList,sorted,insert,24.883229
|
||||
LinkedList,sorted,search,0.106409
|
||||
LinkedList,sorted,delete,0.094658
|
||||
LinkedList,sorted,insert,24.408379
|
||||
LinkedList,sorted,search,0.115546
|
||||
LinkedList,sorted,delete,0.099195
|
||||
LinkedList,sorted,insert,24.421941
|
||||
LinkedList,sorted,search,0.102282
|
||||
LinkedList,sorted,delete,0.092586
|
||||
LinkedList,sorted,insert,24.125530
|
||||
LinkedList,sorted,search,0.106052
|
||||
LinkedList,sorted,delete,0.093177
|
||||
HashTable,shuffled,insert,0.024262
|
||||
HashTable,shuffled,search,0.000651
|
||||
HashTable,shuffled,delete,0.000211
|
||||
HashTable,shuffled,insert,0.022815
|
||||
HashTable,shuffled,search,0.000259
|
||||
HashTable,shuffled,delete,0.000115
|
||||
HashTable,shuffled,insert,0.026916
|
||||
HashTable,shuffled,search,0.000264
|
||||
HashTable,shuffled,delete,0.000115
|
||||
HashTable,shuffled,insert,0.022850
|
||||
HashTable,shuffled,search,0.000251
|
||||
HashTable,shuffled,delete,0.000115
|
||||
HashTable,shuffled,insert,0.023054
|
||||
HashTable,shuffled,search,0.000261
|
||||
HashTable,shuffled,delete,0.000114
|
||||
HashTable,sorted,insert,0.021750
|
||||
HashTable,sorted,search,0.000246
|
||||
HashTable,sorted,delete,0.000110
|
||||
HashTable,sorted,insert,0.022438
|
||||
HashTable,sorted,search,0.000248
|
||||
HashTable,sorted,delete,0.000111
|
||||
HashTable,sorted,insert,0.021394
|
||||
HashTable,sorted,search,0.000230
|
||||
HashTable,sorted,delete,0.000106
|
||||
HashTable,sorted,insert,0.022591
|
||||
HashTable,sorted,search,0.000285
|
||||
HashTable,sorted,delete,0.000125
|
||||
HashTable,sorted,insert,0.021119
|
||||
HashTable,sorted,search,0.000272
|
||||
HashTable,sorted,delete,0.000122
|
||||
BST,shuffled,insert,0.054849
|
||||
BST,shuffled,search,0.000554
|
||||
BST,shuffled,delete,0.000293
|
||||
BST,shuffled,insert,0.053888
|
||||
BST,shuffled,search,0.000415
|
||||
BST,shuffled,delete,0.000260
|
||||
BST,shuffled,insert,0.053399
|
||||
BST,shuffled,search,0.000407
|
||||
BST,shuffled,delete,0.000256
|
||||
BST,shuffled,insert,0.056071
|
||||
BST,shuffled,search,0.000412
|
||||
BST,shuffled,delete,0.000261
|
||||
BST,shuffled,insert,0.053024
|
||||
BST,shuffled,search,0.000409
|
||||
BST,shuffled,delete,0.000285
|
||||
BST,sorted,insert,24.942325
|
||||
BST,sorted,search,0.108153
|
||||
BST,sorted,delete,0.094860
|
||||
BST,sorted,insert,25.196583
|
||||
BST,sorted,search,0.109160
|
||||
BST,sorted,delete,0.096340
|
||||
BST,sorted,insert,24.691507
|
||||
BST,sorted,search,0.115560
|
||||
BST,sorted,delete,0.094962
|
||||
BST,sorted,insert,24.461825
|
||||
BST,sorted,search,0.103381
|
||||
BST,sorted,delete,0.095198
|
||||
BST,sorted,insert,24.798636
|
||||
BST,sorted,search,0.101888
|
||||
BST,sorted,delete,0.093775
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
Анализ по пунктам задания
|
||||
Влияние порядка входных данных на вставку в BST
|
||||
На отсортированных данных BST превращается в связный список
|
||||
(все узлы добавляются только в правое поддерево),
|
||||
поэтому каждая операция вставки требует прохода по всем ранее вставленным
|
||||
элементам. В результате вместо среднего O(log n) получается O(n) – это хорошо
|
||||
видно по резкому росту времени: с 0.02 с до ~2 с. На перемешанных данных
|
||||
дерево остаётся относительно сбалансированным, и вставка быстра.
|
||||
|
||||
Хеш-таблица почти не чувствительна к порядку
|
||||
Время вставки, поиска и удаления в хеш-таблице определяется в первую
|
||||
очередь длиной цепочек, которая зависит только от количества коллизий, а не
|
||||
от порядка поступления ключей. Хеш-функция равномерно распределяет ключи по
|
||||
бакетам, поэтому shuffled и sorted данные дают практически одинаковые результаты.
|
||||
Небольшое влияние порядка могло бы проявиться лишь при очень высоком коэффициенте
|
||||
заполнения и специфических паттернах хеширования, но на наших масштабах оно
|
||||
пренебрежимо мало.
|
||||
|
||||
Связный список всегда медленен при поиске
|
||||
Поиск в связном списке – линейный (O(n)), потому что требуется перебрать все узлы
|
||||
от головы до искомого или до конца. В нашем эксперименте поиск 110 имён занимал
|
||||
в среднем 0.03 с, что на два порядка медленнее хеш-таблицы и BST в нормальном
|
||||
режиме. Порядок данных не влияет на время поиска (линейный обход всегда одинаков),
|
||||
что видно из таблицы.
|
||||
|
||||
Удаление в каждой структуре
|
||||
В связном списке удаление также O(n) из-за необходимости найти предшествующий узел.
|
||||
В хеш-таблице удаление сводится к удалению в цепочке (коротком связном списке)
|
||||
и практически не отличается от поиска.
|
||||
В BST удаление требует поиска узла (O(log n) в сбалансированном, O(n) в
|
||||
вырожденном), плюс операции по перестройке дерева (поиск минимального в правом
|
||||
поддереве). В вырожденном случае (sorted) удаление деградирует так же, как и поиск/вставка.
|
||||
|
||||
Вывод: какую структуру выбирать в реальной жизни
|
||||
|
||||
Частые вставки/удаления + быстрый поиск → Хеш-таблица. Она обеспечивает O(1) в среднем для всех основных операций, не требует поддержания порядка, проста в реализации. Идеально для словарей, кэшей, индексов баз данных.
|
||||
|
||||
Необходимость получать данные в отсортированном порядке → Сбалансированное BST (красно-чёрное, AVL-дерево). Несбалансированное BST, как показано в эксперименте, может деградировать до O(n) при неудачном порядке данных, поэтому в реальных системах всегда применяют самобалансирующиеся варианты. Их операции выполняются за O(log n) в худшем случае, а in-order обход сразу даёт отсортированный список без дополнительной сортировки. Используются в базах данных (индексы), файловых системах, ordered map в языках.
|
||||
|
||||
Связный список сам по себе редко применяется для задач с частым поиском; он оправдан в сценариях, где данные обрабатываются строго последовательно (очереди, стеки, LRU-кэши), или когда вставка/удаление происходят только в начале/конце и не требуется произвольный доступ.
|
||||
|
||||
Дополнительно: Если нужна и быстрая вставка/удаление, и произвольный доступ по индексу, и порядок, то рассматривают сбалансированные деревья (например, B-деревья) или комбинированные структуры (LinkedHashMap).
|
||||
|
||||
Таким образом, выбор структуры определяется типичными паттернами использования: частота операций вставки, поиска, удаления и требование к упорядоченности данных.
|
||||
BIN
stepinim/lab1_structure/docs/data/lab1_graph.png
Normal file
BIN
stepinim/lab1_structure/docs/data/lab1_graph.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
55
stepinim/lab1_structure/docs/data/lab1_results.csv
Normal file
55
stepinim/lab1_structure/docs/data/lab1_results.csv
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
Структура,Режим,Повтор,Операция,Время (сек)
|
||||
LinkedList,shuffled,1,insert,0.5023735999711789
|
||||
LinkedList,shuffled,1,search,0.022223800013307482
|
||||
LinkedList,shuffled,1,delete,0.010106799949426204
|
||||
LinkedList,shuffled,2,insert,0.5151404999778606
|
||||
LinkedList,shuffled,2,search,0.023844500014092773
|
||||
LinkedList,shuffled,2,delete,0.010028599994257092
|
||||
LinkedList,shuffled,3,insert,0.5328615000471473
|
||||
LinkedList,shuffled,3,search,0.020557800016831607
|
||||
LinkedList,shuffled,3,delete,0.012162799946963787
|
||||
LinkedList,sorted,1,insert,0.4577932999818586
|
||||
LinkedList,sorted,1,search,0.017212599981576204
|
||||
LinkedList,sorted,1,delete,0.012185800005681813
|
||||
LinkedList,sorted,2,insert,0.43183969997335225
|
||||
LinkedList,sorted,2,search,0.01829650002764538
|
||||
LinkedList,sorted,2,delete,0.012130599992815405
|
||||
LinkedList,sorted,3,insert,0.436789300001692
|
||||
LinkedList,sorted,3,search,0.017460400005802512
|
||||
LinkedList,sorted,3,delete,0.012465099978726357
|
||||
HashTable,shuffled,1,insert,0.0032562999986112118
|
||||
HashTable,shuffled,1,search,9.469996439293027e-05
|
||||
HashTable,shuffled,1,delete,5.15999854542315e-05
|
||||
HashTable,shuffled,2,insert,0.0031429000082425773
|
||||
HashTable,shuffled,2,search,9.000004502013326e-05
|
||||
HashTable,shuffled,2,delete,4.360004095360637e-05
|
||||
HashTable,shuffled,3,insert,0.003212600015103817
|
||||
HashTable,shuffled,3,search,0.00010830000974237919
|
||||
HashTable,shuffled,3,delete,4.650000482797623e-05
|
||||
HashTable,sorted,1,insert,0.0030796999926678836
|
||||
HashTable,sorted,1,search,8.420000085607171e-05
|
||||
HashTable,sorted,1,delete,4.730001091957092e-05
|
||||
HashTable,sorted,2,insert,0.0030180999892763793
|
||||
HashTable,sorted,2,search,9.079999290406704e-05
|
||||
HashTable,sorted,2,delete,5.299999611452222e-05
|
||||
HashTable,sorted,3,insert,0.0029779999749734998
|
||||
HashTable,sorted,3,search,8.510000770911574e-05
|
||||
HashTable,sorted,3,delete,6.589997792616487e-05
|
||||
BST,shuffled,1,insert,0.011618499993346632
|
||||
BST,shuffled,1,search,0.00031289999606087804
|
||||
BST,shuffled,1,delete,0.0002456999500282109
|
||||
BST,shuffled,2,insert,0.021565500006545335
|
||||
BST,shuffled,2,search,0.00032350001856684685
|
||||
BST,shuffled,2,delete,0.0002101999707520008
|
||||
BST,shuffled,3,insert,0.011865400010719895
|
||||
BST,shuffled,3,search,0.0003497999859973788
|
||||
BST,shuffled,3,delete,0.0002114999806508422
|
||||
BST,sorted,1,insert,1.961912199971266
|
||||
BST,sorted,1,search,0.025325599999632686
|
||||
BST,sorted,1,delete,0.03309909999370575
|
||||
BST,sorted,2,insert,1.8450072000268847
|
||||
BST,sorted,2,search,0.025074300006963313
|
||||
BST,sorted,2,delete,0.03284020000137389
|
||||
BST,sorted,3,insert,1.8502263000118546
|
||||
BST,sorted,3,search,0.028948499995749444
|
||||
BST,sorted,3,delete,0.040639499959070235
|
||||
|
unable to load file
|
15
stepinim/lab1_structure/docs/otchet_1lab.md
Normal file
15
stepinim/lab1_structure/docs/otchet_1lab.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
В ходе экспериментов было показано, что производительность структуры данных сильно зависит
|
||||
от её внутреннего устройства и характера входных данных.
|
||||
|
||||
BST работает быстро на случайных данных, но при отсортированном порядке деградирует почти до
|
||||
связного списка, из-за чего время вставки и удаления резко увеличивается. Хеш-таблица
|
||||
практически не зависит от порядка входных данных, так как доступ к элементам происходит через
|
||||
хеш-функцию, поэтому она показала лучшие результаты при поиске и вставке. Связный список
|
||||
оказался самым медленным при поиске, так как требует последовательного обхода элементов.
|
||||
|
||||
Удаление также работает по-разному: в связном списке и BST сначала требуется поиск элемента,
|
||||
а в хеш-таблице удаление обычно выполняется быстрее за счёт обращения к нужному бакету.
|
||||
|
||||
На практике хеш-таблицы лучше подходят для частого поиска и вставки данных, BST — когда
|
||||
важно хранить элементы в отсортированном виде, а связные списки полезны в более простых
|
||||
задачах, где структура данных часто изменяется и не требуется быстрый поиск.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import sys
|
||||
sys.setrecursionlimit(20000)
|
||||
sys.setrecursionlimit(30000)
|
||||
|
||||
csv_path = 'C:/Users/xalva/2026-rff_mp/stepinim/docs/data/results.csv'
|
||||
csv_path = '/stepinim/docs/data/lab1_results.csv'
|
||||
|
||||
#Связный список
|
||||
def ll_insert(head, name, phone):
|
||||
|
|
@ -131,125 +131,303 @@ def bst_list_all(root):
|
|||
inorder(root)
|
||||
return result
|
||||
|
||||
#ТЕСТ
|
||||
# ============================================================
|
||||
# TECT
|
||||
# ============================================================
|
||||
|
||||
import os
|
||||
import random
|
||||
random.seed(42)
|
||||
N = 10000
|
||||
base_records = [(f"User_{i:05d}", f"123-{i:05d}") for i in range(N)]
|
||||
records_shuffled = base_records.copy()
|
||||
random.shuffle(records_shuffled)
|
||||
records_sorted = sorted(base_records, key=lambda x: x[0])
|
||||
|
||||
# 100 случайных существующих имён из всего набора
|
||||
random_sample = random.sample(base_records, 100)
|
||||
search_existing = [name for name, _ in random_sample]
|
||||
# 10 несуществующих
|
||||
search_nonexist = [f"None_{i}" for i in range(10)]
|
||||
# 50 случайных для удаления
|
||||
delete_sample = random.sample(base_records, 50)
|
||||
delete_names = [name for name, _ in delete_sample]
|
||||
|
||||
import time
|
||||
import csv
|
||||
import statistics
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# ============================================================
|
||||
# ПОДГОТОВКА ПАПОК
|
||||
# ============================================================
|
||||
|
||||
DATA_DIR = os.path.join("docs", "data")
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
|
||||
csv_path = os.path.join(DATA_DIR, "lab1_results.csv")
|
||||
graph_path = os.path.join(DATA_DIR, "lab1_graph.png")
|
||||
|
||||
# ============================================================
|
||||
# ТЕСТОВЫЕ ДАННЫЕ
|
||||
# ============================================================
|
||||
|
||||
random.seed(42)
|
||||
|
||||
N = 3000
|
||||
|
||||
base_records = [
|
||||
(f"User_{i:05d}", f"123-{i:05d}")
|
||||
for i in range(N)
|
||||
]
|
||||
|
||||
records_shuffled = base_records.copy()
|
||||
random.shuffle(records_shuffled)
|
||||
|
||||
records_sorted = sorted(base_records, key=lambda x: x[0])
|
||||
|
||||
# Поиск
|
||||
search_existing = [
|
||||
name for name, _ in random.sample(base_records, 100)
|
||||
]
|
||||
|
||||
search_nonexist = [
|
||||
f"None_{i}"
|
||||
for i in range(10)
|
||||
]
|
||||
|
||||
# Удаление
|
||||
delete_names = [
|
||||
name for name, _ in random.sample(base_records, 50)
|
||||
]
|
||||
|
||||
# ============================================================
|
||||
# СОЗДАНИЕ СТРУКТУР
|
||||
# ============================================================
|
||||
|
||||
def build_structure(records, struct_type):
|
||||
|
||||
if struct_type == "ll":
|
||||
structure = None
|
||||
|
||||
for name, phone in records:
|
||||
structure = ll_insert(structure, name, phone)
|
||||
|
||||
return structure
|
||||
|
||||
elif struct_type == "ht":
|
||||
structure = [None] * HASH_SIZE
|
||||
|
||||
for name, phone in records:
|
||||
ht_insert(structure, name, phone)
|
||||
|
||||
return structure
|
||||
|
||||
elif struct_type == "bst":
|
||||
structure = None
|
||||
|
||||
for name, phone in records:
|
||||
structure = bst_insert(structure, name, phone)
|
||||
|
||||
return structure
|
||||
|
||||
|
||||
def measure_operations(records, struct_type):
|
||||
results = []
|
||||
for rep in range(5):
|
||||
if struct_type == 'll':
|
||||
head = None
|
||||
elif struct_type == 'ht':
|
||||
head = [None] * HASH_SIZE
|
||||
else:
|
||||
root = None
|
||||
# ============================================================
|
||||
# INSERT
|
||||
# ============================================================
|
||||
|
||||
start = time.perf_counter()
|
||||
if struct_type == 'll':
|
||||
for name, phone in records:
|
||||
head = ll_insert(head, name, phone)
|
||||
elif struct_type == 'ht':
|
||||
for name, phone in records:
|
||||
ht_insert(head, name, phone)
|
||||
else:
|
||||
for name, phone in records:
|
||||
root = bst_insert(root, name, phone)
|
||||
insert_time = time.perf_counter() - start
|
||||
results.append((rep + 1, 'insert', insert_time))
|
||||
def measure_insert(records, struct_type):
|
||||
|
||||
start = time.perf_counter()
|
||||
if struct_type == 'll':
|
||||
for name in search_existing + search_nonexist:
|
||||
ll_find(head, name)
|
||||
elif struct_type == 'ht':
|
||||
for name in search_existing + search_nonexist:
|
||||
ht_find(head, name)
|
||||
else:
|
||||
for name in search_existing + search_nonexist:
|
||||
bst_find(root, name)
|
||||
search_time = time.perf_counter() - start
|
||||
results.append((rep + 1, 'search', search_time))
|
||||
start = time.perf_counter()
|
||||
|
||||
start = time.perf_counter()
|
||||
if struct_type == 'll':
|
||||
for name in delete_names:
|
||||
head = ll_delete(head, name)
|
||||
elif struct_type == 'ht':
|
||||
for name in delete_names:
|
||||
ht_delete(head, name)
|
||||
else:
|
||||
for name in delete_names:
|
||||
root = bst_delete(root, name)
|
||||
delete_time = time.perf_counter() - start
|
||||
results.append((rep + 1, 'delete', delete_time))
|
||||
return results
|
||||
build_structure(records, struct_type)
|
||||
|
||||
end = time.perf_counter()
|
||||
|
||||
return end - start
|
||||
|
||||
|
||||
# ============================================================
|
||||
# SEARCH
|
||||
# ============================================================
|
||||
|
||||
def measure_search(records, struct_type):
|
||||
|
||||
structure = build_structure(records, struct_type)
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
if struct_type == "ll":
|
||||
for name in search_existing + search_nonexist:
|
||||
ll_find(structure, name)
|
||||
|
||||
elif struct_type == "ht":
|
||||
for name in search_existing + search_nonexist:
|
||||
ht_find(structure, name)
|
||||
|
||||
elif struct_type == "bst":
|
||||
for name in search_existing + search_nonexist:
|
||||
bst_find(structure, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
|
||||
return end - start
|
||||
|
||||
|
||||
# ============================================================
|
||||
# DELETE
|
||||
# ============================================================
|
||||
|
||||
def measure_delete(records, struct_type):
|
||||
|
||||
structure = build_structure(records, struct_type)
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
if struct_type == "ll":
|
||||
for name in delete_names:
|
||||
structure = ll_delete(structure, name)
|
||||
|
||||
elif struct_type == "ht":
|
||||
for name in delete_names:
|
||||
ht_delete(structure, name)
|
||||
|
||||
elif struct_type == "bst":
|
||||
for name in delete_names:
|
||||
structure = bst_delete(structure, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
|
||||
return end - start
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ЗАМЕРЫ
|
||||
# ============================================================
|
||||
|
||||
all_data = []
|
||||
|
||||
for struct_name, mode_label, records in [
|
||||
("LinkedList", "shuffled", records_shuffled),
|
||||
("LinkedList", "sorted", records_sorted),
|
||||
("HashTable", "shuffled", records_shuffled),
|
||||
("HashTable", "sorted", records_sorted),
|
||||
("BST", "shuffled", records_shuffled),
|
||||
("BST", "sorted", records_sorted),
|
||||
]:
|
||||
for rep, op, t in measure_operations(records, struct_name.split('d')[0].lower()[:2] if 'Linked' in struct_name else ('ht' if 'Hash' in struct_name else 'bst')):
|
||||
all_data.append([struct_name, mode_label, op, f"{t:.6f}"])
|
||||
experiments = [
|
||||
("LinkedList", "ll"),
|
||||
("HashTable", "ht"),
|
||||
("BST", "bst")
|
||||
]
|
||||
|
||||
modes = [
|
||||
("shuffled", records_shuffled),
|
||||
("sorted", records_sorted)
|
||||
]
|
||||
|
||||
for struct_name, struct_type in experiments:
|
||||
|
||||
for mode_name, records in modes:
|
||||
|
||||
for rep in range(1, 4):
|
||||
|
||||
insert_time = measure_insert(records, struct_type)
|
||||
|
||||
search_time = measure_search(records, struct_type)
|
||||
|
||||
delete_time = measure_delete(records, struct_type)
|
||||
|
||||
all_data.append([
|
||||
struct_name,
|
||||
mode_name,
|
||||
rep,
|
||||
"insert",
|
||||
insert_time
|
||||
])
|
||||
|
||||
all_data.append([
|
||||
struct_name,
|
||||
mode_name,
|
||||
rep,
|
||||
"search",
|
||||
search_time
|
||||
])
|
||||
|
||||
all_data.append([
|
||||
struct_name,
|
||||
mode_name,
|
||||
rep,
|
||||
"delete",
|
||||
delete_time
|
||||
])
|
||||
|
||||
# ============================================================
|
||||
# CSV
|
||||
# ============================================================
|
||||
|
||||
with open(csv_path, "w", newline="", encoding="utf-8") as f:
|
||||
|
||||
with open(csv_path, 'w', newline='', encoding='utf-8') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["Структура", "Режим", "Операция", "Время (сек)"])
|
||||
|
||||
writer.writerow([
|
||||
"Структура",
|
||||
"Режим",
|
||||
"Повтор",
|
||||
"Операция",
|
||||
"Время (сек)"
|
||||
])
|
||||
|
||||
writer.writerows(all_data)
|
||||
|
||||
print("CSV сохранён в docs/data/results.csv")
|
||||
print(f"CSV сохранён: {csv_path}")
|
||||
|
||||
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
# ============================================================
|
||||
# ГРАФИК
|
||||
# ============================================================
|
||||
|
||||
df = pd.read_csv(csv_path)
|
||||
|
||||
df_avg = df.groupby(['Структура', 'Режим', 'Операция'])['Время (сек)'].mean().reset_index()
|
||||
df_avg = (
|
||||
df.groupby(
|
||||
["Структура", "Режим", "Операция"]
|
||||
)["Время (сек)"]
|
||||
.mean()
|
||||
.reset_index()
|
||||
)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(12, 6))
|
||||
|
||||
ops = ["insert", "search", "delete"]
|
||||
|
||||
fig, ax = plt.subplots(figsize=(10,6))
|
||||
ops = ['insert', 'search', 'delete']
|
||||
x = range(len(ops))
|
||||
|
||||
width = 0.12
|
||||
|
||||
for i, (struct, mode) in enumerate([('LinkedList','shuffled'),('LinkedList','sorted'),
|
||||
('HashTable','shuffled'),('HashTable','sorted'),
|
||||
('BST','shuffled'),('BST','sorted')]):
|
||||
subset = df_avg[(df_avg['Структура']==struct) & (df_avg['Режим']==mode)]
|
||||
times = [subset[subset['Операция']==op]['Время (сек)'].values[0] for op in ops]
|
||||
ax.bar([p + i*width for p in x], times, width, label=f"{struct} ({mode})")
|
||||
configs = [
|
||||
("LinkedList", "shuffled"),
|
||||
("LinkedList", "sorted"),
|
||||
("HashTable", "shuffled"),
|
||||
("HashTable", "sorted"),
|
||||
("BST", "shuffled"),
|
||||
("BST", "sorted")
|
||||
]
|
||||
|
||||
for i, (struct, mode) in enumerate(configs):
|
||||
|
||||
subset = df_avg[
|
||||
(df_avg["Структура"] == struct)
|
||||
&
|
||||
(df_avg["Режим"] == mode)
|
||||
]
|
||||
|
||||
times = [
|
||||
subset[
|
||||
subset["Операция"] == op
|
||||
]["Время (сек)"].values[0]
|
||||
for op in ops
|
||||
]
|
||||
|
||||
ax.bar(
|
||||
[p + i * width for p in x],
|
||||
times,
|
||||
width,
|
||||
label=f"{struct} ({mode})"
|
||||
)
|
||||
|
||||
ax.set_xticks([p + 2.5 * width for p in x])
|
||||
|
||||
ax.set_xticks([p + 2.5*width for p in x])
|
||||
ax.set_xticklabels(ops)
|
||||
ax.set_ylabel('Среднее время (сек)')
|
||||
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
|
||||
|
||||
ax.set_ylabel("Среднее время (сек)")
|
||||
|
||||
ax.set_title("Сравнение структур данных")
|
||||
|
||||
ax.legend(
|
||||
bbox_to_anchor=(1.05, 1),
|
||||
loc="upper left"
|
||||
)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig('C:/Users/xalva/2026-rff_mp/stepinim/docs/data/grafik.png')
|
||||
|
||||
plt.savefig(graph_path)
|
||||
|
||||
print(f"График сохранён: {graph_path}")
|
||||
|
||||
plt.show()
|
||||
BIN
stepinim/lab2_oop/docs/data/chart_time_2lab.png
Normal file
BIN
stepinim/lab2_oop/docs/data/chart_time_2lab.png
Normal file
Binary file not shown.
20
stepinim/lab2_oop/docs/data/empty_2lab.txt
Normal file
20
stepinim/lab2_oop/docs/data/empty_2lab.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
S
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
E
|
||||
100
stepinim/lab2_oop/docs/data/large_2lab.txt
Normal file
100
stepinim/lab2_oop/docs/data/large_2lab.txt
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
####################################################################################################
|
||||
#S # # ### ## ## # # ### # # ## # # ### ## #### # ## ## # #####
|
||||
# # # # ## ## # # # # # # # # # ##### # ## # # ## # ## # #
|
||||
## # ## ### ## #### ## # # # ## #### # ## #### ## ### # # # ## # # ## #
|
||||
### # ## ## ### # # #### # # # # ## ## ###### ## ## # # ### # ###
|
||||
## # # # ### # # ## ### ### # # ## # # # ## # # ####### # #
|
||||
###### ### ## # # # # # # ### ### ## ### ### ##### # # ## # # ## ## ####
|
||||
#### # ## # # ## # ## ## ## # ## # # ## ## # # # # ## ###
|
||||
# # # # # ###### # # ## #### # # # ## # # ### ##### ## # #
|
||||
# ### # # # # ## ### # # ## #### # # # ###### # # ###### # ## #
|
||||
## ## ## ### # # ### # # ## # ## ### ### ## ## # ### # # #
|
||||
## # ## # # ## # ### # ## # ### ## # ### ### ### # ## ## # ### # # #
|
||||
# # # # # ### # ## # # # ## # # # # # # # # # # ### ## # # ## # # #
|
||||
## # # # #### ## # # # # # # ### # # ##### # # # # # # # # #
|
||||
# ## ## # ## # # #### # # ## #### # ## # # # # # # # # #
|
||||
# # ### # # # ## # # # # ## ## # # # # ## # # # # ## ## #### # ## # # #
|
||||
# # ### # # ## # ## #### #### ## # #### # ### ## # # # # ## ## #
|
||||
##### # # # # # ## # ## # ### # # # # # # # # # # ### ## # ## ## #### # # #
|
||||
# # # #### ## ## ## # # # # # # # # # ## # # ## # ### # # ## # # # ##
|
||||
### # ### ####### ### # # # # # ## ## # ## # ## # ## ###
|
||||
# # ### ######## ### ## # # # # # # ## ## # ## ### # # # ### ### ###
|
||||
# # ## ## # # ### ### ## # # ## # # # # # ## ## ### # # #### #### ###
|
||||
# ### ## ### #### # ## # # ## # ## # ## ### # # # # ### # ## ###
|
||||
#### ## # ### # # ## ### ## # # # # # # # ## # ## ## # # # # ## ## #
|
||||
### ## # # #### ## ## ##### ## # # # ## # ## # # # # # # # # ## # ## # #
|
||||
# # # # # # # ## ## # ### # ## ## # ## # # # ## # # ## ## # # # # ## #
|
||||
# # ###### # # # # # # # # ## ## # # # ## # # # # # # ## # # ## # # ##
|
||||
# # # # # ## # # # # # # # # ## # ## # #### # ### #### ## # # ## ##
|
||||
## # # ## # ### # #### ## # ### ## # # # # ### # ## # # # # #
|
||||
# # ### # ### # ## # ## ## # # # ### ##### ## ### # ## ### # # # ## ###### #
|
||||
## # # # ## # # #### # # ## # ## # # # # # # # # # # # # #
|
||||
## # # # ## #### # ### ### ## # ## ##### # # # # # # # # # # ##### # # ##
|
||||
# ## ## # # # # ### ## # # ### ### ## # # # # ## # # ## ### # # # ###
|
||||
# ## ## ## ### # # #### # ## ## ## ### ### # # ## ##
|
||||
## # # ##### #### # # ## ## ### # # # # # # # # # # ### # #### #
|
||||
# # # # # # #### # # ## # # # ## # # # # # # # ### # # ##
|
||||
## ### ## ### # ## ## ### # ## # # # # # # # # # # #### ## ##
|
||||
## # ### ## ## # # ### # # #### # # # ### # # # # # # #### # #
|
||||
# # # ## ### # # # # # # ## ## # # ## ## # ## # # # # ### ## # #
|
||||
# ### # ### ## # # # # # # ## # ###### # ## ## ## # ## ## ## # ## # #
|
||||
# # # # # ## # # # # # # ## # # # ###### # # ### # #
|
||||
# # ## # # ## # # ## ### # ## ## ## # # # # # # # # # ## # # #
|
||||
## #### ## ### #### # # ### # # # # # ## # ## # # ##### ## ## # # ## #
|
||||
## # # # ## # ## # # ## # #### # # ### # #### # ## # ##### # # # #
|
||||
# # # # # ## #### # # ## # # # # ## # ## ## # # # ## # # ## ## ### # #
|
||||
# # # ## # ## # # ## ## # ## # # ## # ## # # # ##### #
|
||||
## #### ## ##### # ### # ### # # ## # ## # # # # # # # ## # ### # ## #
|
||||
# # # # # ## # ## # ## ## # # ### # ####### # # ## # ### ## ## ## ## ## #
|
||||
### ## # ## ## # ## # ### ### # ### # # # ###### ### ### # # # ## ### # #
|
||||
## # ## ## # ## ### # # # # ## # ### # ### ## # ## # # # # #
|
||||
# # ## ## ## # # # # ## # # ## # ## # # # ## # # # # # # # # ## # # #
|
||||
# # # ## # ## ## ## #### ## ## ## ### ##### ###### ## ### # # #
|
||||
# # ## # # # # ## # # # # # ## # #### ## # ## # ### # ## #
|
||||
# # ## # # # ### # # # # ## ### ## # ## # # # # # ## # # # ### ## # #
|
||||
# ## # # # ## # # # # # ## # # # # ## # # # # ###### ## ### # #
|
||||
# ## ## # ### # # ## ####### ## # ####### # # # # ## # ### # ## # # #
|
||||
## ### ## ### # ## # # ## ### # ### ### # # # ## # # ## # ### # #
|
||||
# # # ### ## # # ## # ## ## # ### # # # ### ###### # # # #
|
||||
## # ### ## # ### ## ## # ## # ## ## ### ## ### ### ## ## # ## #
|
||||
# # #### ## # # ## ## # #### # ### # ## ## # # # # # ## # #
|
||||
# # # # #### # # # ### ## # ## ## ## # # ## # ##### # # # # # ## # #### # # #
|
||||
# # ### # # ## #### # # # # ## ## # ## ## ### # ## ## ## # ## #
|
||||
## # ## # # # # # ## ## # ## ## ## # ## # #### ## # ## #
|
||||
# # # ## # ## # # # # ### # # ## ## # # # # # ### # ### ## # # ## #
|
||||
# # # ### # # ## ## # # ## # ### # # ### # ## # ### # ## ## ## # #
|
||||
### # ## # # #### ### ## # ## # ## # ## #### # # ###### # # #### # ## #
|
||||
# # # # # # ### # # # # ## #### ### # # # # # ## # # # #### # #### # #
|
||||
## ## # ## # # # # # ## # ### #### # ## ### # ##### ### ## ### # # #
|
||||
# # # ####### ## ### # ####### # # # ####### # # # ### # # ## # # # #
|
||||
## # # ## ## ## # ### ## ## ### ## ## # # ## # ## ## # # # # #
|
||||
### # # #### ### # # ## # ## # # # #### # # # # # # # # ## # ## #
|
||||
# ##### # ## ### ## #### # # # ## #### # # # # ## # # ## # #
|
||||
# # # # # ### # ## #### # # # ### # # # # ## # # # # # # #
|
||||
# # ## ## #### # # ### ## ## ### ### ## ## # # # # # ## # ## ### #
|
||||
## # # ## # # ## # ## # ### # ### # # # ## # ### #### # ## #
|
||||
# ## # # # # ## ## # # # # ## # ### ## ###### ### # ## ### # # # # # #
|
||||
### # # # # #### # # # # ### ##### # ## # ## # # ## # # # ## #
|
||||
# # # # ##### # # #### # # # ## # ## # # ## ### # # ## # #### #
|
||||
### ## # # # ## # # ## # # ## # # # ### ## ## # ### # # ## # # # # #
|
||||
#### # # # # ## # # # ## ### # # # ### # ## # # ## # # # ## # #
|
||||
# # # ## # ## # # ## ### # ## ## # ## # ## ## # # # ## # # ### ## ## ## #
|
||||
# # # ## # # # ## # ## ## # ## # ## ## #### #### # ## # # #
|
||||
## # # #### ### ## # #### ### ### # ## # # ## ## # ## # ### #
|
||||
# ## ##### # # ## ### ### # # # # ### #### ## ## ## ## ### ## # #
|
||||
# # ## # ## ## # # ### # # # # ## # ### ## ## ## ## ## # # # #
|
||||
# #### # # #### # ## ### ###### # # # ## # # # # # # # # # #### ## # # # #
|
||||
# #### # ### ##### # ## ## # # ## ## # ## ## # ## ### # # # # # # #
|
||||
# # ## # # # ## # # ## ## # # # # ## # # # ## ### # ## # #
|
||||
### # ## # # # ## # # # #### ##### # # ## # ## # # # # ### # #
|
||||
# # # # ### # ## # # # # ## # # # ### # ## # # # # # # # # # # # #
|
||||
## # # # # ## ## # #### ## # # ## # # # # # ### # # # #### # # ## ## # # #
|
||||
## # # ## # #### # # # # ## # ### ## ## #### # ## ## # ## ## #### ## ### #### #
|
||||
# ### ### ### # ### ### ## # # # ###### # # ### ## # # # # # # # #
|
||||
## ### ## # ## # ## # ## ### # # # #### ### ### # #
|
||||
# # ## # # # ## ## # # # # ### ### # ### ### # # # # ### ## # #
|
||||
## # ## # # # # ###### ## ### # ### # # # ## # ## ## # ### # # # ## # ## #
|
||||
# ## # ## # # # ## ## # ## ## ## # ## # ## # # # # ## # # # #
|
||||
# ### # ## ## # #### # ##### # ## ## ## ### # # # # ### #
|
||||
## # ## # # # # ##### # ## # # # ## # ### # # # ## # ## # # # ## E#
|
||||
####################################################################################################
|
||||
50
stepinim/lab2_oop/docs/data/medium_2lab.txt
Normal file
50
stepinim/lab2_oop/docs/data/medium_2lab.txt
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
##################################################
|
||||
#S ## ### # # # #### # ## #
|
||||
# # ## # # # # ##### ### # ### # #
|
||||
# ## #### # ### ### ## # # #### ### # # #
|
||||
#### # # # # # ## # ####
|
||||
# ## # #### ## # # ## # # # #
|
||||
# ### # # # # ### # ##
|
||||
# # # # ## # # ## # ## # # #
|
||||
## # # # #### # # # # # ### ##
|
||||
## # # ## ## ### # # ## #
|
||||
## # # # # # # # # # # # # #
|
||||
# # ## # ## ## ## ## ## # ###
|
||||
# ### # # # ## ## # # # # ## # ##
|
||||
## # # # # ## # # # # #
|
||||
# # # # # ### # ### # # ##
|
||||
# # # # # # # ##### # ### ##
|
||||
# # # # ## ## # # # # ### #### #
|
||||
## # # # ## # # ## # ### ## ### # #
|
||||
## # ## # # # # #
|
||||
# ##### ## ## # # # ## # ## # # #
|
||||
# # # # ### ##### ### # # ## #
|
||||
## # # # ## # # ## # # # # ## #
|
||||
#### # # ## # # # ## ## # ## ## #
|
||||
# # ### ### ## # ## #### # #
|
||||
# # ### # ## ##### # # # # ## # #
|
||||
## #### # # # # # #
|
||||
# ## # # # # ## ## # # ## # #
|
||||
# # ## # ### # ### ## # ## #
|
||||
# # # # # ## ## ## # #
|
||||
# # ## ### ## ## # # # # # ## # #
|
||||
## # # #### # #### # ## ## # ## #
|
||||
# # # ## # # # # # # # # #
|
||||
# ### ### # # # # # # # #
|
||||
# ## # # # ####### # # # # # # ### #
|
||||
## # # # # # # # # # ## # ## #
|
||||
# # # # ## ## # # ## ### # # # # # # #
|
||||
# ## # ### # # # # # # # #
|
||||
# # # # # # # ## # ### # #
|
||||
# # ### # # # ### # ## # # #
|
||||
# ### # # # # ## # # ## # #
|
||||
# ## # ### # ## ## ### # # # #
|
||||
# ## # # ## ## # # # ## # #
|
||||
# # ## # # # # # # # # ## #
|
||||
## # # # # # # # # # # # #
|
||||
# # # # ### ## ### # ## # # # #
|
||||
## ##### # # # ## # ## ### # #
|
||||
# ## # ## ##### # # # ## #
|
||||
# # # # # # ### # # # # # #
|
||||
### # # # # # # ## ## ### ## #E#
|
||||
##################################################
|
||||
15
stepinim/lab2_oop/docs/data/no_exit_2lab.txt
Normal file
15
stepinim/lab2_oop/docs/data/no_exit_2lab.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
###############
|
||||
#S # #
|
||||
# #
|
||||
## # #
|
||||
# # # #
|
||||
## ## # # # #
|
||||
# # # #
|
||||
# # #
|
||||
# # # ## #
|
||||
## # # #
|
||||
## #
|
||||
## # # # #
|
||||
# # # ##
|
||||
# # #E#
|
||||
###############
|
||||
21
stepinim/lab2_oop/docs/data/results_2lab.csv
Normal file
21
stepinim/lab2_oop/docs/data/results_2lab.csv
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
maze,strategy,time_ms,visited,path_length
|
||||
small,BFS,0.1971,28,15
|
||||
small,DFS,0.062,16,15
|
||||
small,A*,0.1713,28,15
|
||||
small,Dijkstra,0.148,28,15
|
||||
medium,BFS,5.3354,1377,95
|
||||
medium,DFS,0.7772,282,151
|
||||
medium,A*,3.8703,500,95
|
||||
medium,Dijkstra,8.3548,1363,95
|
||||
large,BFS,16.9817,4391,195
|
||||
large,DFS,3.414,614,285
|
||||
large,A*,5.7519,559,195
|
||||
large,Dijkstra,31.018,4380,195
|
||||
empty,BFS,2.3012,400,39
|
||||
empty,DFS,1.4237,400,191
|
||||
empty,A*,3.6105,400,39
|
||||
empty,Dijkstra,2.9606,400,39
|
||||
no_exit,BFS,0.5791,136,0
|
||||
no_exit,DFS,0.5479,136,0
|
||||
no_exit,A*,0.9933,136,0
|
||||
no_exit,Dijkstra,0.8121,136,0
|
||||
|
Gitea Version: 1.22.0 |
