forked from UNN/2026-rff_mp
[4] lab_1 otchet + experiment data + graphics
This commit is contained in:
parent
9ab957e484
commit
44b3b4938b
|
|
@ -1,165 +0,0 @@
|
|||
#LinkedListPhoneBook
|
||||
|
||||
head = None #!!!!!!!!!!!!!!
|
||||
|
||||
print("\nLinked list\n")
|
||||
|
||||
def ll_insert(head, name, phone):
|
||||
|
||||
curr = head
|
||||
|
||||
while curr is not None:
|
||||
if curr['name'] == name:
|
||||
curr['phone'] = phone
|
||||
return head
|
||||
elif curr['next'] == None:
|
||||
curr['next'] = {'name' : name, 'phone' : phone, 'next' : None}
|
||||
return head
|
||||
curr = curr['next']
|
||||
|
||||
return {'name' : name, 'phone' : phone, 'next' : None}
|
||||
|
||||
|
||||
test_names = ['Andrey', 'Ivan', 'Andrey', 'Igor', 'Nagibator3000', 'Sberbank','Loshped']
|
||||
test_phones = ['7-234-246','6-352-095','5-257-098','1-374-098','9-387-098','5-135-357','0-000-000']
|
||||
|
||||
print("\nll_insert test\n")
|
||||
|
||||
for i in range(len(test_names)):
|
||||
head = ll_insert(head, test_names[i], test_phones[i])
|
||||
print(head)
|
||||
|
||||
print("\ntest end\n\n")
|
||||
|
||||
def ll_find(head, name):
|
||||
|
||||
curr = head
|
||||
while curr is not None:
|
||||
if curr['name'] == name:
|
||||
return curr['phone']
|
||||
curr = curr['next']
|
||||
|
||||
return None
|
||||
|
||||
print('ll_find test\n')
|
||||
|
||||
test_names = ["Ivan", "Andrey", "Sberbank", "Nagibator3000","Ermola"]
|
||||
|
||||
for name in test_names:
|
||||
print(ll_find(head, name))
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
|
||||
def ll_delete(head, name):
|
||||
|
||||
if head is not None:
|
||||
|
||||
if head['name'] == name:
|
||||
return head['next']
|
||||
|
||||
old_curr = head
|
||||
curr = head['next']
|
||||
|
||||
while curr is not None:
|
||||
if curr['name'] == name:
|
||||
old_curr['next'] = curr['next']
|
||||
break
|
||||
old_curr, curr = curr, curr['next']
|
||||
|
||||
return head
|
||||
|
||||
print('ll_delete test\n')
|
||||
|
||||
test_names = ['Nagibator3000','Nagibator3000','Loshped','Ermola']
|
||||
|
||||
for name in test_names:
|
||||
head = ll_delete(head, name)
|
||||
print(head)
|
||||
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
|
||||
def ll_list_all(head):
|
||||
|
||||
res = []
|
||||
curr = head
|
||||
|
||||
while curr is not None:
|
||||
res += [(curr['name'],curr['phone'])]
|
||||
curr = curr['next']
|
||||
|
||||
return sorted(res)
|
||||
|
||||
print('ll_list_all test\n')
|
||||
|
||||
print(ll_list_all(head))
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
|
||||
|
||||
|
||||
print("\nHash Table\n")
|
||||
|
||||
size = 8
|
||||
buckets = [None] * size
|
||||
|
||||
def index(name,size):
|
||||
return hash(name) % size
|
||||
|
||||
def ht_insert(buckets, name, phone):
|
||||
ind = index(name, size)
|
||||
buckets[ind] = ll_insert(buckets[ind], name, phone)
|
||||
|
||||
def ht_find(buckets, name):
|
||||
ind = index(name, size)
|
||||
return ll_find(buckets[ind], name)
|
||||
|
||||
def ht_delete(buckets, name):
|
||||
ind = index(name, size)
|
||||
buckets[ind] = ll_delete(buckets[ind], name)
|
||||
|
||||
def ht_list_all(buckets):
|
||||
res = []
|
||||
for head in buckets:
|
||||
curr = head
|
||||
while curr is not None:
|
||||
res += [(curr['name'],curr['phone'])]
|
||||
curr = curr['next']
|
||||
return sorted(res)
|
||||
|
||||
test_names = ['Andrey', 'Ivan', 'Andrey', 'Igor', 'Nagibator3000', 'Sberbank','Loshped']
|
||||
test_phones = ['7-234-246','6-352-095','5-257-098','1-374-098','9-387-098','5-135-357','0-000-000']
|
||||
|
||||
print("\nht_insert test\n")
|
||||
|
||||
print(buckets)
|
||||
for i in range(len(test_names)):
|
||||
ht_insert(buckets, test_names[i], test_phones[i])
|
||||
print(buckets)
|
||||
|
||||
print("\ntest end\n\n")
|
||||
|
||||
print("ht_find test\n")
|
||||
|
||||
test_names = ["Ivan", "Andrey", "Sberbank", "Nagibator3000","Ermola"]
|
||||
|
||||
for name in test_names:
|
||||
print(ht_find(buckets, name))
|
||||
|
||||
print("\ntest end\n\n")
|
||||
|
||||
print('ht_delete test\n')
|
||||
|
||||
test_names = ['Nagibator3000','Nagibator3000','Loshped','Ermola']
|
||||
|
||||
for name in test_names:
|
||||
ht_delete(buckets, name)
|
||||
print(buckets)
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
|
||||
print('ht_list_all test\n')
|
||||
|
||||
print(ht_list_all(buckets))
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
57
GutovVM/docs/data/lab_1_data/graphics1-1.py
Normal file
57
GutovVM/docs/data/lab_1_data/graphics1-1.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#Графики
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
data = []
|
||||
|
||||
with open('results.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
|
||||
print(data)
|
||||
|
||||
types = ["shuffled","sorted"]
|
||||
algorythms = ['Linked list','Hash-table','BST']
|
||||
operations = ['Insert','Find','Delete']
|
||||
for dt in types:
|
||||
|
||||
for ot in operations:
|
||||
|
||||
X = algorythms
|
||||
Y = [0.,0.,0.]
|
||||
|
||||
for row in data:
|
||||
if row[1] == dt and row[2] == ot:
|
||||
if row[0] == X[0]:
|
||||
Y[0] = float(row[3])
|
||||
elif row[0] == X[1]:
|
||||
Y[1] = float(row[3])
|
||||
elif row[0] == X[2]:
|
||||
Y[2] = float(row[3])
|
||||
|
||||
plt.bar(X,Y)
|
||||
plt.title(dt + ot)
|
||||
plt.ylabel('Время')
|
||||
plt.show()
|
||||
|
||||
for dt in types:
|
||||
|
||||
for at in algorythms:
|
||||
|
||||
X = operations
|
||||
Y = [0.,0.,0.]
|
||||
|
||||
for row in data:
|
||||
if row[1] == dt and row[0] == at:
|
||||
if row[2] == X[0]:
|
||||
Y[0] = float(row[3])
|
||||
elif row[2] == X[1]:
|
||||
Y[1] = float(row[3])
|
||||
elif row[2] == X[2]:
|
||||
Y[2] = float(row[3])
|
||||
|
||||
plt.bar(X,Y,color='g')
|
||||
plt.title(dt + at)
|
||||
plt.ylabel('Время')
|
||||
plt.show()
|
||||
58
GutovVM/docs/data/lab_1_data/graphics1-2.py
Normal file
58
GutovVM/docs/data/lab_1_data/graphics1-2.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#Графики через ln
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
data = []
|
||||
|
||||
with open('results.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
|
||||
print(data)
|
||||
|
||||
types = ["shuffled","sorted"]
|
||||
algorythms = ['Linked list','Hash-table','BST']
|
||||
operations = ['Insert','Find','Delete']
|
||||
for dt in types:
|
||||
|
||||
for ot in operations:
|
||||
|
||||
X = algorythms
|
||||
Y = [0.,0.,0.]
|
||||
|
||||
for row in data:
|
||||
if row[1] == dt and row[2] == ot:
|
||||
if row[0] == X[0]:
|
||||
Y[0] = np.log(float(row[3]))
|
||||
elif row[0] == X[1]:
|
||||
Y[1] = np.log(float(row[3]))
|
||||
elif row[0] == X[2]:
|
||||
Y[2] = np.log(float(row[3]))
|
||||
|
||||
plt.bar(X,Y)
|
||||
plt.title(dt + ot)
|
||||
plt.ylabel('Время')
|
||||
plt.show()
|
||||
|
||||
for dt in types:
|
||||
|
||||
for at in algorythms:
|
||||
|
||||
X = operations
|
||||
Y = [0.,0.,0.]
|
||||
|
||||
for row in data:
|
||||
if row[1] == dt and row[0] == at:
|
||||
if row[2] == X[0]:
|
||||
Y[0] = np.log(float(row[3]))
|
||||
elif row[2] == X[1]:
|
||||
Y[1] = np.log(float(row[3]))
|
||||
elif row[2] == X[2]:
|
||||
Y[2] = np.log(float(row[3]))
|
||||
|
||||
plt.bar(X,Y,color='g')
|
||||
plt.title(dt + at)
|
||||
plt.ylabel('Время')
|
||||
plt.show()
|
||||
176
GutovVM/docs/data/lab_1_data/log.txt
Normal file
176
GutovVM/docs/data/lab_1_data/log.txt
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
Данный файл был создан в ручную копированием данных выводимых программой main при последнем запуске.
|
||||
|
||||
Linked list
|
||||
|
||||
|
||||
ll_insert test
|
||||
|
||||
{'name': 'Andrey', 'phone': '7-234-246', 'next': None}
|
||||
{'name': 'Andrey', 'phone': '7-234-246', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': None}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': None}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': None}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': None}}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}}}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': {'name': 'Loshped', 'phone': '0-000-000', 'next': None}}}}}}
|
||||
|
||||
test end
|
||||
|
||||
|
||||
ll_find test
|
||||
|
||||
6-352-095
|
||||
5-257-098
|
||||
5-135-357
|
||||
9-387-098
|
||||
None
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
ll_delete test
|
||||
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': {'name': 'Loshped', 'phone': '0-000-000', 'next': None}}}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': {'name': 'Loshped', 'phone': '0-000-000', 'next': None}}}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}}}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'next': {'name': 'Ivan', 'phone': '6-352-095', 'next': {'name': 'Igor', 'phone': '1-374-098', 'next': {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}}}}
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
ll_list_all test
|
||||
|
||||
[('Andrey', '5-257-098'), ('Igor', '1-374-098'), ('Ivan', '6-352-095'), ('Sberbank', '5-135-357')]
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
|
||||
Hash Table
|
||||
|
||||
|
||||
ht_insert test
|
||||
|
||||
[None, None, None, None, None, None, None, None]
|
||||
[{'name': 'Andrey', 'phone': '7-234-246', 'next': None}, None, None, None, None, None, None, None]
|
||||
[{'name': 'Andrey', 'phone': '7-234-246', 'next': None}, None, None, None, None, None, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, None]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, None, None, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, None]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, None, None, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': None}, None, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': None}, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, {'name': 'Loshped', 'phone': '0-000-000', 'next': None}, None, None, {'name': 'Nagibator3000', 'phone': '9-387-098', 'next': None}, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
|
||||
test end
|
||||
|
||||
|
||||
ht_find test
|
||||
|
||||
6-352-095
|
||||
5-257-098
|
||||
5-135-357
|
||||
9-387-098
|
||||
None
|
||||
|
||||
test end
|
||||
|
||||
|
||||
ht_delete test
|
||||
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, {'name': 'Loshped', 'phone': '0-000-000', 'next': None}, None, None, None, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, {'name': 'Loshped', 'phone': '0-000-000', 'next': None}, None, None, None, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, None, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
[{'name': 'Andrey', 'phone': '5-257-098', 'next': None}, None, None, None, None, {'name': 'Sberbank', 'phone': '5-135-357', 'next': None}, {'name': 'Ivan', 'phone': '6-352-095', 'next': None}, {'name': 'Igor', 'phone': '1-374-098', 'next': None}]
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
ht_list_all test
|
||||
|
||||
[('Andrey', '5-257-098'), ('Igor', '1-374-098'), ('Ivan', '6-352-095'), ('Sberbank', '5-135-357')]
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
|
||||
bst_insert test
|
||||
|
||||
None
|
||||
{'name': 'Andrey', 'phone': '7-234-246', 'left': None, 'right': None}
|
||||
{'name': 'Andrey', 'phone': '7-234-246', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': None, 'right': None}, 'right': None}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': None, 'right': None}, 'right': None}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': None, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': None, 'right': None}}, 'right': None}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': None, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': None, 'right': None}}, 'right': {'name': 'Nagibator3000', 'phone': '9-387-098', 'left': None, 'right': None}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': None, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}, 'right': {'name': 'Nagibator3000', 'phone': '9-387-098', 'left': None, 'right': None}}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': {'name': 'Loshped', 'phone': '0-000-000', 'left': None, 'right': None}, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}, 'right': {'name': 'Nagibator3000', 'phone': '9-387-098', 'left': None, 'right': None}}
|
||||
|
||||
test end
|
||||
|
||||
|
||||
bst_find test
|
||||
|
||||
6-352-095
|
||||
5-257-098
|
||||
5-135-357
|
||||
9-387-098
|
||||
None
|
||||
|
||||
test end
|
||||
|
||||
|
||||
bst_delete test
|
||||
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': {'name': 'Loshped', 'phone': '0-000-000', 'left': None, 'right': None}, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}, 'right': None}
|
||||
{'name': 'Andrey', 'phone': '5-257-098', 'left': {'name': 'Ivan', 'phone': '6-352-095', 'left': {'name': 'Loshped', 'phone': '0-000-000', 'left': None, 'right': None}, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}, 'right': None}
|
||||
{'name': 'Ivan', 'phone': '6-352-095', 'left': {'name': 'Loshped', 'phone': '0-000-000', 'left': None, 'right': None}, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}
|
||||
{'name': 'Ivan', 'phone': '6-352-095', 'left': {'name': 'Loshped', 'phone': '0-000-000', 'left': None, 'right': None}, 'right': {'name': 'Igor', 'phone': '1-374-098', 'left': {'name': 'Sberbank', 'phone': '5-135-357', 'left': None, 'right': None}, 'right': None}}
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
bst_list_all test
|
||||
|
||||
[('Loshped', '0-000-000'), ('Ivan', '6-352-095'), ('Sberbank', '5-135-357'), ('Igor', '1-374-098')]
|
||||
|
||||
test_end
|
||||
|
||||
|
||||
Итерация 1
|
||||
Время Связного Списка: 2.9917209999402985 0.02659020002465695 0.012590099941007793
|
||||
Время Хеш-таблицы: 0.005119499983265996 3.9100064896047115e-05 2.0299921743571758e-05
|
||||
Время Двоичного Дерева Поиска: 0.09058830002322793 0.00027840002439916134 0.00014549994375556707
|
||||
Итерация 2
|
||||
Время Связного Списка: 2.903203699970618 0.023054099990986288 0.010875999927520752
|
||||
Время Хеш-таблицы: 0.00455170008353889 3.400002606213093e-05 1.9400031305849552e-05
|
||||
Время Двоичного Дерева Поиска: 0.03216309996787459 0.00027810002211481333 0.00014749995898455381
|
||||
Итерация 3
|
||||
Время Связного Списка: 2.921877200016752 0.025615100050345063 0.01236239995341748
|
||||
Время Хеш-таблицы: 0.00479620008263737 3.529991954565048e-05 2.0200037397444248e-05
|
||||
Время Двоичного Дерева Поиска: 0.03450970002450049 0.0004401999758556485 0.00016369996592402458
|
||||
Итерация 4
|
||||
Время Связного Списка: 3.003447199938819 0.02533069998025894 0.010745699983090162
|
||||
Время Хеш-таблицы: 0.004474699962884188 3.350002225488424e-05 1.8000020645558834e-05
|
||||
Время Двоичного Дерева Поиска: 0.07804860000032932 0.00027279998175799847 0.00014109991025179625
|
||||
Итерация 5
|
||||
Время Связного Списка: 2.9807132000569254 0.0290351000148803 0.013929600012488663
|
||||
Время Хеш-таблицы: 0.005072099971584976 5.009991582483053e-05 2.2300053387880325e-05
|
||||
Время Двоичного Дерева Поиска: 0.03607590007595718 0.0003352999920025468 0.00016259995754808187
|
||||
Итерация 1
|
||||
Время Связного Списка: 2.5927454999182373 0.02170580008532852 0.010246100020594895
|
||||
Время Хеш-таблицы: 0.00436040002387017 3.50000336766243e-05 1.8999911844730377e-05
|
||||
Время Двоичного Дерева Поиска: 0.029087499948218465 0.0003063000040128827 0.00015670002903789282
|
||||
Итерация 2
|
||||
Время Связного Списка: 2.5688632000237703 0.02236179995816201 0.00998460000846535
|
||||
Время Хеш-таблицы: 0.004271199926733971 3.3100019209086895e-05 1.7400016076862812e-05
|
||||
Время Двоичного Дерева Поиска: 0.03174210002180189 0.000283299945294857 0.00013529998250305653
|
||||
Итерация 3
|
||||
Время Связного Списка: 2.6008588999975473 0.019859899999573827 0.010582599905319512
|
||||
Время Хеш-таблицы: 0.00447160005569458 3.23000131174922e-05 1.810002140700817e-05
|
||||
Время Двоичного Дерева Поиска: 0.03173729998525232 0.0002880999818444252 0.0001452000578865409
|
||||
Итерация 4
|
||||
Время Связного Списка: 2.5892133000306785 0.022096000029705465 0.010453099966980517
|
||||
Время Хеш-таблицы: 0.004718700074590743 3.42000275850296e-05 1.7300015315413475e-05
|
||||
Время Двоичного Дерева Поиска: 0.033104100031778216 0.0002930999035015702 0.00015160010661929846
|
||||
Итерация 5
|
||||
Время Связного Списка: 2.5684097999474034 0.020924199954606593 0.009929200052283704
|
||||
Время Хеш-таблицы: 0.0046051000244915485 3.370002377778292e-05 1.8400023691356182e-05
|
||||
Время Двоичного Дерева Поиска: 0.03069589997176081 0.0003073000116273761 0.00014600006397813559
|
||||
[['Linked list', 'shuffled', 'Insert', '2.9601924599846825'], ['Linked list', 'shuffled', 'Find', '0.02592504001222551'], ['Linked list', 'shuffled', 'Delete', '0.01210075996350497'], ['Hash-table', 'shuffled', 'Insert', '0.004802840016782284'], ['Hash-table', 'shuffled', 'Find', '3.839998971670866e-05'], ['Hash-table', 'shuffled', 'Delete', '2.0040012896060943e-05'], ['BST', 'shuffled', 'Insert', '0.0542771200183779'], ['BST', 'shuffled', 'Find', '0.0003209599992260337'], ['BST', 'shuffled', 'Delete', '0.00015207994729280472'], ['Linked list', 'sorted', 'Insert', '2.5840181399835274'], ['Linked list', 'sorted', 'Find', '0.021389540005475282'], ['Linked list', 'sorted', 'Delete', '0.010239119990728796'], ['Hash-table', 'sorted', 'Insert', '0.004485400021076202'], ['Hash-table', 'sorted', 'Find', '3.3660023473203185e-05'], ['Hash-table', 'sorted', 'Delete', '1.8039997667074203e-05'], ['BST', 'sorted', 'Insert', '0.03127337999176234'], ['BST', 'sorted', 'Find', '0.00029561996925622227'], ['BST', 'sorted', 'Delete', '0.00014696004800498485']]
|
||||
|
|
@ -207,39 +207,28 @@ def bst_find(root, name):
|
|||
def bst_delete(root, name):
|
||||
|
||||
if root is None:
|
||||
return None
|
||||
elif name == root['name']:
|
||||
curr = root['left']
|
||||
if curr is not None:
|
||||
oldcurr = root
|
||||
while curr['right'] is not None:
|
||||
oldcurr,curr = curr,curr['right']
|
||||
|
||||
if oldcurr == root:
|
||||
root['left'] = curr['left']
|
||||
|
||||
else:
|
||||
oldcurr['right'] = curr['right']
|
||||
|
||||
curr['left'],curr['right'] = root['left'],root['right']
|
||||
return curr
|
||||
|
||||
curr = root['right']
|
||||
if curr is not None:
|
||||
oldcurr = root
|
||||
while curr['left'] is not None:
|
||||
oldcurr,curr = curr,curr['left']
|
||||
|
||||
if oldcurr == root:
|
||||
root['right'] = curr['right']
|
||||
|
||||
else:
|
||||
oldcurr['left'] = curr['left']
|
||||
|
||||
curr['left'],curr['right'] = root['left'],root['right']
|
||||
return curr
|
||||
|
||||
return None
|
||||
elif name == root['name']:
|
||||
|
||||
if root['left'] is None and root['right'] is None:
|
||||
return None
|
||||
elif root['left'] is not None and root['right'] is None:
|
||||
return root['left']
|
||||
elif root['right'] is not None and root['left'] is None:
|
||||
return root['right']
|
||||
|
||||
curr = root['left']
|
||||
oldcurr = root
|
||||
while curr['right'] is not None:
|
||||
oldcurr,curr = curr,curr['right']
|
||||
|
||||
if oldcurr == root:
|
||||
root['left'] = curr['left']
|
||||
else:
|
||||
oldcurr['right'] = curr['left']
|
||||
|
||||
curr['left'],curr['right'] = root['left'],root['right']
|
||||
return curr
|
||||
|
||||
elif hash(name) < hash(root['name']):
|
||||
root['left'] = bst_delete(root['left'],name)
|
||||
|
|
@ -292,4 +281,169 @@ print('bst_list_all test\n')
|
|||
|
||||
print(bst_list_all(root))
|
||||
|
||||
print('\ntest_end\n\n')
|
||||
print('\ntest_end\n\n')
|
||||
|
||||
|
||||
|
||||
###ЭКСПЕРЕМЕНТАЛЬНАЯ ЧАСТЬ
|
||||
|
||||
#1 Генерация
|
||||
|
||||
import random
|
||||
|
||||
records_shuffled = []
|
||||
records_sorted = []
|
||||
|
||||
N = 10000
|
||||
|
||||
for i in range(1,N+1):
|
||||
number = str(random.randint(1,9)) + '-' + str(random.randint(100,999)) + '-' + str(random.randint(100,999)) + '-' + str(random.randint(10,99)) + '-' + str(random.randint(10,99))
|
||||
records_sorted += [(f"User_{i:05d}", number)]
|
||||
|
||||
records_shuffled = records_sorted[:] #срезал чтобы не ссылка была
|
||||
random.shuffle(records_shuffled)
|
||||
|
||||
#2 Инструменты замера времени
|
||||
|
||||
import time
|
||||
|
||||
#start = time.perf_counter()
|
||||
# ... операции ...
|
||||
#end = time.perf_counter()
|
||||
#elapsed = end - start # время в секундах
|
||||
|
||||
results = []
|
||||
types = ["shuffled","sorted"]
|
||||
for dt in range(2):
|
||||
data = (records_shuffled, records_sorted)[dt]
|
||||
time_res_sum = [0]*9
|
||||
for iteration in range(5):
|
||||
names = [x for x,_ in data]
|
||||
test_names = random.sample(names, 150)
|
||||
|
||||
find_names = test_names[0:100]
|
||||
find_names += [f"None_{i}" for i in range(10)]
|
||||
|
||||
delete_names = test_names[100:150]
|
||||
|
||||
#LinkedList
|
||||
time_res = []
|
||||
|
||||
head = None
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for a in data:
|
||||
head = ll_insert(head, a[0], a[1])
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in find_names:
|
||||
ll_find(head, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in delete_names:
|
||||
head = ll_delete(head, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
#HashTable
|
||||
size = 15013 #простое число от которого 10000 - это примерно 0.7 (коэффициент заполнения)
|
||||
buckets = [None] * size
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for a in data:
|
||||
buckets = ht_insert(buckets, a[0], a[1])
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in find_names:
|
||||
ht_find(buckets, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in delete_names:
|
||||
buckets = ht_delete(buckets, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
#BinarySearchTree
|
||||
root = None
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for a in data:
|
||||
root = bst_insert(root, a[0], a[1])
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in find_names:
|
||||
bst_find(root, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
for name in delete_names:
|
||||
root = bst_delete(root, name)
|
||||
|
||||
end = time.perf_counter()
|
||||
time_res.append(end - start)
|
||||
|
||||
print("Итерация ", iteration+1)
|
||||
print("Время Связного Списка: ", time_res[0], time_res[1], time_res[2])
|
||||
print("Время Хеш-таблицы: ", time_res[3], time_res[4], time_res[5])
|
||||
print("Время Двоичного Дерева Поиска: ", time_res[6], time_res[7], time_res[8])
|
||||
|
||||
for i in range(9):
|
||||
time_res_sum[i] += time_res[i]
|
||||
|
||||
for i in range(9):
|
||||
time_res_sum[i] /= 5
|
||||
|
||||
results.append(["Linked list", types[dt], "Insert",str(time_res_sum[0])])
|
||||
results.append(["Linked list", types[dt], "Find",str(time_res_sum[1])])
|
||||
results.append(["Linked list", types[dt], "Delete",str(time_res_sum[2])])
|
||||
results.append(["Hash-table", types[dt], "Insert",str(time_res_sum[3])])
|
||||
results.append(["Hash-table", types[dt], "Find",str(time_res_sum[4])])
|
||||
results.append(["Hash-table", types[dt], "Delete",str(time_res_sum[5])])
|
||||
results.append(["BST", types[dt], "Insert",str(time_res_sum[6])])
|
||||
results.append(["BST", types[dt], "Find",str(time_res_sum[7])])
|
||||
results.append(["BST", types[dt], "Delete",str(time_res_sum[8])])
|
||||
|
||||
print(results)
|
||||
|
||||
import csv
|
||||
|
||||
with open("results.csv", "w", newline="") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerows(results)
|
||||
18
GutovVM/docs/data/lab_1_data/results.csv
Normal file
18
GutovVM/docs/data/lab_1_data/results.csv
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Linked list,shuffled,Insert,2.9601924599846825
|
||||
Linked list,shuffled,Find,0.02592504001222551
|
||||
Linked list,shuffled,Delete,0.01210075996350497
|
||||
Hash-table,shuffled,Insert,0.004802840016782284
|
||||
Hash-table,shuffled,Find,3.839998971670866e-05
|
||||
Hash-table,shuffled,Delete,2.0040012896060943e-05
|
||||
BST,shuffled,Insert,0.0542771200183779
|
||||
BST,shuffled,Find,0.0003209599992260337
|
||||
BST,shuffled,Delete,0.00015207994729280472
|
||||
Linked list,sorted,Insert,2.5840181399835274
|
||||
Linked list,sorted,Find,0.021389540005475282
|
||||
Linked list,sorted,Delete,0.010239119990728796
|
||||
Hash-table,sorted,Insert,0.004485400021076202
|
||||
Hash-table,sorted,Find,3.3660023473203185e-05
|
||||
Hash-table,sorted,Delete,1.8039997667074203e-05
|
||||
BST,sorted,Insert,0.03127337999176234
|
||||
BST,sorted,Find,0.00029561996925622227
|
||||
BST,sorted,Delete,0.00014696004800498485
|
||||
|
BIN
GutovVM/docs/otchet1.docx
Normal file
BIN
GutovVM/docs/otchet1.docx
Normal file
Binary file not shown.
BIN
GutovVM/docs/~$tchet1.docx
Normal file
BIN
GutovVM/docs/~$tchet1.docx
Normal file
Binary file not shown.
0
GutovVM/docs/~WRL3973.tmp
Normal file
0
GutovVM/docs/~WRL3973.tmp
Normal file
Loading…
Reference in New Issue
Block a user