Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6203925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:00:01+00:00 2026-05-24T05:00:01+00:00

I have been trying to figure out how to solve TSP using backtracking. How

  • 0

I have been trying to figure out how to solve TSP using backtracking.
How do you calculate the “cost”?

Matrix:

∞   20  30  10  11
15  ∞   16  4   2
3   5   ∞   2   4
19  6   18  ∞   3
16  4   7   16  ∞

Cost:

3 -> 1 -> 2 -> 4 -> 5 -> 3 cost = 37
3 -> 1 -> 2 -> 5 -> 4 -> 3 cost = 59
3 -> 1 -> 5 -> 2 -> 4 -> 3 cost = 50
3 -> 1 -> 5 -> 4 -> 2 -> 3 cost = 62
3 -> 1 -> 4 -> 2 -> 5 -> 3 cost = 28
3 -> 1 -> 4 -> 5 -> 2 -> 3 cost = 36

I found out that it’s calculated using Bellmans equation, I just don’t know
the way to do it.

Any help would be highly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:00:02+00:00Added an answer on May 24, 2026 at 5:00 am

    In order to calculate the costs, you just need to sum up all the edge costs. For example for the route 3 -> 1 -> 2 -> 4 -> 5 -> 3, this yields

    (3,1) => 3
    (1,2) => 20
    (2,4) => 4
    (4,5) => 3
    (5,3) => 7
    ------------
    sum      37
    

    So, essentially you have to generate a first sample route and calculate its cost. As soon as you did this, you know that the resulting cost might be an optimum solution.

    If you do backtracking now and you come into a situation where you already have a higher cost, you know that this won’t lead to a better route and thus, you can stop exploring routes and backtrack one step back.

    Example: You discovered in your first run that the route 1 2 3 4 5 6 7 8 9 1 yields cost of 40. Now, at some backtracking step, you have the beginning of a route: 1 2 4 5 6 ... and see that up to this point, the cost is already 41. This means, if you explore any route beginning with these numbers, you will have a route having cost more than 40 and thus, not optimal! Now, you can simply discard all routes beginning with 1 2 4 5 6.

    (Note that the above considerations work only if using nonnegative edge costs!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to figure out how i can solve an equation that has been
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out a way to tag several methods from
I am fairly new to Emacs and I have been trying to figure out
I have been trying to figure this out for way to long tonight. I
I have been going mad trying to figure out why my scripts weren't working,
I have been pulling my hair out trying to figure out what I can't
I have been pounding my head against a wall trying to figure out what
Here's a fun one I've been trying to figure out. I have the following
I have been trying to figure out a reliable solution in provide a drag-drop-upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.