-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
[DO NOT MERGE] try Kahn's toposort #2833
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Preview in LiveCodesLatest commit: b7bc3f1
See documentations for usage instructions. |
85b05fe
to
b9e5a49
Compare
b9e5a49
to
2699718
Compare
2699718
to
abbbaab
Compare
abbbaab
to
83ec3d3
Compare
Update: if I use indexes instead of map, its a little faster but more ugly.
|
Update: using arrays seems to help
|
e991fe5
to
b7bc3f1
Compare
Closing this for now. While Kahn's algorithm is slightly faster for extremely large K-Ary and Star graphs, it comes with higher memory overhead and performs worse on smaller atom graphs. Given that the average case involves smaller atom graphs, I don't believe the added complexity of Kahn's algorithm is justified. |
FOR DEMONSTRATION PURPOSES ONLY
Related: #2821 (comment)
Summary
Kahn's Topological Sort uses an iterative BFS approach to sort nodes in a DAG. It uses in-degrees a count of the number of remaining unsorted dependencies a node as. As nodes are sorted, in-degrees is decremented. When in-degrees reaches zero for a node, that node is appended to the sorted set.
The difficulty with using Kahn's in our application is that we first need to do a bunch of expensive admin work.
in-degree === 0
The result averages (100x) show that Kahns runs ~25% slower than iterative DFS.