Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If possible convert this code into java // problem using naive approach. #include using namespace std; #define V 4 // implementation of traveling Salesman Problem

If possible convert this code into java

// problem using naive approach.

#include

using namespace std;

#define V 4

// implementation of traveling Salesman Problem

int travllingSalesmanProblem(int graph[][V], int s)

{

// store all vertex apart from source vertex

vector vertex;

for (int i = 0; i < V; i++)

if (i != s)

vertex.push_back(i);

// store minimum weight Hamiltonian Cycle.

int min_path = INT_MAX;

do {

// store current Path weight(cost)

int current_pathweight = 0;

// compute current path weight

int k = s;

for (int i = 0; i < vertex.size(); i++) {

current_pathweight += graph[k][vertex[i]];

k = vertex[i];

}

current_pathweight += graph[k][s];

// update minimum

min_path = min(min_path, current_pathweight);

} while (next_permutation(vertex.begin(), vertex.end()));

return min_path;

}

// driver program to test above function

int main()

{

// matrix representation of graph

int graph[][V] = { { 0, 10, 15, 20 },

{ 10, 0, 35, 25 },

{ 15, 35, 0, 30 },

{ 20, 25, 30, 0 } };

int s = 0;

cout << travllingSalesmanProblem(graph, s) << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

=+4 How did it affect HR?

Answered: 1 week ago

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago