Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e02209fb-63d5-47fd-83bd-b36e5c9349d5</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>TA_Lab2_Sperkach_Anna_IS_01.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>TA_Lab2_Sperkach_Anna_IS-01</Name>
<RootNamespace>TA_Lab2_Sperkach_Anna_IS-01</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="call.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="TA_Lab2_Sperkach_Anna_IS_01.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "TA_Lab2_Sperkach_Anna_IS-01", "TA_Lab2_Sperkach_Anna_IS-01.pyproj", "{E02209FB-63D5-47FD-83BD-B36E5C9349D5}"
EndProject
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "minimum", "..\minimum\minimum.pyproj", "{D1A42009-002B-45BD-9885-4E89B34F8DBB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E02209FB-63D5-47FD-83BD-B36E5C9349D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E02209FB-63D5-47FD-83BD-B36E5C9349D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1A42009-002B-45BD-9885-4E89B34F8DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1A42009-002B-45BD-9885-4E89B34F8DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {690E8806-05B2-43C1-8524-479AD6307BC1}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import numpy as np
import random
from call import plot_data

sizes = [10, 100, 1000]
#sizes = [10]
#sizes = [100]
#sizes = [1000]

types = ["random", "best", "worst"]
data_plot = {'random': {'bubble':{}, 'insertion':{}, 'bubble_impr':{}},
'best': {'bubble':{}, 'insertion':{}, 'bubble_impr':{}},
'worst': {'bubble':{}, 'insertion':{}, 'bubble_impr':{}}}


def generate_data(n, gen_typ="random"):

if gen_type=="best":
a = [i+1 for i in range(n)]
return a
elif gen_type=="worst":
a = [i+1 for i in reversed(range(n))]
return a
else:
a = [i+1 for i in range(n)]
random.shuffle(a)
return a


def bubble_sort(arr):
#print(arr)
counter=0
for i in range(len(arr)-1):
for j in range(0, len(arr)-1):
counter+=1
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
#print (arr)
return counter

def bubble_impr_sort(arr):
counter =0
#print (arr)
swapped = True
endOfList = len(arr)-1
while swapped:
swapped = False
for i in range(endOfList):
counter += 1
if arr[i] >= arr[i+1]:
arr[i],arr[i+1] = arr[i+1],arr[i]
swapped = True
endOfList-=1
#print (arr)
return counter

def insertion_sort(arr):
counter = 0
for i in range(1,len(arr)):
key = arr[i]
j = i-1
while j>=0 and arr[j] > key:
counter +=1
arr[j+1] = arr[j]
j -= 1
arr[j+1] = key
counter += 1
print (arr)

min(arr)
print ("\tМинимальный элемент в insertion sort:", min(arr))
return counter




for n in sizes:
print ("\nDATA SIZE: ", n)

for gen_type in types:
print( "\n\tDATA TYPE:", gen_type)
data = generate_data(n, gen_type)

data_bubble = np.copy(data)
bubble_op_count = bubble_sort(data_bubble)
print ("\tBubble sort Кол-во сравнений:", int(bubble_op_count))
data_plot[gen_type]['bubble'][n] = bubble_op_count

data_bubble_impr = np.copy(data)
bubble_impr_op_count = bubble_impr_sort(data_bubble_impr)
print ("\tImproved bubble sort Кол-во сравнений:", int(bubble_impr_op_count))
data_plot[gen_type]['bubble_impr'][n] = bubble_impr_op_count

data_insertion = np.copy(data)
insertion_op_count = insertion_sort(data_insertion)
print ("\tInsertion sort Кол-во сравнений:", int(insertion_op_count))
data_plot[gen_type]['insertion'][n] = insertion_op_count


#Побудова графіків швидкодії алгоритмів
plot_data(data_plot, logarithmic=True, oneplot=True)

Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions 2Lab_TA-master/TA_Lab2_Sperkach_Anna_IS-01/call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import collections
import matplotlib.pyplot as plt
import numpy as np
from pylab import figure, show
from math import log

def plot_data(data, logarithmic=False, oneplot=False):
#print(data)
fig = figure(1)
num = len(data)
colors = ['y','b','r']
markers = ['o','s','x']
lines = ['-','--',':']

