Skip to content

Reduce the complexity of graphs/minimum_spanning_tree_prims.py #7952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MaximSmolskiy
Copy link
Member

@MaximSmolskiy MaximSmolskiy commented Nov 2, 2022

Describe your change:

Reduce the complexity of graphs/minimum_spanning_tree_prims.py from 21 to 7

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Nov 2, 2022
Comment on lines 88 to 91
visited = [0 for i in range(len(adjacency_list))]
nbr_tv = [
-1 for i in range(len(adjacency_list))
] # Neighboring Tree Vertex of selected vertex
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
visited = [0 for i in range(len(adjacency_list))]
nbr_tv = [
-1 for i in range(len(adjacency_list))
] # Neighboring Tree Vertex of selected vertex
visited = [0] * len(adjacency_list)
nbr_tv = [-1] * len(adjacency_list) # Neighboring Tree Vertex of selected vertex

Comment on lines 128 to 129
n = int(input("Enter number of vertices: ").strip())
e = int(input("Enter number of edges: ").strip())
Copy link
Member

Choose a reason for hiding this comment

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

Do we gather this data and then not use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, n wasn't used, but e is used

Comment on lines 128 to 129
n = int(input("Enter number of vertices: ").strip())
e = int(input("Enter number of edges: ").strip())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
n = int(input("Enter number of vertices: ").strip())
e = int(input("Enter number of edges: ").strip())
n = int(input("Enter number of vertices: ").strip())
number_of_edges = int(input("Enter number of edges: ").strip())

@MaximSmolskiy MaximSmolskiy requested review from cclauss and removed request for dhruvmanila November 2, 2022 20:58
Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

MUCH more readable! Thanks for doing this.

Are you ready to merge this?

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Nov 2, 2022
@MaximSmolskiy
Copy link
Member Author

MUCH more readable! Thanks for doing this.

Are you ready to merge this?

Yes

@cclauss cclauss merged commit a02de96 into TheAlgorithms:master Nov 2, 2022
@MaximSmolskiy MaximSmolskiy deleted the reduce-the-complexity-of-graphs/minimum_spanning_tree_prims.py branch November 2, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants