You are on page 1of 13

Decision problems vs.

optimization problems
The problems we are trying to solve are basically of two kinds. In decision problems we are trying to decide whether a statement is true or false. In optimization problems we are trying to find the solution with the best possible score according to some scoring scheme. Optimization problems can be either maximization problems, where we are trying to maximize a certain score, or minimization problems, where we are trying to minimize a cost function. Example 1: Hamiltonian cycles Given a directed graph, we want to decide whether or not there is a Hamiltonian cycle in this graph. This is a decision problem. A deterministic algorithm is an algorithm which, in informal terms, behaves predictably. Given a particular input, it will always produce the same output, and the underlying machine will always pass through the same sequence of states. Deterministic algorithms are by far the most studied and familiar kind of algorithm, as well as one of the most practical, since they can be run on real machines efficiently. Formal definition Formally, deterministic algorithms can be defined in terms of a state machine: a state describes what a machine is doing at a particular instant in time. State machines pass in a discrete manner from one state to another. Just after we enter the input, the machine is in its initial state or start state. If the machine is deterministic, this means that from this point onwards, its current state determines what its next state will be; its course through the set of states is predetermined. Note that a machine can be deterministic and still never stop or finish, as long as we can predict with certainty what states it will pass through. Examples of particular abstract machines which are deterministic include the deterministic Turing machine and deterministic finite automaton. What makes algorithms non-deterministic? A variety of factors can cause an algorithm to behave in a way which is not deterministic, or non-deterministic: If it uses external state other than the input, such as user input, a global variable, a hardware timer value, a random value, or stored disk data. If it operates in a way that is timing-sensitive, for example if it has multiple processors writing to the same data at the same time. In this case, the precise order in which each processor writes its data will affect the result. If a hardware error causes its state to change in an unexpected way.

Non-deterministic algorithm
A non-deterministic algorithm involves some kind of choice at some stage in its execution. The algorithm we use to solve problems in reality using computers belongs to the deterministic category. Every step of a deterministic algorithm is uniquely determined. On the other hand, in the non-deterministic algorithms, action corresponding to one or more steps of the algorithm is depend on a no. of alternatives. The algorithm is assumed to have the power to make the correct choice. Non-deterministic algorithms is basically a definitional device for capturing the notion of verifiability, rather than a realistic method for solving problems. To reconcile this situation with our experience with deterministic algorithms, we may assume that each time a choice is to be made in non-deterministic algorithms; several copies of the algorithm are brought in to action. Each copy tries with a separate choice. The copy that reaches success first terminates all other copies. A nonsuccessful copy does affect other copies. We may simple assume that a non-deterministic algorithm always makes a correct choice whenever it is asked to make selection out of no. of alternatives, provided such a correct choice exist in the alternatives. Further when successful termination is possible, a non-deterministic algorithm makes a sequence of choices that is a shortest sequence of choices leading to a successful termination

To specify non-deterministic algorithms, we introduce these new functions Choice(S) :- arbitrarily choose one of the element of set S Failure () :- signals an unsuccessful completion Success () :- signals a successful completion

Give an example that is sorting by using these functions from ur sartaj shahani book
Tractability Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard working definition: polynomial time On an input of size n the worst-case running time is O(nk) for some constant k O(n2), O(n3), O(1), O(n lg n), O(2n), O(nn), O(n!) Polynomial time: O(n2), O(n3), O(1), O(n lg n) Not in polynomial time: O(2n), O(nn), O(n!) Polynomial-Time Algorithms Are some problems solvable in polynomial time? o Of course: many algorithms weve studied provide polynomial-time solutions to some problems Are all problems solvable in polynomial time? o No: Turings Halting Problem is not solvable by any computer, no matter how much time is given Most problems that do not yield polynomial-time algorithms are either optimization or decision problems. Optimization/Decision Problems Optimization Problems: o An optimization problem is one which asks, What is the optimal solution to problem X? o Examples: 0-1 Knapsack Fractional Knapsack Minimum Spanning Tree Decision Problems An decision problem is one with yes/no answer Examples: v Does a graph G have a MST of weight W? An optimization problem tries to find an optimal solution A decision problem tries to answer a yes/no question Many problems will have decision and optimization versions. o Eg: Traveling salesman problem optimization: find hamiltonian cycle of minimum weight decision: is there a hamiltonian cycle of weight k Some problems are decidable, but intractable: as they grow large, we are unable to solve them in reasonable time Is there a polynomial-time algorithm that solves the problem? Dealing with Hard Problems What to do when we find a problem that looks hard I couldnt find a polynomial-time algorithm, because Im too dumb Sometimes we can prove a strong lower bound (but not usually) I couldnt find a polynomial-time algorithm, because no such algorithm exists! NP-completeness lets us show collectively that a problem is hard. I couldnt find a polynomial-time algorithm, but neither could all these other smart people.

