0% found this document useful (0 votes)
31 views11 pages

5.5 TSP

Uploaded by

yatinrana10143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views11 pages

5.5 TSP

Uploaded by

yatinrana10143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Department of Computer Science and Engineering (CSE)

UNIVERSITY INSTITUTE OF
ENGINEERING
COMPUTER SCIENCE ENGINEERING
Bachelor of Engineering
Design and Analysis of
Algorithms(CST-311/ITT-311)

Topic: Travelling Salesman Problem DISCOVER . LEARN . EMPOWER

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Learning Objectives & Outcomes


Objective:
• To understand the concept of Travelling Salesman
Problem using dynamic programming

Outcome:
• Student will understand
 Travelling Salesman Problem

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Travelling Salesman Problem

• Travelling Salesman Problem (TSP): Given a set of


cities and 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.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Naive Solution

1) Consider city 1 as the starting and ending point.


2) Generate all (n-1)! Permutations of cities.
3) Calculate cost of every permutation and keep track of
minimum cost permutation.
4) Return the permutation with minimum cost.

Time Complexity: Θ(n!)

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Using Dynamic Programming


• To calculate cost(i) using Dynamic Programming, we
need to have some recursive relation in terms of sub-
problems. Let us define a term C(S, i) be the cost of the
minimum cost path visiting each vertex in set S exactly
once, starting at 1 and ending at i.
• We start with all subsets of size 2 and calculate C(S, i) for
all subsets where S is the subset, then we calculate C(S, i)
for all subsets S of size 3 and so on. Note that 1 must be
present in every subset.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Algorithm

If size of S is 2, then S must be {1, i},


C(S, i) = dist(1, i)
Else if size of S is greater than 2.
C(S, i) = min { C(S-{i}, j) + dis(j, i)} where j belongs to S, j != i
and j != 1.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Differentiate between Divide & Conquer Method vs


Dynamic Programming.
Divide & Conquer Method Dynamic Programming

1.It deals (involves) three steps at each level of recursion: 1.It involves the sequence of four steps:
Divide the problem into a number of subproblems.
oCharacterize the structure of optimal solutions.
Conquer the subproblems by solving them recursively.
Combine the solution to the subproblems into the solution oRecursively defines the values of optimal solutions.
for original subproblems.
oCompute the value of optimal solutions in a Bottom-up
minimum.

oConstruct an Optimal Solution from computed information.

2. It is Recursive. 2. It is non Recursive.

3. It does more work on subproblems and hence has more 3. It solves subproblems only once and then stores in the
time consumption. table.

4. It is a top-down approach. 4. It is a Bottom-up approach.

5. In this subproblems are independent of each other. 5. In this subproblems are interdependent.

6. For example: Merge Sort & Binary Search etc. 6. For example: Matrix Multiplication.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Differentiate between Dynamic Programming and


Greedy Method
Dynamic Programming Greedy Method

1. Dynamic Programming is used to obtain 1. Greedy Method is also used to get the
the optimal solution. optimal solution.

2. In Dynamic Programming, we choose at 2. In a greedy Algorithm, we make whatever


each step, but the choice may depend on the choice seems best at the moment and then
solution to sub-problems. solve the sub-problems arising after the
choice is made.

3. Less efficient as compared to a greedy 3. More efficient as compared to a greedy


approach approach

4. Example: 0/1 Knapsack 4. Example: Fractional Knapsack

5. It is guaranteed that Dynamic 5. In Greedy Method, there is no such


Programming will generate an optimal guarantee of getting Optimal Solution.
solution using Principle of Optimality.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

REFERENCES
Text books:
•Cormen, Leiserson, Rivest, Stein, “Introduction to Algorithms”, Prentice Hall of
India, 3rd edition 2012. problem, Graph coloring.

Websites:
•https://www.tutorialspoint.com/design_and_analysis_of_algorithms/
design_and_analysis_of_algorithms_travelling_salesman_problem.htm
•https://www.javatpoint.com/divide-and-conquer-method-vs-dynamic-
programming
•https://www.javatpoint.com/dynamic-programming-vs-greedy-method

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Summary

Dynamic programming:

• Travelling Salesman Problem


• Differentiate between Divide & Conquer Method vs Dynamic
Programming.
• Differentiate between Dynamic Programming and Greedy
Method

University Institute of Engineering (UIE)


THANK YOU

University Institute of Engineering (UIE)

You might also like