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.
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.
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.
Remove comments, rename variables better.
|
|
||
| """ | ||
|
|
||
| test_graph_1 = { |
There was a problem hiding this comment.
@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.
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 | ||
|
|
| n = len(graph) | ||
|
|
||
| visited = n * [False] |
There was a problem hiding this comment.
| 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}.