ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Design and Analysis of Algorithms
    COMP3138
    Progress0 / 53 topics
    Topics
    1. Introduction to Algorithm Design2. Data Structures3. Efficiency in Algorithms4. Analysis of Algorithms5. Mathematical Review6. Mathematical Analysis of Algorithms7. Types of Functions8. Order of Growth9. Asymptotic Notations10. Sorting Algorithms11. Selection Sort Algorithm12. Example and Analysis of Selection Sort13. Insertion Sort Algorithm14. Divide and Conquer Algorithms15. Merge Sort Algorithm16. Quick Sort Algorithm17. Bucket Sort Algorithm18. Radix Sort Algorithm19. Counting Sort Algorithm20. Heap Sort Basics21. Heap Algorithms22. Heap Properties and Examples23. Heap Operations24. Heap Sort Algorithm Analysis25. Heap Insertion and Deletion26. Tree Based Algorithms and Hashing27. Red Black Tree Basics28. Binary Search Tree Basics29. Tree Searching Algorithms30. Analysis of Tree Searching Algorithms31. Analysis of Insertion and Deletion in BST32. Hashing Basics33. Examples of Hash Functions34. Analysis of Collision Resolution Techniques35. Dynamic Programming36. 0-1 Knapsack Problem37. Fractional Knapsack Problem38. Longest Common Subsequence39. Shortest Path Finding40. Matrix Chain Multiplication41. Assembly Line Chain Problem42. Greedy Algorithms43. Prim's Algorithm44. Kruskal's Algorithm45. Dijkstra's Algorithm46. Huffman Coding47. NP-Completeness48. Polynomial Time Verification49. Reducibility50. NP-Completeness Proofs51. Randomized Algorithms52. Particle Swarm Optimization53. Genetic Algorithms
    COMP3138›NP-Completeness Proofs
    Design and Analysis of AlgorithmsTopic 50 of 53

    NP-Completeness Proofs

    9 minread
    1,454words
    Intermediatelevel

    NP-Completeness Proofs

    An NP-completeness proof is used to show that a problem is both in NP and NP-hard. These two properties are crucial in establishing that a problem is NP-complete:

    1. In NP: A problem is in NP if, given a solution, we can verify whether it is correct in polynomial time.
    2. NP-hard: A problem is NP-hard if every problem in NP can be reduced to it in polynomial time.

    A problem is NP-complete if it satisfies both of these properties. Let's break down how we go about proving that a problem is NP-complete.

    Steps to Prove NP-Completeness

    To prove that a problem PPP is NP-complete, we follow these general steps:

    1. Prove that the problem is in NP:

      • We need to show that the problem is in NP, which means that given a candidate solution, we can verify whether it’s correct in polynomial time.
      • This step is typically straightforward. For example, in the Traveling Salesman Problem (TSP), given a tour of cities, you can check in polynomial time if the tour visits every city exactly once and whether the total distance is less than a given threshold.
    2. Prove that the problem is NP-hard:

      • To show that a problem is NP-hard, we reduce a known NP-complete problem to PPP in polynomial time.
      • If we can show that a known NP-complete problem can be transformed into PPP, we can conclude that PPP is NP-hard. This is because if we could solve PPP efficiently, we could solve the NP-complete problem efficiently as well, which would imply that P = NP.
      • The reduction is usually done from a well-established NP-complete problem such as SAT, 3-SAT, Clique, Vertex Cover, or Knapsack.

    Detailed Steps in NP-Completeness Proofs

    Step 1: Proving the Problem is in NP

    For any problem PPP to be in NP, we need to show that, given a candidate solution, it can be verified in polynomial time. This step is typically straightforward and involves constructing a verification algorithm that checks if the proposed solution satisfies the conditions of the problem.

    Example: For the Subset Sum Problem, given a subset of integers, we need to verify if the sum of the subset equals a given target sum. The verification process involves summing the integers in the subset and checking if the result matches the target. This can clearly be done in polynomial time.

    Step 2: Proving the Problem is NP-Hard

    To prove that a problem is NP-hard, we must show that we can reduce an existing NP-complete problem to the given problem PPP. This is typically done in one of the following ways:

    1. Choosing a Known NP-Complete Problem: We start by picking a well-known NP-complete problem that has already been proven to be in NP and NP-hard. Common choices include:

      • 3-SAT (Boolean satisfiability)
      • Clique (Finding a complete subgraph in a graph)
      • Vertex Cover (Finding the smallest set of vertices that touch all edges in a graph)
      • Subset Sum (Determining if there is a subset of integers that sum to a given value)
      • Knapsack (Maximizing the value of items taken while adhering to a weight limit)
    2. Reducing the Problem: The key step in the proof is the reduction: transforming an instance of the known NP-complete problem into an instance of the problem PPP in polynomial time. The reduction must preserve the solution; in other words, a solution to the transformed problem must correspond to a solution to the original problem.

    3. Proving Correctness of the Reduction: After performing the reduction, we need to show that solving the transformed problem will allow us to solve the original NP-complete problem.

    Example: Proving 3-SAT is NP-Complete

    Let’s walk through the proof that 3-SAT is NP-complete as an example.

    1. Prove that 3-SAT is in NP:

      • Given a proposed truth assignment for the boolean variables, we can easily check whether this assignment satisfies the 3-SAT formula. This check involves going through all the clauses of the formula and verifying that each clause is true under the given assignment. This can be done in polynomial time.
    2. Prove that 3-SAT is NP-Hard:

      • To prove that 3-SAT is NP-hard, we need to reduce a known NP-complete problem to 3-SAT. One of the most common reductions is from SAT (the general satisfiability problem) to 3-SAT.

      • The SAT problem allows clauses of any size (e.g., a clause could have more than 3 literals). To reduce SAT to 3-SAT, we need to ensure that every clause has exactly 3 literals. We can do this by introducing new variables and transforming larger clauses into a series of smaller clauses, each of which has 3 literals. This is known as a clause transformation.

      • For example:

        • If a clause in SAT is (x∨y∨z∨w)(x \vee y \vee z \vee w)(x∨y∨z∨w), we can break it into two clauses in 3-SAT as follows:
          • (x∨y∨z)(x \vee y \vee z)(x∨y∨z)
          • neg z \vee w) $$
        • The reduction preserves satisfiability because a solution to the original SAT formula will also satisfy the transformed 3-SAT formula and vice versa.

    Thus, by reducing SAT to 3-SAT in polynomial time, we show that 3-SAT is NP-hard.

    Example of a Full NP-Completeness Proof: Vertex Cover Problem

    Let’s go through a detailed proof of NP-completeness for the Vertex Cover Problem.

    Problem: Given a graph G=(V,E)G = (V, E)G=(V,E) and an integer kkk, is there a set of kkk vertices such that every edge in GGG is incident to at least one vertex in the set?

    Step 1: Prove that Vertex Cover is in NP

    • Given a set of kkk vertices, we can check in polynomial time whether every edge in the graph has at least one endpoint in the set. This involves going through each edge and verifying if at least one of its endpoints is in the set. This check can be done in linear time relative to the number of edges, so verifying the solution is clearly in NP.

    Step 2: Prove that Vertex Cover is NP-Hard

    • To prove that the Vertex Cover Problem is NP-hard, we reduce an already known NP-complete problem to it. A common choice is to reduce from the 3-SAT Problem to Vertex Cover.
    Reduction from 3-SAT to Vertex Cover
    • 3-SAT Instance: Given a 3-SAT formula with mmm clauses and nnn variables, we want to determine if there is a satisfying assignment to the variables.

    • Graph Construction: We construct a graph based on the clauses and variables in the 3-SAT formula:

      • For each variable, create two vertices, one for the literal and one for its negation.
      • For each clause in the 3-SAT formula, create a triangle in the graph that represents the literals in that clause. Each vertex in the triangle corresponds to a literal in the clause.
    • Vertex Cover Construction: The goal is to find a set of kkk vertices such that every edge in the graph is covered by at least one vertex in the set. If we choose k=2n+mk = 2n + mk=2n+m, the vertex cover will correspond to choosing a satisfying assignment for the 3-SAT formula.

    • Why the Reduction Works: The reduction works because if a satisfying assignment exists, there will be a way to select kkk vertices that cover all the edges in the graph, reflecting the assignment’s truth values. Conversely, a valid vertex cover corresponds to a satisfying assignment for the 3-SAT formula.

    Thus, by reducing 3-SAT to the Vertex Cover Problem, we prove that Vertex Cover is NP-hard.

    Conclusion

    To prove that a problem is NP-complete, we need to demonstrate two things:

    1. The problem is in NP (its solution can be verified in polynomial time).
    2. The problem is NP-hard (we can reduce a known NP-complete problem to it in polynomial time).

    A typical NP-completeness proof involves selecting an appropriate known NP-complete problem, performing a polynomial-time reduction, and verifying that the solution to the reduced problem corresponds to a solution to the original problem. By following this approach, we can show that a problem is NP-complete and therefore likely does not have an efficient solution unless P=NPP = NPP=NP.

    Previous topic 49
    Reducibility
    Next topic 51
    Randomized Algorithms

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time9 min
      Word count1,454
      Code examples0
      DifficultyIntermediate