-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Strongly connected components #2114
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
Strongly connected components #2114
Conversation
Hey @nikalosa, TravisCI finished with status TravisBuddy Request Identifier: 631e3d40-ae34-11ea-b5ce-3bd953fd8c80 |
…kalosa/Python into strongly-connected-components
Please fix also flake8 errors: https://travis-ci.com/github/TheAlgorithms/Python/builds/171253892 |
…kalosa/Python into strongly-connected-components
That error has already fixed after the first commit. |
""" | ||
|
||
n = len(graph) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graph_size
could be more readable instead n
|
||
# describe reversed graph (All edges reversed) | ||
reverse_graph = {vert: [] for vert in range(n)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse_graph
--> reversed_graph
. I think comment above is unnecessary. Variable name defines exactly what is it.
components_list = [] | ||
# reinitialize visited list | ||
visited = n * [False] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments, rename variables better.
|
||
""" | ||
|
||
test_graph_1 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss Do you have any idea how we can avoid declaring these variables here but keep current doctests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are OK here. Naming helps a lot so when I see test_graph_1
, I immediately know that this data is for testing purposes. If I was going to move this algorithm to some larger program, I will need to do some level of refactoring. I might move all the doctests and the test data to a separate test_xyz.py file or I might remove them altogether. For our purposes in this repo, a single file that contains the algorithm, tests, and test data is good for learning purposes as long as we are diligent with our naming.
""" | ||
|
||
visited[vert] = True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n = len(graph) | ||
|
||
visited = n * [False] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n = len(graph) | |
visited = n * [False] | |
visited = len(graph) * [False] |
Hey @nikalosa, TravisCI finished with status TravisBuddy Request Identifier: b99b17b0-b09b-11ea-b9a3-b9754cbad7e4 |
Co-authored-by: Christian Clauss <cclauss@me.com>
* Implement strongly connected components for graph algorithms * fixup! Format Python code with psf/black push * Delete trailing whitespace * updating DIRECTORY.md * Add doctests and typehints * Remove unnecessary comments, change variable names * fixup! Format Python code with psf/black push * Change undefined variable's name * Apply suggestions from code review Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Algorithm for finding out strongly connected components in a graph
Checklist:
Fixes: #{$ISSUE_NO}
.