Algorithm TSPInput: Output: C={c1,c2,…,cn} and a distance function dist:C×C→R≥0Minimum tour distance starting and ending at c1while visiting every city in Cfor i=2 to n doOPT[{ci},ci]=dist(c1,ci)end forfor k=2 to n dofor S⊆{c2,c3,…,cn} with ∣S∣=k doOPT[S,ci]=cj∈(S∖{ci})min(OPT[S∖{ci},cj]+dist(cj,ci))end forIncrease k by oneend forreturn 2≤i≤nmin(OPT[{c2,c3,…,cn},ci]+dist(ci,c1))
Analysis of Runtime
Number of entries in the dynamic programming table is O(2n⋅n)
We maintain an entry OPT[S,ci], for each S⊆{c1,c2,⋯,cn} and each ci∈S
To compute OPT[S,ci], we take min over ∣S∣ numbers, look up ∣S∣−1 entries and do ∣S∣−1 additions