NP Hard & NP-Complete Classes (2024)

NP Hard & NP-Complete Classes (1)

  • Design and Analysis of Algorithms
  • Home
  • Basics of Algorithms
  • DAA - Introduction to Algorithms
  • DAA - Analysis of Algorithms
  • DAA - Methodology of Analysis
  • DAA - Time Complexity
  • DAA - Master's Theorem
  • DAA - Space Complexities
  • Divide & Conquer
  • DAA - Max-Min Problem
  • DAA - Merge Sort Algorithm
  • DAA - Strassen's Matrix Multiplication
  • DAA - Karatsuba Algorithm
  • DAA - Towers of Hanoi
  • Greedy Algorithms
  • DAA - Greedy Algorithms
  • DAA - Travelling Salesman Problem
  • DAA - Prim's Minimal Spanning Tree
  • DAA - Kruskal's Minimal Spanning Tree
  • DAA - Dijkstra's Shortest Path Algorithm
  • DAA - Map Colouring Algorithm
  • DAA - Fractional Knapsack
  • DAA - Job Sequencing with Deadline
  • DAA - Optimal Merge Pattern
  • Dynamic Programming
  • DAA - Dynamic Programming
  • DAA - Matrix Chain Multiplication
  • DAA - Floyd Warshall Algorithm
  • DAA - 0-1 Knapsack Problem
  • DAA - Longest Common Subsequence Algorithm
  • DAA - Travelling Salesman Problem using Dynamic Programming
  • Randomized Algorithms
  • DAA - Randomized Algorithms
  • DAA - Randomized Quick Sort Algorithm
  • DAA - Karger's Minimum Cut Algorithm
  • DAA - Fisher-Yates Shuffle Algorithm
  • Approximation Algorithms
  • DAA - Approximation Algorithms
  • DAA - Vertex Cover Problem
  • DAA - Set Cover Problem
  • DAA - Travelling Salesperson Approximation Algorithm
  • Sorting Techniques
  • DAA - Bubble Sort Algorithm
  • DAA - Insertion Sort Algorithm
  • DAA - Selection Sort Algorithm
  • DAA - Shell Sort Algorithm
  • DAA - Heap Sort Algorithm
  • DAA - Bucket Sort Algorithm
  • DAA - Counting Sort Algorithm
  • DAA - Radix Sort Algorithm
  • DAA - Quick Sort Algorithm
  • Searching Techniques
  • DAA - Searching Techniques Introduction
  • DAA - Linear Search
  • DAA - Binary Search
  • DAA - Interpolation Search
  • DAA - Jump Search
  • DAA - Exponential Search
  • DAA - Fibonacci Search
  • DAA - Sublist Search
  • DAA - Hash Table
  • Graph Theory
  • DAA - Shortest Paths
  • DAA - Multistage Graph
  • DAA - Optimal Cost Binary Search Trees
  • Heap Algorithms
  • DAA - Binary Heap
  • DAA - Insert Method
  • DAA - Heapify Method
  • DAA - Extract Method
  • Complexity Theory
  • DAA - Deterministic vs. Nondeterministic Computations
  • DAA - Max Cliques
  • DAA - Vertex Cover
  • DAA - P and NP Class
  • DAA - Cook's Theorem
  • DAA - Hill Climbing Algorithm
  • DAA Useful Resources
  • DAA - Quick Guide
  • DAA - Useful Resources
  • DAA - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

A problem is in the class NPC if it is in NP and is as hard as any problem in NP. A problem is NP-hard if all problems in NP are polynomial time reducible to it, even though it may not be in NP itself.

NP Hard & NP-Complete Classes (3)

If a polynomial time algorithm exists for any of these problems, all problems in NP would be polynomial time solvable. These problems are called NP-complete. The phenomenon of NP-completeness is important for both theoretical and practical reasons.

Definition of NP-Completeness

A language B is NP-complete if it satisfies two conditions

  • B is in NP

  • Every A in NP is polynomial time reducible to B.

If a language satisfies the second property, but not necessarily the first one, the language B is known as NP-Hard. Informally, a search problem B is NP-Hard if there exists some NP-Complete problem A that Turing reduces to B.

The problem in NP-Hard cannot be solved in polynomial time, until P = NP. If a problem is proved to be NPC, there is no need to waste time on trying to find an efficient algorithm for it. Instead, we can focus on design approximation algorithm.

NP-Complete Problems

Following are some NP-Complete problems, for which no polynomial time algorithm is known.

  • Determining whether a graph has a Hamiltonian cycle
  • Determining whether a Boolean formula is satisfiable, etc.

NP-Hard Problems

The following problems are NP-Hard

  • The circuit-satisfiability problem
  • Set Cover
  • Vertex Cover
  • Travelling Salesman Problem

In this context, now we will discuss TSP is NP-Complete

TSP is NP-Complete

The traveling salesman problem consists of a salesman and a set of cities. The salesman has to visit each one of the cities starting from a certain one and returning to the same city. The challenge of the problem is that the traveling salesman wants to minimize the total length of the trip

Proof

To prove TSP is NP-Complete, first we have to prove that TSP belongs to NP. In TSP, we find a tour and check that the tour contains each vertex once. Then the total cost of the edges of the tour is calculated. Finally, we check if the cost is minimum. This can be completed in polynomial time. Thus TSP belongs to NP.

Secondly, we have to prove that TSP is NP-hard. To prove this, one way is to show that Hamiltonian cycle ≤p TSP (as we know that the Hamiltonian cycle problem is NPcomplete).

Assume G = (V, E) to be an instance of Hamiltonian cycle.

Hence, an instance of TSP is constructed. We create the complete graph G' = (V, E'), where

$$E^{'}=\lbrace(i, j)\colon i, j \in V \:\:and\:i\neq j$$

Thus, the cost function is defined as follows −

$$t(i,j)=\begin{cases}0 & if\: (i, j)\: \in E\\1 & otherwise\end{cases}$$

Now, suppose that a Hamiltonian cycle h exists in G. It is clear that the cost of each edge in h is 0 in G' as each edge belongs to E. Therefore, h has a cost of 0 in G'. Thus, if graph G has a Hamiltonian cycle, then graph G' has a tour of 0 cost.

Conversely, we assume that G' has a tour h' of cost at most 0. The cost of edges in E' are 0 and 1 by definition. Hence, each edge must have a cost of 0 as the cost of h' is 0. We therefore conclude that h' contains only edges in E.

We have thus proven that G has a Hamiltonian cycle, if and only if G' has a tour of cost at most 0. TSP is NP-complete.

Advertisem*nts

';adpushup.triggerAd(ad_id); });

NP Hard & NP-Complete Classes (2024)
Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6270

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.