Skip to content

Created Kruskal's algo file - #47

Open
EricBrianAnil wants to merge 1 commit into
codesankalp:masterfrom
EricBrianAnil:patch-1
Open

Created Kruskal's algo file#47
EricBrianAnil wants to merge 1 commit into
codesankalp:masterfrom
EricBrianAnil:patch-1

Conversation

@EricBrianAnil

@EricBrianAnil EricBrianAnil commented Sep 30, 2020

Copy link
Copy Markdown

Kruskal's algorithm for an MST implemented in python 3.7. closes #28

Kruskal's algorithm for an MST implemented in python 3.7
@codesankalp

Copy link
Copy Markdown
Owner

@EricBrianAnil to get your pull request reviewed or to be valid. Please link this pull request to the issue.

@EricBrianAnil

Copy link
Copy Markdown
Author

@EricBrianAnil to get your pull request reviewed or to be valid. Please link this pull request to the issue.

I've linked the pull request to the issue, #28

Comment thread dsalgo/kruskals.py
Comment on lines +62 to +83
def main() :

# Edge(source, destination, weight)
num_nodes = int(input("Enter the number of nodes : "))
edges=[]
for i in range(num_nodes):
s=int(input("Enter the source: "))
d=int(input("Enter the destination: "))
w=int(input("Enter the weight: "))
edges.append(Edge(s,d,w))

g = Graph(num_nodes, edges)
g.KruskalMST()


if __name__ == "__main__" :
main()



""" Sample Output : Edges of minimum spanning tree are in Graph 1 : [0-2](1) [3-4](1) [1-3](2) [2-3](2) [1-5](3)
Cost of minimum spanning tree : 9 """

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EricBrianAnil you should not add driver code here. Add them in tests directory

Comment thread dsalgo/kruskals.py
@@ -0,0 +1,83 @@
# Kruskal's algorithm for Minimum Spanning Tree in Python

from dataclasses import dataclass, field

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aryamanz29 Is this library required?

@Aryamanz29 Aryamanz29 Oct 6, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devkapilbansal no, Firstly he should create a graph using class then define Kruskal's algo() inside it. Library needed for this task is collections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Kruskal’s Minimum Spanning Tree Algorithm

4 participants