Problem Description
a. Implement the algorithm 3.11 titled Traveling Salesperson Problem Tree using C++, Java, or C Sharp.
Algorithm 3.11: Dynamic Programming Algorithm for the Traveling Salesperson Problem
Problem: Determine an optimal tour in a weighted, directed graph. The weights are nonnegative numbers.
Inputs: A weighted, directed graph, and n, the number of vertices in the graph. The graph is represented by a two-dimensional array w, which has both its rows and columns indexed from 1 to n, where W[i][j] is the weight on the edge from the ith vertex to the jth vertex.
Outputs: A variable minlength, whose value is the length of an optimal tour, and a two-dimensional array P from which an optimal tour can be constructed. P has its rows indexed from 1 to n and its columns indexed by all subsets of V-{v1}. P[i][A] is the index of the first vertex after vi on a shortest path from vi to v that passes through all vertices in A exactly once.
void travel(int n, const number W[][], index P[l[l, number& minlength)
index i, j, k; number D[1..n][subset of V-{u}];
for i=2; i<=n; i++)
D[i][] = W[i][1];
for k=1; k<=n-2; k++
for all subsets A in V- {vi} containing k vertices
for i such that i != 1 and i is not in A
D[i][A] = minimum(W[i][j] + D[j][A-{i}], j in A)
P[i][A] = value of j that gave the minimum;
D[1][V-{vi}] = minimum(W[1][j] + D[j][V-{v1,vi}], j in P[1][V-{}])
minlength = D[1][V-{v1}];