Skip to content

Commit ceb417c

Browse files
authored
Update with Prim's and Kruskal's MST
1 parent 206f01d commit ceb417c

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

README.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
### Description ###
44

55
The package aims to create visual outputs for popular graph algorithms.
6-
Currently: BFS and DFS
7-
I plan to implement more algorithms: Prim's and Kruskal's Algorithms etc
6+
Currently: BFS, DFS, Topological Sort, Prim's MST and Kruskal's MST
7+
I plan to implement more algorithms: A* Search etc
88

99
It is not just limited to getting a visual output, but the algorithms will be optimised by using heuristics for non-polynomial time algorithms. This project aims to create a better understanding of the working of graph algorithms, improve the computation time and optimising the algorithms. It could be used by analysts as well as students and teachers, as a teaching aid.
1010

@@ -14,16 +14,17 @@ To run the package: pip install graph-algo-vis
1414

1515
### BFS and DFS ###
1616
Import:
17-
from graph_algo_vis import dfs_traversal
17+
from graph_algo_vis import dfs_traversal, bfs_traversal
1818

1919
Instantiation:
20-
g = dfs_traversal.DFS()
20+
d = dfs_traversal.DFS()
21+
b = bfs_traversal.BFS()
2122

2223
Visualize the input graph:
23-
g.draw_graph("input.txt")
24+
d.draw_graph("input.txt")
2425

2526
Visualize the result of DFS:
26-
g.depth_first_search("input.txt")
27+
d.depth_first_search("input.txt")
2728

2829
### Topological Sort ###
2930
Import:
@@ -33,7 +34,19 @@ Instantiation:
3334
g = topological_sort.Top_Sort()
3435

3536
Visualize the input graph and result:
36-
g.topological_sort("input.txt")
37+
g.topological_sort("input.txt")
38+
39+
### Prim's and Kruskal's MST ###
40+
Import:
41+
from graph_algo_vis import primsMST, kruskalsMST
42+
43+
Instantiation:
44+
p = primsMST.Prims()
45+
k = kruskalsMST.Krusals()
46+
47+
Visualize the input graph and result:
48+
p.prims("input.txt")
49+
k.kruskals("input.txt")
3750

3851
### Pre requisites ###
3952

@@ -44,7 +57,7 @@ To run this package run you must have matplotlib and networkx libraries installe
4457
Input is taken from the file
4558
#### input.txt ####
4659

47-
Sample input for BFS and DFS
60+
Sample input for BFS, DFS, Prim's MST and Kruskal's MST
4861
```
4962
4
5063
0 5 10 5
@@ -102,12 +115,27 @@ Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for ever
102115
Green node - denotes the starting node.
103116
Red node - denotes the final node.
104117

105-
![3](https://i.ibb.co/Rz4qPMv/Graph-after-Topological-Sort.png)
118+
![3](https://i.ibb.co/Rz4qPMv/Graph-after-Topological-Sort.png)
119+
120+
### Prim's and Kruskal's MST ###
121+
122+
Prim's and Kruskal's algorithms are greedy algorithms that find a minimum spanning tree for
123+
a weighted, connected, undirected graph.
124+
125+
Minimum Spanning Tree (MST) : A spanning tree with a weight less than or equal to the weight of every other spanning tree. The weight of a spanning tree is the sum of weights given to each edge of the spanning tree.
126+
127+
The edges coloured in Red represent the edges included in the MST
128+
![4](https://i.ibb.co/CMQWgQ4/MST.png)
106129

107130
### Time Complexity ###
108131

132+
BFS, DFS, Topological Sort:
109133
0(m+n)
110134
where m - number of edges
111-
n - number of nodes
135+
n - number of nodes
136+
137+
Prim's and Kruskal's MST:
138+
O(V^2)
139+
where V - Number of vertices
112140

113141

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"License :: OSI Approved :: MIT License",
1212
"Operating System :: OS Independent"
1313
],
14-
version='0.2',
14+
version='0.3',
1515
extras_require = {
16-
"dev": ["networkx", "matplotlib",],
16+
"dev": ["networkx", "matplotlib"],
1717
},
1818
install_requires=[
1919
'networkx',
20-
'matplotlib',
20+
'matplotlib'
2121
],
22-
keywords = ['Graph', 'Algorithms', 'BFS', 'DFS', 'Topological Sort'],
22+
keywords = ['Graph', 'Algorithms', 'BFS', 'DFS', 'Topological Sort', "Prim's MST", "Kruskal's MST"],
2323
description='Visualize Graph Algorithms',
2424
packages=['graph_algo_vis'],
2525
author="Akrash Sharma",

0 commit comments

Comments
 (0)