Problem Statement: Solving Travelling Salesman Problem Using Reedy Algorithm & Rute Force Algorithm
Problem Statement: Solving Travelling Salesman Problem Using Reedy Algorithm & Rute Force Algorithm
Atharva Vijay Nikam Tejas Shailendra More Bhushan Anil Karape Parth Parmar
Introduction
● WHAT IS TRAVELLING SALESMAN PROBLEM?
○ Given a set of cities and the distance between every pair of
cities, the problem is to find the shortest possible route that
visits every city exactly once and returns to the starting
point.
Introduction
● Greedy algorithm:
○ Greedy algorithm is an algorithm that will solve problem
by choosing the best choice/optimum solution at that
time, without considering the consequences that will
affect it later, thus the solution won’t be always the
optimal global solution.
● Brute Force algorithm:
○ Brute Force Algorithms are exactly what they sound like –
straightforward methods of solving a problem that rely on
sheer computing power and trying every possibility rather
than advanced techniques to improve efficiency.
Literature Survey
.
Sr.No Title Authors
○ Def permutation(lst): This function is used to generate all possible routes, excluding the initial
city, using lst which is the list of cities.
○ Def countCost(matrix): This function is used to count the total distance for all possible routes,
in which the salesman has to visit each cities once.
● TIME COMPLEXITY:
○ The TSP solutions in the algorithm imply trying all the permutation combinations with a
complexity of O(n! (n + 1)). With n is the number of cities. If we want to solve 4 city problem,
the time running would be 120.
○ If we try with 8 cities, the time would be 362880, we can see that this algorithm won’t be
practical to use with problem that has many cities.
Analysis of Algorithm
Greedy Approach:
● For solving TSP, the algorithm will selects the shortest distance for each initial city to target
city. After adding up the distance from each city, the algorithm choose the shortest
possible distance and also the routes.
● The following are the functions that we use in our program
○ Def takeInput(n): This function is used to take input from user and store them in
matrix list, with n is the number of city in the problem.
○ Def countCost(matrix): This function is used to count the total distance by choosing
the minimum distance for each cities in the matrix, without visiting the same city
twice, from the initial city and visiting the next cities that has least distance, and back
again to the initial city. After all cities have been visited, the algorithm will compute
the total distance.
● TIME COMPLEXITY:
○ The complexity of TSP using greedy algorithm O(n² + 2n + 2) with n is the number of
cities on the problem. If we want to solve 4 city problem, the time running would be
26, and if we solve 8 city problem, the time running would be 82
RESULTS
● If we compare both of the algorithms running time, greedy algorithm is much faster
that brute force, but the solution produced by this algorithm won’t always be the
optimal solution.
Conclusion
● According to our experiment, solving TSP with brute force algorithm and
greedy algorithm, we can conclude that greedy algorithm is more
efficient than brute force algorithm, because the running time for
greedy algorithm is much faster than brute force algorithm.
● But the consequences is that greedy algorithm will not always gives the
optimal solution, while brute force will take much time, but always gives
the optimal solution.