Polynomial-Time Decision Problems To simplify the notion of hardness, we will focus on the following: Polynomial-time as the cut-off for efficiency Decision problems: output is 1 or 0 (yes or no) Examples: Does a given graph G have an Euler tour? Does a text T contain a pattern P? Does an instance of 0/1 Knapsack have a solution with benefit at least K? Does a graph G have an MST with weight at most K? Problems and Languages A language L is a set of strings defined over some alphabet Every decision algorithm A defines a language L L is the set consisting of every string x such that A outputs yes on input x. We say A accepts x in this case Example: If A determines whether or not a given graph G has an Euler tour, then the language L for A is all graphs with Euler tours. The Class P P: the class of decision problems that have polynomial-time deterministic algorithms. That is, they are solvable in O(p(n)), where p(n) is a polynomial on n A deterministic algorithm is (essentially) one that always computes the correct answer Why polynomial? if not, very inefficient nice closure properties the sum and composition of two polynomials are always polynomials too Sample Problems in P u Fractional Knapsack u MST u Sorting u Others? The class NP NP: the class of decision problems that are solvable in polynomial time on a nondeterministic machine (or with a non-deterministic algorithm) (A determinstic computer is what we know) A nondeterministic computer is one that can guess the right answer or solution o Think of a nondeterministic computer as a parallel machine that can freely spawn an infinite number of processes NP is the complexity class consisting of all languages accepted by polynomial-time non-deterministic algorithms. Example o Problem: Decide if a graph has an MST of weight K o Algorithm: Non-deterministically choose a set T of n-1 edges Test that T forms a spanning tree Test that T has weight at most K o Analysis: Testing takes O(n+m) time, so this algorithm runs in polynomial time. Alternate Definition :- NP is the set of yes/no problems with the following property : If the answer is yes , then there is a proof of this fact that can be checked in polynomial time. Intuitively NP is the set of problems where we can verify a Yes answer quickly if we have the solution in front of us. Note that NP stands for Nondeterministic Polynomial-time

NP is the complexity class consisting of all languages verified by polynomial-time algorithms. Example: o Problem: Decide if a graph has an MST of weight K o Verification Algorithm: Use as a certificate, y, a set T of n-1 edges Test that T forms a spanning tree Test that T has weight at most K o Analysis: Verification takes O(n+m) time, so this algorithm runs in polynomial time. Sample Problems in NP u Fractional Knapsack u MST u Sorting u Others? Hamiltonian Cycle (Traveling Salesman) Graph Coloring Satisfiability (SAT) v the problem of deciding whether a given Boolean formula is satisfiable Equivalence of the Two Definitions Suppose A is a non-deterministic algorithm Let y be a certificate consisting of all the outcomes of the choose steps that A uses We can create a verification algorithm that uses y instead of As choose steps If A accepts on x, then there is a certificate y that allows us to verify this (namely, the choose steps A made) If A runs in polynomial-time, so does this verification algorithm Suppose B is a verification algorithm Non-deterministically choose a certificate y Run B on y If B runs in polynomial-time, so does this non-deterministic algorithm P and NP P is a subset of NP. P is the complexity class consisting of all languages that are accepted by polynomial-time algorithms. NP is the complexity class consisting of all languages verified by polynomial-time algorithms. A language that is accepted by polynomial-time algorithms must be verified by polynomial-time algorithms Major open question: P=NP? Most researchers believe that P and NP are different, but no body can prove it.

NP

What do you mean by Verification Algorithm ? Before talking about the class of NPcomplete problems, it is important to introduce the notion of a verification algorithm. Many language recognition problems that may be very hard to solve, but they have the property that it is easy to verify whether a string is in the language. Verification algorithm has two arguments: Problem input

