SlideShare a Scribd company logo
4
Most read
5
Most read
9
Most read
TSP  NP-Complete
Emre Can Kucukoglu
eckucukoglu@gmail.com
16.01.2016
Traveling Salesman Problem
• Given n cities 𝑐1, 𝑐2, 𝑐3, … , 𝑐 𝑛 and integer distances 𝑑 𝑐 𝑖,𝑐 𝑗
between
any two cities 𝑐𝑖 𝑎𝑛𝑑 𝑐𝑗.
• TSP asks for the total distance of the shortest tour of the cities.
• Decision version of TSP asks if there is a tour with a total distance
at most B, where B is an input.
TSP: formal description
TSP = {
<G, d, B> :
G=(V, E) is a complete undirected graph,
d is an edge cost function from VxV→Z+ ∪ {0},
B ∈ Z,
G has a Hamiltonian cycle with cost ≤ B
}
TSP  NP-Complete ?
• To prove that TSP  NP-Complete,
• First, we must show that there exists a nondeterministic algorithm in
polynomial time that solves TSP.
• TSP  NP
• Then, we will reduce the undirected Hamiltonian cycle, which is a known
NP-complete problem, to TSP:
• HAM-CYCLE ≤ 𝑝 TSP
Nondeterministic algorithm for TSP
• The following procedure is a
polynomial time non-deterministic
algorithm that terminates
successfully iff an ordering of n-
cities are distinct and sum of
distances between pairs are less
than or equal to B.
• The complexity of this non-
deterministic algorithm is O(n).
• So that; TSP  NP
Hamiltonian Circuit Problem
• Find a tour of a given unweighted graph that simply starts at one
vertex and goes through all the other vertices and ends at the
starting vertex.
• Note that the input graph G to a Hamiltonian Cycle problem need
not be a complete graph connecting all vertices.
• Hamiltonian circuit is a known NP-Complete problem.
• To transform Hamiltonian circuit/cycle problem to TSP,
• Create a graph G’ = (V, E’) from Hamiltonian cycle instance G = (V, E),
• G’ is a complete graph,
• Edges in E’ also in E have an edge cost 0,
• All other edges in E’ have an edge cost 1.
HAM-CYCLE ≤ 𝑝 TSP
• Take any instance G = (V, E) for
the Hamiltonian cycle
problem,
• Convert it into an instance
G′=(V, E′ = V×V, d), B = 0 of TSP,
• 𝑑 𝑐 𝑖,𝑐 𝑗
= { 0 if edge (𝑐𝑖, 𝑐𝑗)  E,
1 otherwise }
• Time complexity of reduction
is O(𝑛2) as there n(n-1)/2
edges on a complete graph.
HAM-CYCLE ≤ 𝑝 TSP
• Problem: Is there a TSP on G’ with total edge cost = 0 ?
• If G has a Hamiltonian circuit, algorithm will return "yes" on input (G′, C),
• If there is no Hamiltonian circuit in G, algorithm will return "no" on input (G′, C).
• If G’ has a cycle with cost = 0, every edge of that cycle has a cost = 0, thus G has a
Hamiltonian cycle.
• If Hamiltonian cycle does not exist, then there is no simple cycle in G, that visits
every vertex exactly once. Suppose that TSP has a “yes” answer. Then, there is a
cycle that visits every vertex once with total cost = 0. Since negative distance cost is
not possible, every edges have cost = 0, which implies that these edges are in the
Hamiltonian Circuit graph. It is a contradiction.
HAM-CYCLE ≤ 𝑝 TSP
TSP  NP-Complete
• It is well known that Hamiltonian Circuit is NP-Complete, every
problem ß in NP reduces to Hamiltonian Circuit in polynomial
time.
• We have reduced Hamiltonian Circuit to TSP in polynomial time, it
indicates that every problem ß in NP reduces to TSP is polynomial
time, since the sum of two polynomials is also a polynomial.
References
• http://www.csie.ntu.edu.tw/~lyuu/complexity/2004/c_20040929.pdf
• http://web.calstatela.edu/faculty/jmiller6/2014spring-
cs312/lectures/Lecture10.pdf
• https://www.quora.com/Why-is-the-traveling-salesman-problem-NP-
complete/answer/Luke-Benning