if oneplot==True:
ax = fig.add_subplot(111)
ax.grid(True)
i = -1
line_titles = []
x_max = y_max = 0
for label, value in data.items():
i += 1
j = -1
for sort_type, points in value.items():
j += 1
od_points = collections.OrderedDict(sorted(points.items()))
if logarithmic:
xs = [(x>0 and log(x,10) or 0) for x in od_points.keys()]
ys = [(y>0 and log(y,10) or 0) for y in od_points.values()]
else:
xs = od_points.keys()
ys = od_points.values()
xs.insert(0,0)
x_max = max(x_max, max(xs))
ys.insert(0,0)
y_max = max(y_max, max(ys))
ax.plot(xs, ys, colors[j%num]+markers[j%num]+lines[i%num], label=sort_type )
line_titles.append(sort_type+' '+label)
ax.set_xlim( (0, x_max*1.1) )
ax.set_ylim( (0, y_max*1.1) )
ax.legend(line_titles, loc=4)
else:
i = 0
for label, value in data.items():
i += 1
ax = fig.add_subplot(num,1,i)
ax.grid(True)
ax.set_title(label)
j = -1
x_max = y_max = 0
for sort_type, points in value.items():
j += 1
od_points = collections.OrderedDict(sorted(points.items()))
if logarithmic:
xs = [log(x,10) for x in od_points.keys()]
ys = [log(y,10) for y in od_points.values()]
else:
xs = od_points.keys()
ys = od_points.values()
xs.insert(0,0)
x_max = max(x_max, max(xs))
ys.insert(0,0)
y_max = max(y_max, max(ys))
ax.plot(xs, ys, colors[j%num]+markers[j%num]+'-', label=sort_type )
ax.set_xlim( (0, x_max*1.1) )
ax.set_ylim( (0, y_max*1.1) )
ax.legend(loc=4)
show()
57 changes: 57 additions & 0 deletions 3Lab_TA_2sem-master/TA_3Lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import numpy as np
from merge_sort import SortAndCountInversitions
from merge_sort import MergeAndCountSplitInversitions
from merge_sort import AllUsersSort
from merge_sort import ResultSort


def InPut(): #include the input
f=open("input.txt")
lst = []
for row in f:
strs = row.split(' ')
for s in strs:
if s != ' ':
lst = lst +[int(s)]
AllUsers = int(lst[0]);
AllFilms = int(lst[1]);
array = np.zeros((AllUsers, AllFilms), dtype=int)
t = 2
for i in range (AllUsers):
num = int(lst[t]);
t+=1
for j in range(AllFilms):
array[i][j] = lst[t]
t+=1
f.close()
return (AllUsers, AllFilms, array)

def OutPut(result, User, AllUsers):
f = open("output.txt", 'wt')
User +=1
s = str(User) + '\n'
f.write(s)
for i in range(1, AllUsers):
s1= str(result[i][0])
s2= str(result[i][1])
f.write(s1 +' ' + s2 +'\n')



AllUsers, AllFilms, array = InPut()
User = int(input("Choose the User to be compared:"))
User -=1;
array = AllUsersSort(array, User, AllUsers, AllFilms);
result = np.zeros((AllUsers, 2), dtype=int);
t=0;
for i in range(AllUsers):
if i != User:
t+=1
result[t][0]=i+1
massive = array[i]
A, result[t][1] = SortAndCountInversitions(list(massive))
result = ResultSort(result, AllUsers)
OutPut(result, User, AllUsers)



23 changes: 23 additions & 0 deletions 3Lab_TA_2sem-master/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
22 7
1 1 2 3 4 5 6 7
2 1 2 3 4 5 7 6
3 1 2 3 4 6 7 5
4 1 2 3 4 7 6 5
5 1 2 3 5 7 6 4
6 1 2 3 6 7 5 4
7 1 2 3 7 6 5 4
8 1 2 4 7 6 5 3
9 1 2 5 7 6 4 3
10 1 2 6 7 5 4 3
11 1 2 7 6 5 4 3
12 1 3 7 6 5 4 2
13 1 4 7 6 5 3 2
14 1 5 7 6 4 3 2
15 1 6 7 5 4 3 2
16 1 7 6 5 4 3 2
17 2 7 6 5 4 3 1
18 3 7 6 5 4 2 1
19 4 7 6 5 3 2 1
20 5 7 6 4 3 2 1
21 6 7 5 4 3 2 1
22 7 6 5 4 3 2 1
50 changes: 50 additions & 0 deletions 3Lab_TA_2sem-master/merge_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import numpy as np

def SortAndCountInversitions(A): #inversion calculation procedure
AllUsers =len(A)
if AllUsers == 1:
return (A, 0)
else:
Left= A[:int(len(A)/2)]
Right= A[int(len(A)/2):]
Left, x = SortAndCountInversitions(Left)
Right, y = SortAndCountInversitions(Right)
A, z = MergeAndCountSplitInversitions(A, Left, Right)
return (A, x + y + z)


def MergeAndCountSplitInversitions(A, Left, Right): #using the method of merge sort and count the split inversitions
counter=0 #split inversion counter
n1= len(Left)
n2 = len(Right)
i=0
j=0
lst=[]
while i< n1 and j< n2:
if Left[i] <= Right[j]:
lst.append(Left[i]) #then go to the end of the list
i += 1
else:
lst.append(Right[j])
j += 1
counter += (n1 -i)
lst= lst + Left[i:]
lst= lst + Right[j:]
return lst, counter;

def ResultSort(result, AllUsers): #sort the massive with result
for i in range(AllUsers-1):
for j in range(0, AllUsers-1):
if result[j][1] > result[j+1][1] :
result[j][1], result[j+1][1] = result[j+1][1], result[j][1]
result[j][0], result[j+1][0] = result[j+1][0], result[j][0]
return result


def AllUsersSort(array, User, AllUsers, AllFilms): #sort the massive with AllUsers
for i in range(AllFilms-1):
for j in range(0, AllFilms-1):
if array[User][j] > array[User][j+1] :
for t in range(AllUsers):
array[t][j], array[t][j+1] = array[t][j+1], array[t][j]
return array
Loading