Skip to content
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

feat: add Kahn's algorithm for topological sort #735

Merged
merged 3 commits into from
Sep 8, 2024

Conversation

soondubu137
Copy link
Contributor

Additions

Currently, there is only a DFS implementation for topological sort. Therefore, I'm adding Kahn's algorithm.

graph/kahn.go: an implementation of the Kahn's algorithm for topological sort, complemented with detailed comments. My code conforms to the Graph struct defined in graph/graph.go.
graph/kahn_test.go: 11 test cases.

Notes

  1. I suggest renaming graph/topological.go to something else to indicate its DFS implementation.
  2. graph/topological_test.go has a package-level variable called testCases. I think it's better to move it into the test function.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.65%. Comparing base (24c7f1f) to head (104beaf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #735      +/-   ##
==========================================
+ Coverage   87.59%   87.65%   +0.05%     
==========================================
  Files         208      209       +1     
  Lines        5524     5547      +23     
==========================================
+ Hits         4839     4862      +23     
  Misses        543      543              
  Partials      142      142              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@soondubu137
Copy link
Contributor Author

soondubu137 commented Sep 8, 2024

It seems the current codebase has some linting issue. I checked the errors reported by CI Lint, and I think they arise from existing files. (Same for PR #734)

@raklaptudirm raklaptudirm merged commit 67eebcb into TheAlgorithms:master Sep 8, 2024
4 of 5 checks passed
@soondubu137 soondubu137 deleted the impl/kahn branch September 9, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants