Created Kruskal's algo file - #47
Open
EricBrianAnil wants to merge 1 commit into
Open
Conversation
Kruskal's algorithm for an MST implemented in python 3.7
Owner
|
@EricBrianAnil to get your pull request reviewed or to be valid. Please link this pull request to the issue. |
Author
I've linked the pull request to the issue, #28 |
devkapilbansal
requested changes
Oct 1, 2020
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 """ |
Collaborator
There was a problem hiding this comment.
@EricBrianAnil you should not add driver code here. Add them in tests directory
| @@ -0,0 +1,83 @@ | |||
| # Kruskal's algorithm for Minimum Spanning Tree in Python | |||
|
|
|||
| from dataclasses import dataclass, field | |||
Collaborator
There was a problem hiding this comment.
@devkapilbansal no, Firstly he should create a graph using class then define Kruskal's algo() inside it. Library needed for this task is collections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kruskal's algorithm for an MST implemented in python 3.7. closes #28