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.
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
Topological Sorting #93
Topological Sorting #93
Changes from 36 commits
3fe9e21
a629352
99f77cd
956eac3
3ec396d
3ba348d
432b6b4
97ccea7
3e55e23
286e9ce
419b663
2408835
7e459bf
6fc3af0
767a532
8ebb5f4
ffe4553
bb28f8c
ce5df25
1c82f04
1c644a0
a0fde77
2ae7d97
a3a3b31
c05cd27
b5db653
057ee77
9e92f3f
665a484
5dce08b
03200f7
f8cd4fb
21cde40
14f0b8d
7efd134
0bcad82
f96849a
57d3c47
c5ddba1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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.
If you add the
start_vertex
to thesorted_vertices
before thefor
-loop, do you already have the vertices recorded in the correct order? Maybe it would be possible to get rid of thestd::reverse
then.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'm not sure about that. In this case, vertices will be stored as usual in DFS traversal, ignoring all other dependencies.
Consider this directed graph
0
/ \
1 2
\ /
3
If we do preorder, the vertices will be 0–1–3–2, which is incorrect for TS.
But if we do post order 0-1-2-3, Or maybe I missed something, correct me if I'm getting something wrong.
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 quickly checked @bobluppes's proposal and it indeed fails the tests. I would suggest going with the solution in this PR and think about ways getting rid of the
std::reverse
in a follow up.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.
Ah, my bad indeed. One thing we could investigate is to use a
std::deque
rather than avector
and callpush_front
. However, let's not optimize prematurely and let's tackle this in a follow up.