Skip to content

feat: add Traveling Salesman Problem implementation #6205

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

Merged
merged 13 commits into from
Mar 31, 2025

Conversation

DenizAltunkapan
Copy link
Collaborator

The Traveling Salesman Problem (TSP) asks:
"Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?"
TSP is NP-hard and serves as a benchmark for optimization algorithms.
For more information, see Wikipedia.

  • Added brute-force solution with permutation generation (O(n!))
  • Implemented dynamic programming solution (Held-Karp algorithm, O(n^2*2^n))
  • Included comprehensive test cases for both approaches
  • Added detailed JavaDoc documentation for all methods
  • 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

@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 73.77%. Comparing base (0072ed9) to head (9995922).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/graph/TravelingSalesman.java 83.33% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6205      +/-   ##
============================================
+ Coverage     73.74%   73.77%   +0.03%     
- Complexity     5275     5297      +22     
============================================
  Files           669      670       +1     
  Lines         18283    18343      +60     
  Branches       3528     3546      +18     
============================================
+ Hits          13483    13533      +50     
- Misses         4259     4263       +4     
- Partials        541      547       +6     

☔ 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.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) March 31, 2025 22:14
@siriak siriak merged commit 743f966 into TheAlgorithms:master Mar 31, 2025
6 checks passed
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