Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upChanges data type from set to list for correct return result #1816
Conversation
|
I added a new graph, so the test needs to be fixed accordingly. |
| @@ -31,13 +34,12 @@ def bfs(graph, start): | |||
| >>> ''.join(sorted(bfs(G, 'A'))) | |||
| 'ABCDEF' | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cclauss
Mar 27, 2020
Member
I added a new graph, so the test function needs to be fixed accordingly because currently it returns ABCDEFGHI not ABECFIHGD. This is why Travis CI is failing this pull request. Either the test must be fixed to match the function output or the function must be fixed to match the test's expected result. They must agree for this pull request to be considered.
This comment has been minimized.
This comment has been minimized.
cclauss
Mar 27, 2020
Member
Python sets are defined to be an unordered collection with no duplicate elements. This means that they should not be used if the order of elements is important.
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.
b0r1sp commentedMar 26, 2020
•
edited
It seems, saving 'explored' in a set returns wrong results. During traversal, the order of the entries in var 'explored' are changed by python (by version 2 AND 3).
Result during iteration with data type 'set':
For comparison, here's the result with data type 'list':
The result is for the old example-graph essentially the same, but for more complex graphs it will be wrong.
I added a slightly more complex graph:
Here's the wrong result with data type 'set' - note how the order changes:
What should be the result? (order of vertices on every level does not matter)
Level 0: A
Level 1: B,C,E
Level 2: F,I,H
Level 3: G,D
If you take a close look above, e.g. D is returned on the wrong level.
Here's the correct result with data type 'list':
I suggest to include the more complex graph for testing purposes.