Skip to content

Add Topological Sort algorithm using DFS in GraphSearch #6263

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Saipatnaik-23
Copy link

@Saipatnaik-23 Saipatnaik-23 commented Jun 6, 2025

Description

This PR adds an implementation of Topological Sort using Depth-First Search (DFS) in Java under com.thealgorithms.graphsearch .

  • ✅ Uses DFS approach
  • ✅ Handles Directed Acyclic Graph (DAG)
  • ✅ Includes inline documentation and Javadoc comments
  • ✅ Includes a sample test case in main

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

let me know if improvements are needed. 😊

@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.

Project coverage is 73.93%. Comparing base (7602f1e) to head (a0dd6d3).

Files with missing lines Patch % Lines
...com/thealgorithms/graphsearch/TopologicalSort.java 0.00% 31 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6263      +/-   ##
============================================
- Coverage     74.07%   73.93%   -0.14%     
+ Complexity     5351     5349       -2     
============================================
  Files           677      678       +1     
  Lines         18648    18679      +31     
  Branches       3621     3627       +6     
============================================
- Hits          13813    13811       -2     
- Misses         4276     4307      +31     
- Partials        559      561       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Saipatnaik-23 Saipatnaik-23 marked this pull request as ready for review June 6, 2025 17:31
@Saipatnaik-23
Copy link
Author

Hello maintainers! This PR is ready for review — all checks are passing. Please let me know if any changes are needed. Thank you! 😊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the topological sorting already implemented in src/main/java/com/thealgorithms/sorts/TopologicalSort.java ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh You're right — I overlooked that it's already implemented in the sorts directory. Thanks for pointing that out.
Would you prefer that I close this PR, or is there a way I could contribute/improve the existing implementation?

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