Problem Definition

  • Given a set of cities
  • A distance function which gives the distance between every pair of cities
  • We want to start at and finish at after visiting all cities on the way
  • Question is which order should we choose to visit the cities to minimise the total distance traveled.

Brute Force algorithm

  • Tries all possible orders
  • Given an ordering of the cities, we can compute its cost by adding values.
  • Hence, running time of the algorithm is which is roughly
  • Can we do better, say ?

Setting up the recurrence for dynamic programming:

  • For each and each let be the minimum length of a tour that
    • Starts at
    • visits all cities in
    • ends at
  • Base case is when
    • For each , we have
  • Now suppose and we want to compute for some
    • That is, we want to compute a minimum length of tour which starts at , visits all cities in and ends at
    • Let be the last city visited on this tour before ending at
    • We don’t know , but it must be a city from
    • So we guess all possibilities for which gives the following recurrence:

Algorithm

Analysis of Runtime

  • Number of entries in the dynamic programming table is
    • We maintain an entry , for each and each
  • To compute , we take min over numbers, look up entries and do additions
    • Overall time is since