0% found this document useful (0 votes)
47 views

Problem Statement: Solving Travelling Salesman Problem Using Reedy Algorithm & Rute Force Algorithm

The document compares greedy and brute force algorithms for solving the travelling salesman problem (TSP). The TSP involves finding the shortest route to visit each city once and return to the starting point. A greedy algorithm selects the shortest distance at each step without considering future consequences, resulting in faster run times but not necessarily the optimal solution. In contrast, a brute force algorithm tries every possible route to always find the optimal solution but has exponentially higher run times as the number of cities increases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Problem Statement: Solving Travelling Salesman Problem Using Reedy Algorithm & Rute Force Algorithm

The document compares greedy and brute force algorithms for solving the travelling salesman problem (TSP). The TSP involves finding the shortest route to visit each city once and return to the starting point. A greedy algorithm selects the shortest distance at each step without considering future consequences, resulting in faster run times but not necessarily the optimal solution. In contrast, a brute force algorithm tries every possible route to always find the optimal solution but has exponentially higher run times as the number of cities increases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Problem Statement

Solving Travelling Salesman Problem Using


Greedy Algorithm &
Brute 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

1 Implementation of Greedy Algorithm in Travel Ejim, S.


Salesman Problem

2 Population-Based Optimization Algorithms for Mohammad Reza Bonyadi


Solving the Travelling Salesman Problem

3 What is a Brute Force Algorithm Spacey, J


Analysis of Algorithm

Brute Force Approach:


● The TSP solutions for brute force is by trying all possible routes also compute the total distance and
then compare the distances from each routes. The least distance will be taken as the optimal
solution.
● 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 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.

You might also like