899c844c78
- Replaced std::set with std::vector for sequence handling. - Added randomization of sequences to avoid ordered input bias. - Removed unused balance function and related code in bst.cpp and bst.h. - Fixed bugs in list insertion and search logic. - Updated plot.py to allow custom y-axis labels and enable log scale for build plots.
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
import matplotlib.pyplot as plt
|
|
|
|
def plot(header:str, first:list[int], second:list[int], log=False, labels=("Lista", "Drzewo BST"), ylabel= "Czas (ms)"):
|
|
plt.figure(figsize=(10, 6))
|
|
plt.plot(range(1000,25001,1000), first, label=labels[0])
|
|
plt.plot(range(1000,25001,1000), second, label=labels[1])
|
|
plt.xlabel("Rozmiar tablicy")
|
|
plt.ylabel(ylabel)
|
|
if log:
|
|
plt.yscale('log', base=2)
|
|
plt.title(header)
|
|
plt.legend()
|
|
plt.savefig(f"./charts/{header}.png")
|
|
|
|
if __name__ == "__main__":
|
|
with open('results.csv', 'r') as file:
|
|
data = file.read()
|
|
lines = data.split('\n')
|
|
headers = lines[0].split(',')
|
|
values = [line.split(',') for line in lines[1:]]
|
|
|
|
bstTimes = {
|
|
"build":[],
|
|
"search":[],
|
|
"delete":[]
|
|
}
|
|
|
|
listTimes = {
|
|
"build":[],
|
|
"search":[],
|
|
"delete":[]
|
|
}
|
|
|
|
for row in values:
|
|
if row[0] == 'BST':
|
|
bstTimes['build'].append(float(row[1]))
|
|
bstTimes['search'].append(float(row[2]))
|
|
bstTimes['delete'].append(float(row[3]))
|
|
elif row[0] == 'List':
|
|
listTimes['build'].append(float(row[1]))
|
|
listTimes['search'].append(float(row[2]))
|
|
listTimes['delete'].append(float(row[3]))
|
|
|
|
|
|
plot("Tworzenie", listTimes['build'], bstTimes['build'], log=True)
|
|
plot("Wyszukiwanie", listTimes['search'], bstTimes['search'], log=True)
|
|
plot("Usuwanie", listTimes['delete'], bstTimes['delete'])
|
|
|
|
with open("avl.csv", "r") as file:
|
|
data = file.read()
|
|
lines = data.split('\n')
|
|
headers = lines[0].split(',')
|
|
values = [line.split(',') for line in lines[1:-1]]
|
|
|
|
bstHeights = [int(x[0]) for x in values]
|
|
avlHeights = [int(x[1]) for x in values]
|
|
|
|
plot("AVL", bstHeights, avlHeights, log=True, labels=("Drzewo BST", "Drzewo AVL"), ylabel="Wysokość drzewa")
|