More Related Content

What's hot (20)

PPTX
sum of subset problem using Backtracking
Abhishek Singh
 
PPTX
N queen problem
Ridhima Chowdhury
 
PPTX
First order logic
Megha Sharma
 
PPT
01 knapsack using backtracking
mandlapure
 
PPT
2.2 decision tree
Krish_ver2
 
PPTX
The n Queen Problem
Sukrit Gupta
 
PPTX
Galois field
Niaj Morshed
 
PPTX
First order predicate logic (fopl)
chauhankapil
 
PPT
Computational Learning Theory
butest
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PPT
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
PPTX
Unification and Lifting
Megha Sharma
 
PPTX
Asymptotic notations
Nikhil Sharma
 
PPTX
Knowledge Representation, Inference and Reasoning
Sagacious IT Solution
 
PPTX
Truth management system
Mohammad Kamrul Hasan
 
PPT
Np cooks theorem
Narayana Galla
 
PDF
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
PPTX
Decision Tree - ID3
Xueping Peng
 
PPTX
Classification in data mining
Sulman Ahmed
 
PPTX
Context free grammar
Ratnakar Mikkili
 
sum of subset problem using Backtracking
Abhishek Singh
 
N queen problem
Ridhima Chowdhury
 
First order logic
Megha Sharma
 
01 knapsack using backtracking
mandlapure
 
2.2 decision tree
Krish_ver2
 
The n Queen Problem
Sukrit Gupta
 
Galois field
Niaj Morshed
 
First order predicate logic (fopl)
chauhankapil
 
Computational Learning Theory
butest
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Unification and Lifting
Megha Sharma
 
Asymptotic notations
Nikhil Sharma
 
Knowledge Representation, Inference and Reasoning
Sagacious IT Solution
 
Truth management system
Mohammad Kamrul Hasan
 
Np cooks theorem
Narayana Galla
 
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Decision Tree - ID3
Xueping Peng
 
Classification in data mining
Sulman Ahmed
 
Context free grammar
Ratnakar Mikkili
 

Similar to Tsp is NP-Complete (20)

PPTX
optimal merge pattern notes - algorithms
devivisalakshi2010
 
PPT
chapter111111111111111111111111111111.ppt
sppatelrs
 
PPT
chapter1 (1).ppt
NateHigger
 
PPT
chapter1.ppt
NateHigger
 
PPT
lecture 29
sajinsc
 
PPT
rachit.ppt for academic purposes for college students
sriramvignesh9
 
PPTX
P vs NP
Mikel Qafa
 
PDF
NP Problems in design and analysis of alogorithm
keshavrohilla987
 
PDF
Reductions
Muhammad Alhalaby
 
PPTX
unit-4-dynamic programming
hodcsencet
 
PDF
Solving connectivity problems via basic Linear Algebra
cseiitgn
 
PPTX
Approximation
RiyaSingh235
 
PDF
The Traveling Salesman Problem
Maryam Alipour
 
PPT
lecture 30
sajinsc
 
PPT
Chap8 new
Loc Tran
 
PPTX
NP Complete Problems -- Internship
Seshagiri Rao Kornepati
 
PPTX
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
PPT
Approx
guest0264d3b
 
PPTX
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
PPTX
Teori pnp
Tenia Wahyuningrum
 
optimal merge pattern notes - algorithms
devivisalakshi2010
 
chapter111111111111111111111111111111.ppt
sppatelrs
 
chapter1 (1).ppt
NateHigger
 
chapter1.ppt
NateHigger
 
lecture 29
sajinsc
 
rachit.ppt for academic purposes for college students
sriramvignesh9
 
P vs NP
Mikel Qafa
 
NP Problems in design and analysis of alogorithm
keshavrohilla987
 
Reductions
Muhammad Alhalaby
 
unit-4-dynamic programming
hodcsencet
 
Solving connectivity problems via basic Linear Algebra
cseiitgn
 
Approximation
RiyaSingh235
 
The Traveling Salesman Problem
Maryam Alipour
 
lecture 30
sajinsc
 
Chap8 new
Loc Tran
 
NP Complete Problems -- Internship
Seshagiri Rao Kornepati
 
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
Approx
guest0264d3b
 
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
Ad

Recently uploaded (20)

PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
Basics and rules of probability with real-life uses
ravatkaran694
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Ad

Tsp is NP-Complete

  • 1. TSP  NP-Complete Emre Can Kucukoglu [email protected] 16.01.2016
  • 2. Traveling Salesman Problem • Given n cities 𝑐1, 𝑐2, 𝑐3, … , 𝑐 𝑛 and integer distances 𝑑 𝑐 𝑖,𝑐 𝑗 between any two cities 𝑐𝑖 𝑎𝑛𝑑 𝑐𝑗. • TSP asks for the total distance of the shortest tour of the cities. • Decision version of TSP asks if there is a tour with a total distance at most B, where B is an input.
  • 3. TSP: formal description TSP = { <G, d, B> : G=(V, E) is a complete undirected graph, d is an edge cost function from VxV→Z+ ∪ {0}, B ∈ Z, G has a Hamiltonian cycle with cost ≤ B }
  • 4. TSP  NP-Complete ? • To prove that TSP  NP-Complete, • First, we must show that there exists a nondeterministic algorithm in polynomial time that solves TSP. • TSP  NP • Then, we will reduce the undirected Hamiltonian cycle, which is a known NP-complete problem, to TSP: • HAM-CYCLE ≤ 𝑝 TSP
  • 5. Nondeterministic algorithm for TSP • The following procedure is a polynomial time non-deterministic algorithm that terminates successfully iff an ordering of n- cities are distinct and sum of distances between pairs are less than or equal to B. • The complexity of this non- deterministic algorithm is O(n). • So that; TSP  NP
  • 6. Hamiltonian Circuit Problem • Find a tour of a given unweighted graph that simply starts at one vertex and goes through all the other vertices and ends at the starting vertex. • Note that the input graph G to a Hamiltonian Cycle problem need not be a complete graph connecting all vertices. • Hamiltonian circuit is a known NP-Complete problem.
  • 7. • To transform Hamiltonian circuit/cycle problem to TSP, • Create a graph G’ = (V, E’) from Hamiltonian cycle instance G = (V, E), • G’ is a complete graph, • Edges in E’ also in E have an edge cost 0, • All other edges in E’ have an edge cost 1. HAM-CYCLE ≤ 𝑝 TSP
  • 8. • Take any instance G = (V, E) for the Hamiltonian cycle problem, • Convert it into an instance G′=(V, E′ = V×V, d), B = 0 of TSP, • 𝑑 𝑐 𝑖,𝑐 𝑗 = { 0 if edge (𝑐𝑖, 𝑐𝑗)  E, 1 otherwise } • Time complexity of reduction is O(𝑛2) as there n(n-1)/2 edges on a complete graph. HAM-CYCLE ≤ 𝑝 TSP
  • 9. • Problem: Is there a TSP on G’ with total edge cost = 0 ? • If G has a Hamiltonian circuit, algorithm will return "yes" on input (G′, C), • If there is no Hamiltonian circuit in G, algorithm will return "no" on input (G′, C). • If G’ has a cycle with cost = 0, every edge of that cycle has a cost = 0, thus G has a Hamiltonian cycle. • If Hamiltonian cycle does not exist, then there is no simple cycle in G, that visits every vertex exactly once. Suppose that TSP has a “yes” answer. Then, there is a cycle that visits every vertex once with total cost = 0. Since negative distance cost is not possible, every edges have cost = 0, which implies that these edges are in the Hamiltonian Circuit graph. It is a contradiction. HAM-CYCLE ≤ 𝑝 TSP
  • 10. TSP  NP-Complete • It is well known that Hamiltonian Circuit is NP-Complete, every problem ß in NP reduces to Hamiltonian Circuit in polynomial time. • We have reduced Hamiltonian Circuit to TSP in polynomial time, it indicates that every problem ß in NP reduces to TSP is polynomial time, since the sum of two polynomials is also a polynomial.