Cs Proj Pdf_merged
Cs Proj Pdf_merged
Project Report
2024 - 2025
Name:
Standard:
Subject:
Reg. No.:
Title of the Project:
BONAFIDE CERTIFICATE
Date Teacher-in-charge
1 INTRODUCTION 2
2 OBJECTIVE 3
3 ALGORITHM 4
6 SYSTEM DESIGN 6
7 MODULES USED 13
8 SOURCE CODE 14
9 OUTPUT 24
10 FUTURE ENHANCEMENTS 30
11 CONCLUSION 31
12 BIBLIOGRAPHY 32
1
1. INTRODUCTION:
A minimum spanning tree is the subset of a graph where all the points in the given graph
is connected with minimum cost (path traversed). Finding the minimum distance
between multiple points has been a powerful tool in solving problems for the modern
era engineers since the 1930 when it was first published by Czech scientist Otakar
Borůvka for efficient power transmission across the city of Moarvia. More commonly
used alogirthms to solve such problems are Prim’s algorithm and Kruskal’s algorithm.
This project aims to solve problems with sparse graphs (3 to ~10⁶ points) hence we
Simpler to implement
The minimum spanning tree is built on python using kruskal’s algorithm helps in
Handwriting recognition
Cluster analysis
2
2. OBJECTIVE:
The ultimate motive behind this project is to allow people with any amount of
knowledge and experience with MST’s to access MST for solving real life problems in
The simple code used helps any one with data to find relationships in it, optimise their
solution for a specific problem, foster more interested into the beautiful and highly
It also aims towards solving complex engineering problems faced by people from all
3
3. ALGORITHM:
Kruskal's algorithm works to find the Minimum Spanning Tree (MST) of a graph by
1) Sort all edges: Arrange all the edges in non-decreasing order based on their
weights.
3) Select edges: Start from the smallest edge and check if they have dissimilar
parents,
4) Add edge if no cycle detected: If the edge does not form a cycle (i.e., they have
5) Repeat: Continue this process until the MST contains exactly (number of
6) Terminate: The algorithm terminates when all vertices are connected and there
The following process ensures that the MST has the least possible edge weight sum
4
4. MINIMUM HARDWARE SPECIFICATIONS:
Processor : Intel i3 – 6100 (2.7 GHz) / AMD Ryzen 3 1200 (3.1 GHz)
RAM : 10 GB (SSD/HDD)
5
6. SYSTEM DESIGN:
In this phase, a logical system is built which fulfils the given requirements. Design phase
logically working system. Normally, design is performed in the following two steps:
Here the system is designed at block level. The blocks are created on the basis of
analysis done in the problem identification phase. Different blocks are created for
different functions emphasis is put on minimising the information flow between blocks.
Thus, all activities which require more interaction are kept in one block.
The general tasks involved in the design process are the following:
System reviews.
6
Getting choice from user
7
For recieving number of points for random coordiantes
8
Recieving necessary run conditions from
user
9
A manual simulation of flow of air
through lungs.
10
An automatic random points run
11
Output in given file
12
7. MODULES USED:
copy : copy is used to form deep copy of list to count number of parents.
13
8. SOURCE CODE:
import copy
import time
import tkinter as tk
import random as rd
import math
import ast
GUI = tk.Tk()
GUI.attributes('-fullscreen', True)
f_name = 0
k = 0
next = 0
ch = 0
np = 0
o = 0
file = 0
k = True
canvas = None
oval_cords = []
dist_list = []
min_dist_order_list = []
visited = []
final_tree = []
no_of_points_box = 0
no_of_points_box_entry = 0
time_b_val = 0
mode_b_val = 0
branch_b_val = 0
no_pt = 0
timee = 0
mode = 0
branch = 0
total_cost = 0
f_name = 0
text = 0
def on_right_click(event):
GUI.quit()
GUI.bind("<Button-3>", on_right_click)
14
def create_canvas():
global canvas
canvas = tk.Canvas(GUI, bg='#E0FFFF', height=GUI.winfo_height()-50,
width=GUI.winfo_width())
canvas.grid(row=0, column=0, sticky='nsew')
return canvas
def random_cords():
global canvas, np
canvas = create_canvas()
canvas.update()
canvas_width = canvas.winfo_width()-10
canvas_height = canvas.winfo_height()-100
for i in range(np):
x = rd.randint(0, canvas_width-15)
y = rd.randint(0, canvas_height-100)
canvas.create_oval(x - 5, y - 5, x + 5, y + 5, fill='blue')
global oval_cords
oval_cords.append([str(i),[x,y]])
dist_lst_calc()
def get_np():
global np, no_of_points_box, no_of_points_box_entry
random_btn.destroy()
input_file_btn.destroy()
choice_label.destroy()
15
def np_calc():
global np, no_of_points_box, no_of_points_box_entry
np = no_of_points_box_entry.get()
np = int(np)
no_of_points_box.destroy()
no_of_points_box_entry.destroy()
method()
def dist_lst_calc():
global oval_cords, dist_list, min_dist_order_list, np
global timee, mode, branch
for j in range(np):
x1 = oval_cords[j][1][0]
y1 = oval_cords[j][1][1]
graph_lines_calc()
def method():
global time_b_val, mode_b_val, branch_b_val
w_msg.destroy()
if o == 1:
f_name.destroy()
k.destroy()
16
instructions = tk.Label(text =
''' **INSTRUCTIONS**:
------------
1. To run code in manual mode give mode as 1 and to run code in automatic mode give
mode as 0
2. Input the time between every code run in the *TIME* box. (For instant output and
manual mode give t as 0)
3. Enter the numbers of braches to connect at a time in the *BRANCH* box. (Branch
>0)
17
def method_sec():
global timee,mode,branch, canvas
global canvas, np, min_dist_order_list
timee = int(time_b_val.get())
mode = int(mode_b_val.get())
branch = int(branch_b_val.get())
if o == 0:
random_cords()
elif o == 1:
cords()
def sui():
global k, no_pt, np, next, ch, n
global visited, min_dist_order_list, oval_cords, canvas, final_tree , total_cost
n = 0
pseudo_lst = copy.deepcopy(visited)
while pseudo_lst != []:
c = pseudo_lst.pop()
if c[1] == -1:
n+=1
if mode == 0:
if len(min_dist_order_list) > 0:
pts = min_dist_order_list.pop(0)
from_pt = pts[1][0]
to_pt = pts[1][1]
if parent_1 != parent_2:
if timee != 0:
GUI.update()
time.sleep(timee)
visited[parent_2][1] = parent_1
final_tree.append(pts)
total_cost += pts[0]
18
for p in oval_cords:
if int(p[0]) == from_pt:
x1 = p[1][0]
y1 = p[1][1]
elif int(p[0]) == to_pt:
x2 = p[1][0]
y2 = p[1][1]
canvas.create_line(x1,y1,x2,y2,fill = 'blue')
no_pt += 1
else:
sui()
elif n == 1:
msg = tk.Label(text = 'MST constructed :)', font = ('Courier New',11),
fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)
else:
msg = tk.Label(text = 'MST constructed :)', font = ('Courier New',11),
fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)
elif mode == 1:
for t in range(branch):
if len(min_dist_order_list) > 0:
pts = min_dist_order_list.pop(0)
from_pt = pts[1][0]
to_pt = pts[1][1]
19
if parent_1 != parent_2:
if timee != 0:
GUI.update()
time.sleep(timee)
visited[parent_2][1] = parent_1
final_tree.append(pts)
total_cost += pts[0]
for p in oval_cords:
if int(p[0]) == from_pt:
x1 = p[1][0]
y1 = p[1][1]
elif int(p[0]) == to_pt:
x2 = p[1][0]
y2 = p[1][1]
canvas.create_line(x1,y1,x2,y2,fill = 'blue')
no_pt += 1
else:
sui()
else:
next.destroy()
msg = tk.Label(text = 'MST constructed :)', font = ('Courier
New',11), fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)
break
def data_to_file():
global file, text
ch.destroy()
text = tk.Button(text = 'Enter file path and press button: ', font = ('Courier
New',11), fg = 'white', bg = 'black',command = enter_data)
text.place(relx = 0, rely = 0.96)
20
def enter_data():
global file, total_cost
f = file.get()
fi.write('\n')
fi.write('Total cost' + str(total_cost))
file.destroy()
text.destroy()
def graph_lines_calc():
global k, n, no_pt
global min_dist_order_list, oval_cords, canvas, visited, next
global timee, mode, branch
if len(visited) <np:
for i in range(np):
visited.append([i,-1])
if mode == 0:
elif mode == 1:
def get_list():
global oval_cords, f_name, o
file = f_name.get()
f = open(file,'r')
oval_cords = f.read()
oval_cords = ast.literal_eval(oval_cords)
o = 1
method()
21
def get_file():
global f_name, k, f_name
random_btn.destroy()
input_file_btn.destroy()
choice_label.destroy()
def cords():
global oval_cords,canvas,np
canvas = create_canvas()
canvas.update()
canvas_width = canvas.winfo_width()
canvas_height = canvas.winfo_height()-100
pseudo_list = copy.deepcopy(oval_cords)
while len(pseudo_list) > 0:
cord = pseudo_list.pop(0)
x = cord[1][0]
y = cord[1][1]
i = cord[0]
canvas.create_oval(x - 5, y - 5, x + 5, y + 5, fill='blue')
canvas.create_text(x + 10, y - 10, text=str(np), fill="red", font=("Arial",
10))
np+=1
dist_lst_calc()
choice_label = tk.Label(text = 'Choose the way you want to use the program with:',
bg = 'black', fg = 'white', font = ('Courier New',15), relief =
'raised')
choice_label.place(relx = 0.3, rely = 0.4)
22
input_file_btn = tk.Button(text='2. Input coordinates via file', command= get_file ,
background= 'black', fg = 'white', font = ('Courier New',11),
relief = 'raised')
input_file_btn.place(anchor='se', relx=0.68, rely=0.5)
GUI.mainloop()
23
9. OUTPUT:
Simulation of air through human lungs (Coordinates from file):
24
25
26
27
Random Coordinates simulation:
28
29
10. FUTURE ENHANCMENTS:
Spanning Tree (MST), helping users better understand the cost of connection.
Make some modifications in the sui() function to join points under specific
Add support for weighted graphs where users can specify edge weights directly.
Implement graph drawing tools, enabling users to draw and interact with their
own graphs.
Provide options to export the MST as an image, CSV file, or in standard graph
30
11. CONCLUSION:
This Minimum Spanning Tree program is a solid starting point for anyone looking to
understand or work with MSTs. Whether you’re a student learning the basics or a
This isn’t just a tool for fun; it has real-world applications. From designing networks to
planning routes, finding an MST is something engineers and researchers deal with all
the time. The ability to save results is another practical touch, ensuring the data can be
That said, there’s still plenty of room for improvement. Adding more features like
support for different MST algorithms, better visualization, or the ability to work with
In short, this program has done a great job at being both educational and functional. It
simplifies a tricky mathematical concept and makes it easy to see it in action. With a
few enhancements in the future, it has the potential to become more visually interesting,
practical and useful for the user. It’s a reminder of how coding can take abstract ideas
31
BIBILIOGRAPHY:
References:
https://www.youtube.com/playlist?list=PLEJXowNB4kPzByLnnFYNSCoqtFz0
VKLk5
https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-
greedy-algo-2
https://stackoverflow.com/questions/58199612/how-to-display-a-complete-text-
in-tkinter-gui-in-python
www.chatgpt.com
https://personal.utdallas.edu/~besp/teaching/mst-applications.pdf
https://docs.python.org/3/library/tkinter.html
Books:
Computer science with Python Class XII, Sumita Arora, Dhanapat Rai and Co,
15th edition.
32