Certificate (solution) Answers yes or no Checks if 2nd argument is certificate for first argument for studied problem The language verified by the verification algorithm A is: {i | there is an c with A(i,c)= true} Example Consider the following problem, called the Hamiltonian cycle problem. Given an undirected graph G, does G have a cycle that visits every vertex exactly once. (There is a similar problem on directed graphs, and there is also a version which asks whether there is a path that visits all vertices.) We can describe this problem as a language recognition problem, where the language is HC = {(G) : G has a Hamiltonian cycle}, where (G) denotes an encoding of a graph G as a string. The Hamiltonian cycle problem seems to be much harder, and there is no known polynomial time algorithm for this problem. For example, the figure below shows two graphs, one which is Hamiltonian and one which is not. However, suppose that a graph did have a Hamiltonian cycle. Then it would be a very easy matter for someone to convince us of this. They would simply say ``the cycle is v3 , v7 , v1 ,..., v13 . We could then inspect the graph, and check that this is indeed a legal cycle and that it visits all the vertices of the graph exactly once. Thus, even though we know of no efficient way to solve the Hamiltonian cycle problem, there is a very efficient way to verify that a given graph is in HC.

The given cycle is called a certificate. This is some piece of information which allows us to verify that a given string is in a language. More formally, given a language L, and given x L, a verification algorithm is an algorithm which given x and a string y called the certificate, can verify that x is in the language L using this certificate as help. If x is not in L then there is nothing to verify. Note that not all languages have the property that they are easy to verify. For example, consider the following languages: UHC = {(G) : G has a unique Hamiltonian cycle}, HC = {(G) : G has no Hamiltonian cycle}.

Suppose that a graph G is in the language UHC. What information would someone give us that would allow us to verify that G is indeed in the language? They could give us an example of the unique Hamiltonian cycle, and we could verify that it is a Hamiltonian cycle, but what sort of certificate could they give us to convince us that this is the only one? They could give another cycle that is NOT Hamiltonian, but this does not mean that there is not another cycle somewhere that is Hamiltonian. They could try to list every other cycle of length n, but this would not be at all efficient, since there are n! possible cycles in general. Thus, it is hard to imagine that someone could give us some information that would allow us to efficiently convince ourselves that a given graph is in the language.

What do you mean by reducibility? Language L1 is polynomial time reducible to language L2 (or: L1 p L2 ), if there exists a polynomial time computable function f : {0,1}* {0,1}* such that For all x {0,1}*: x L1 if and only if f(x) L2 We call the function f the reduction function and a polynomial time algorithm F that computes f is called reduction algorithm.

L2 ?F L2

f(x)

A2

f(x) f(x)

L1 ?

This diagram illustrates the idea of polynomial time reduction from a language L1 to another language L2. The reduction function f provides a polynomial time mapping such that if x L1 , then f(x) L2. Moreover if x L1 , then f(x) L2. Thus the reduction function maps any instance x of the decision problem represented by the language L1 to an instance f(x) of the problem represented by L2.

NP-Completeness: Reductions
The class of NPcomplete problems consists of a set of decision problems (languages) (a subset of the class NP) that no one knows how to solve efficiently, but if there were a polynomial time solution for even a single NPcomplete problem, then every problem in NP would be solvable in polynomial time. To establish this, we need to introduce the concept of a reduction. Before discussing reductions, let us just consider the following question. Suppose that there are two problems, A and B. You know (or you strongly believe at least) that it is impossible to solve problem A in polynomial time. You want to prove that B cannot be solved in polynomial time. How would you do this? We want to show that (A P) (B P). To do this, we could prove the contrapositive, (B P) (A P): In other words, to show that B is not solvable in polynomial time, we will suppose that there is an algorithm that solves B in polynomial time, and then derive a contradiction by showing that A can be solved in polynomial time. How do we do this? Suppose that we have a subroutine that can solve any instance of problem B in polynomial time. Then all we need to do is to show that we can use this subroutine to solve problem A in polynomial time. Thus we have ``reduced'' problem A to problem B. It is important to note here that this supposed subroutine is really a fantasy. We know (or strongly believe) that A cannot be solved in polynomial time, thus we are essentially proving that the subroutine cannot exist, implying that B cannot be solved in polynomial time. Be sure that you understand this, this is the basis behind all reductions.

NP-completeness
The class of NPcomplete problems consists of a set of decision problems (languages) (a subset of the class NP) that no one knows how to solve efficiently, but if there were a polynomial time solution for even a single NPcomplete problem, then every problem in NP would be solvable in polynomial time.

A language L is NP-complete, if

1. L NP 2. For every L NP: L P L

NP-Hard
A language L is NP-hard, if 1. For every L NP : L p L NP-hardness sometimes also used as term for problems that are not a decision problem, and for problems that are harder than NP

What do you mean by satisfiability?


Satisfiability (SAT): Given a Boolean expression on n variables, can we assign values such that the expression is TRUE? Ex: ((x1 x2) ((x1 x3) x4)) 2 x Seems simple enough, but no known deterministic polynomial time algorithm exists Easy to verify in polynomial time!

Example:- Conjunctive Normal Form (3-CNF) Even if the form of the Boolean expression is simplified, the problem may be NP-Complete Literal: an occurrence of a Boolean or its negation A Boolean formula is in conjunctive normal form, or CNF, if it is an AND of clauses, each of which is an OR of literals Ex: (x1 x2) (x1 x3 x4) (x5) 3-CNF: each clause has exactly 3 distinct literals Ex: (x1 x2 x3) (x1 x3 x4) (x5 x3 x4) Notice: true if at least one literal in each clause is true
Inputs: L ogic G ates: N T O 0 O R 1 A D N 0 0 1 1 0 1 1 0 1 1 O utput: 1

Proving NP- Completeness

Given a problem X, prove it is in NP-Complete. 1. Prove X is in NP.

2. Pick a known NP-complete problem say Y 3. Reduce y to X. i) Describe a transformation that maps instances of Y to instances of X , such that yes for X = yes for Y ii) prove the transformation works iii) proves it runs in polynomial time

Some examples in NP-Completyeness


Problem 1 : Clique decision problem ( max. clique problem) Theorem : prove that CLIQUE is NP- Complete what is Clique problem :In an undirected graph, a subgraph wherein each node is connected to each other node in the subgraph is a clique. Give an integer k and a graph, the problem is to determine there is a clique of size k anywhere in the graph. A clique of size k is called a k-clique. So the formal definition is : CLIQUE = { < G,K >: G is a graph with a clique of size k }

Ex . 4-clique

First, prove that CLIQUE is in NP It is simple to find a verifier for CLIQUE, using the nodes in the clique as the certificate: 1. Verify that the clique is a subgraph of the correct size 2. Check that the graph contains edges connecting the nodes in the clique. If 1 and 2 are both true, accept, otherwise reject. Now, a polynomial time reduction to 3SAT Next we want to show that the clique problem is NP-hard by proving that 3-CNF-SAT P CLIQUE We will construct a graph G based on a formula . Let k be the number of clauses in . G will have a clique of size k iff is satisfiable. The reduction algorithm begins with an instance of 3-CNF-SAT. Let = C1 C2 .. Ck Be a Boolean formula in 3-CNF with k clauses.

=(x1 x2 x3) (x1 x2 x3 ) (x1 x2 x3 )

What should the reduction do? A: Transform a 3-CNF formula to a graph, for which a k-clique will exist (for some k) iff the 3-CNF formula is satisfiable The reduction: Let = C1 C2 Ck be a 3-CNF formula with k clauses, each of which has 3 distinct literals For each clause put a triple of vertices in the graph, one for each literal

Put an edge between two vertices if they are in different triples and their literals are consistent, meaning not each others negation Run an example:

= (x1 x2 x3) (x1 x2 x3 ) (x1 x2 x3 )

Construction of G Each clause in will be represented as a set of three nodes, one for each literal. Each literal in a clause will be represented as a node labeled as the literal. The nodes will all be connected, except that no nodes from the same clause will be connected and no two nodes with contradictory labels will be connected(i.e. x1 and x1)

x1

x2

X3

X1

X1

X2

X2

X3

X3

Prove the reduction works: If B has a satisfying assignment, then each clause has at least one literal (vertex) that evaluates to 1 Picking one such true literal from each clause gives a set V of k vertices. V is a clique (Why?) If G has a clique V of size k, it must contain one vertex in each triple (clause) (Why?) We can assign 1 to each literal corresponding with a vertex in V, without fear of contradiction Proof Theorem: is satisfiable iff G has a k-clique: Assume is satisfiable. In each clause, at least one literal is true. Select one node which has a true literal as its label from each clause. The nodes selected form a k-clique since the nodes are selected one from each clause. The labels are connected since they cannot be contradictory. (cont) Finishing the proof(the converse) Assume G has a k-clique. Assign each of the literals in the labels of the clique to be true. Because nodes from the same clause are not connected, a k-clique must visit k clauses. No contradictions will be encountered since contradictory labels are not connected. Thus each clause contains at least one true literal, which means that is satisfied.Thus the reduction is correct. O(n) 3CNF formula with k clauses TRUE or FALSE Graph with 3k nodes Maximum clique size

CLIQUE O(1)

Problem-2:-Vertex-Cover problem Theorem : Prove that vertex cover problem is NP-Complete Instance: Given an n-node undirected graph G(V,E) with node set V and edge set E; a positive integer k with k<=n. Question: Is there a subset W of V having size at most k and such that for every edge {u,v} in E at least one of u and v belongs to W? A vertex cover of an undirected graph G = (V,E) is a subset V1 is a subset of V such that if (u,v) E then u V1 or v V1 ( or both). That is each vertex covers its incident edges, and a vertex cover for G is a set of vertices that covers all the edges in E. the size of vertex cover is the number of vertices in it. The vertex cover problem is to find a vertex cover of minimum size in a given graph. As a language we define: VERTEX COVER = { (G,K): graph G has a vertex cover of size k} Proof of Vertex cover is in NP-complete We first show that it is belongs to NP. Suppose we are a given graph G=(V,E) and an integer k. the certificate we choose is the vertex cover V1 V itself. The verification algorithm affirms that |V1| = k, and then it checks, for each edge (u,v) E that u V1 or v V1. This verification can be performed straightforwardly in polynomial time. Secondly we show that a known problem that is CLIQUE P VERTEX-COVER. This reduction is based on the notion of the complement of a graph. Given an undirected graph G= (V,E), we define the complement of G as G1= (V,E1) , where E1= { (u,v) : u ,v V, uv, and (u,v) E}. In other words G1 is the graph containing exactly those edges that are not in G. As discussed in below figure.

u
w

z y

z y

Reduction algorithm

The reduction algorithm takes as input an instance (G,k) of the clique prolem. It computes the complement of G which is easily done in polynomial time. The output of the reduction algorithm is the instance < G1 , |V| - k > of the vertex cover problem. To complete the proof we have to show that the graph G has a clique of size k iff the graph G1 has a vertex cover of size |V| - k. Suppose that G has a clique V1 V with |V1| = k. we claim hat V V1 is a vertex cover in G1. Let (u ,v ) be any edge in E1. Then ( u ,v) E, which implies that at least one of u or v does not belongs to V1, since every pair of vertices in V1 is connected by an edge of E. So at least one of u or v is in V V1 which means that an edge ( u ,v) is covered by V V1.since (u,v) was choosen arbitrarily from E1, every edge of E1 is covered by a vertex in V V1. Hence the set V V1 which has size |V| - k forms a vertex cover for G1. Conversely suppose that G1 has a vertex cover V1 V , where |V1| = |V| - k. then for all u , v V if ( u,v) E1, then u V1 or v V1 or both. The contrapositive of this implication is that for all u v V1, if u V1 or v V1, then (u,v) E. Polynomial time

CLIQUE problem

Complement of Graph

VERTEX COVER Largest clique trivial Smallest vertex cover S

Problem-3 TRAVELING SALESMAN PROBLEM (TSP)


The well-known traveling salesman problem: Optimization variant: a salesman must travel to n cities, visiting each city exactly once and finishing where he begins. How to minimize travel time? Model as complete graph with cost c(i,j) to go from city i to city j How would we turn this into a decision problem? Ans : ask if there is a TSP with cost < k That is the salesman must visit all n cities. For this salesman may make a TOUR or HAMILTNIAN CYCLE, visiting each city exactly once and finishing at city he starts from. There is a integer cost c(i,j) to travel city I to city j. Salesman makes a tour such that the total cost should minimum. So the language for this decision problem is: TSP= {<G,c,k> : G=(V,E) is a complete graph, c is a function from V X V Z ,k Z and G has a TSP tour with cost at most k} The steps to prove TSP is NP-Complete: 1) Prove that TSP NP (Argue this) 2)Reduce the undirected hamiltonian cycle problem to the TSP if we had a TSP-solver, we could use it to solve the hamilitonian cycle problem in polynomial time So How can we transform an instance of the hamiltonian cycle problem to an instance of the TSP? Can we do this in polynomial time?

Proof of 1): If for a given instance of problem, we use as a certificate the sequence of n vertices in the tour. The verification algorithm checks that the sequence contain each vertex exactly once and sum up edge costs on that tour and check it must be at most k. This process certainly take in polynomial time. Proof of 2) that is we have to prove TSP is NP-hard. We choose a problem already in NPC i.e HAMILTONIAN CYCLE and we have show HAMILTONIAN CYCLE P TSP. For this we form a complete graph G1 = { V ,E1 : where E1 =(i,j) : i,j V and I not equal to j} and we define the cost function as : c(i,j) = { 0 if (i,j) belongs to E 1 if (i,j) does not belongs to E}

4 1 2 1

3
x

5 We now show that graph G has a Hamiltonian cycle if and only if graph G1 has a tour of cost at most 0. Suppose that graph g has a Hamiltonian cycle h. Each edge in h belongs to E and thus has a cost 0 in G1. Thus h is a tour in G1 with cost 0. Conversely , suppose that graph G1 has a tour h1 of cost at most 0. Since the costs of edges in E1 are 0 and 1, the cost of tour h1 is exactly 0 and each edge on the tour must have cost 0. Therefore h1 contains only edges in E. we conclude that h1 is a Hamiltonian cycle in graph G. (proved) Problem-4:- Hamiltonian Cycle (from Vertex Cover)
A Hamiltonian cycle is a graph is a cycle that visits every vertex exactly once. This is very different from an Eulerian cycle, which is actually a closed walk that traverses every edge exactly once. Eulerian cycles are easy to find and construct in linear time using a variant of depth-first search.Finding Hamiltonian cycles, on the other hand, is NP-hard. To prove this, we use a reduction from the vertex cover problem. Given a graph G and an integer k, we need to transform it into another graph G0, such that G0 has a Hamiltonian cycle if and only if G has a vertex cover of size k. As usual, our transformation uses several gadgets. For each edge (u, v) in G, we have an edge gadget in G0 consisting of twelve vertices and fourteen edges, as shown below. The four corner vertices (u, v, 1), (u, v, 6), (v, u, 1), and (v, u, 6) each have an edge leaving the gadget. A Hamiltonian cycle can only pass through an edge gadget in one of three ways. Eventually, these will correspond to one or both of the vertices u and v being in the vertex cover.

DRAW THE DIAGRAM FROM CORMEN BOOK


G0 also contains k cover vertices, simply numbered 1 through k. Finally, for each vertex u in G, we string together all the edge gadgets for edges (u, v) into a single vertex chain, and then connect the ends of the chain to all the cover vertices. Specifically,suppose u has d neighbors v1, v2, . . . , vd. Then G0 has d 1 edges between (u, vi, 6) and (u, vi+1, 1), plus k edges between the cover vertices and (u, v1, 1), and finally k edges between the cover vertices and (u, vd, 6). Its not hard to prove that if {v1, v2, . . . , vk} is a vertex cover of G, then G0 has a Hamiltonian cyclestart at cover vertex 1, through traverse the vertex chain for v1, then visit cover vertex 2, then traverse the vertex chain for v2, and so forth, eventually returning to cover vertex 1. Conversely, any Hamiltonian cycle in G0 alternates between cover vertices and vertex chains, and

the vertex chains correspond to the k vertices in a vertex cover of G. (This is a little harder to prove.) Thus,G has a vertex cover of size k if and only if G0 has a Hamiltonian cycle.

DRAW THE DIAGRAM FROM CORMEN BOOK


The transformation from G to G0 takes at most O(n2) time, so the Hamiltonian cycle problem is NPhard. Moreover, since we can easily verify a Hamiltonian cycle in linear time, the Hamiltonian cycle problem is in NP, and therefore NP-complete. A closely related problem to Hamiltonian cycles is the famous traveling salesman problemGiven a weighted graph G, find the shortest cycle that visits every vertex. Finding the shortest cycle is obviously harder than determining if a cycle exists at all, so the traveling salesman problem is also NP-hard.

You might also like