Ads &aa Unit 5
Ads &aa Unit 5
Ads &aa Unit 5
3. NP-Complete Problems
- Definition: A problem is NP-Complete if:
1. It is in NP (the solution can be verified in polynomial time).
2. It is NP-Hard, meaning any NP problem can be reduced to it in polynomial time.
- Key Point: If an NP-Complete problem can be solved in polynomial time, then all NP
problems can be solved in polynomial time, i.e., P = NP.
4. Cook’s Theorem
- Cook’s Theorem (1971) is a foundational result in computational complexity theory. It was
the first to show that a problem, specifically Boolean Satisfiability Problem (SAT), is NP-
Complete.
- Implication: Cook's Theorem established the concept of NP-Complete problems and laid the
foundation for showing that other problems (like 3-SAT, Knapsack, etc.) are NP-Complete.
Essentially, it provided a universal method for reducing any NP problem to another NP-
Complete problem in polynomial time.
6. Summary of Relationships
- NP-Hard: Problems as hard as NP problems but not necessarily in NP (no efficient solution
or even verification).
- NP-Complete: Problems in NP (verifiable in polynomial time) and as hard as the hardest NP
problems (any NP problem can be transformed into an NP-Complete problem).
- If you solve an NP-Complete problem in polynomial time, then you solve all NP problems
in polynomial time, and it would imply that P = NP—a major unsolved question in computer
science.
Visual Summary
- P ⊆ NP
- NP-Complete ⊆ NP ⊆ NP-Hard
- NP-Hard: Not necessarily in NP but as hard as NP problems.
- NP-Complete: Problems that are both in NP and NP-Hard.
Cook’s Theorem:
Cook's Theorem is one of the most important results in computer science, and it establishes
the concept of NP-Completeness. In simple terms, it tells us that Boolean Satisfiability
Problem (SAT) is the first known NP-Complete problem.
1. What is SAT?
The Boolean Satisfiability Problem (SAT) asks whether a logical expression (a collection of
AND, OR, and NOT operations) can be made true by assigning values (true/false) to its
variables.
For example:
- (x1 OR NOT x2) AND (x2 OR x3)
The question is: can you assign true/false to the variables (x1), (x2), and (x3) so that the
whole expression evaluates to true?
In this case:
- If we set ( x1 = {true} ), ( x2 = {false} ), and ( x3 = {true} ), the expression becomes true.
2. What does NP mean?
A problem is in NP if, given a solution, you can verify whether it is correct in polynomial
time (efficient time).
For SAT:
- If someone gives you a set of variable assignments (like x1 = {true} , x2 = {false} ), and
( x3 = {true} )), you can easily check whether the expression becomes true or not in
polynomial time. So, SAT is in NP.
3. What is NP-Complete?
- A problem is NP-Complete if:
1. It is in NP.
2. Every other NP problem can be transformed (or reduced) into it in polynomial time.
This means that solving one NP-Complete problem efficiently (in polynomial time) would
allow you to solve all NP problems efficiently.
4. What Does Cook’s Theorem Say?
Cook’s Theorem says that SAT is NP-Complete. It means:
1. SAT is in NP (as we discussed).
2. Every other NP problem can be reduced to SAT in polynomial time.
5. Why Is This Important?
This was the first time someone (Stephen Cook) showed that there exists a problem (SAT)
that is as hard as any problem in NP. If we can solve SAT efficiently, we can solve every NP
problem efficiently, which means P = NP (a huge question in computer science).
E
Problem Statement:
Let’s say we are asked: Can you color this graph using 3 colors or fewer?
1. Step 1: Try to Color the Graph with 3 Colors
We need to assign colors to the vertices such that:
- No two connected vertices (like A and B) get the same color.
2. Step 2: Color the Graph
- Let’s assign Color 1 to vertex A.
- Vertex B is adjacent to A, so it can’t have Color 1. We give it Color 2.
- Vertex C is adjacent to both A and B, so it needs a different color. We give it Color 3.
- Vertex D is adjacent to B and C, so we can give it Color 1 (since it’s not adjacent to A,
which already has Color 1).
- Vertex E is adjacent to C, so it can’t have Color 3. We can assign it Color 2 (since it’s not
adjacent to B, which has Color 2).
3. Step 3: Check if the Graph is Properly Colored
After coloring the graph, here’s what we have:
- A = Color 1
- B = Color 2
- C = Color 3
- D = Color 1
- E = Color 2
No two connected vertices have the same color, so this is a valid coloring with 3 colors.
4. Step 4: Answer
Since we successfully colored the graph with 3 colors, the answer to the CNDP for ( k = 3 )
is yes.
5. Why is CNDP NP-Hard?
The Chromatic Number Decision Problem is NP-Hard because:
- Verification: If someone gives you a colored graph, it’s easy to check if the coloring is
correct (just check if adjacent vertices have different colors). This can be done in polynomial
time.
- Hardness: However, finding the chromatic number (the minimum number of colors) is
difficult because you have to try different combinations of color assignments, especially for
large graphs.
Since we don’t know of any efficient way to solve CNDP for large graphs, it is classified as
NP-Hard.
6. Key Points About the Chromatic Number Decision Problem (CNDP)
- Input: A graph and a number ( k ).
- Output: "Yes" if the graph can be colored with ( k ) colors or fewer, and "No" if it cannot be.
- NP-Hardness: While verifying a coloring is easy, finding the chromatic number is
computationally hard, which is why CNDP is NP-Hard.
7. Why Is This Problem Important?
Graph coloring problems like CNDP are important in areas like:
- Scheduling: Assigning time slots to tasks or exams without conflicts (e.g., no two tasks
sharing the same resource at the same time).
- Map Coloring: Ensuring that no two neighboring regions on a map share the same color.
- Resource Allocation: Assigning resources such that no two conflicting tasks use the same
resource.
Since it’s NP-Hard, CNDP is difficult to solve efficiently for large graphs, which means
finding the chromatic number is a computational challenge in many practical applications.
Traveling Salesperson Decision Problem (TSP) –
The Traveling Salesperson Problem (TSP) is a famous NP-Hard problem in computer
science. It asks a very straightforward question about finding the shortest possible route for a
salesperson who needs to visit several cities and return to the starting point.
1. What is the TSP Problem?
In the Traveling Salesperson Problem (TSP), you're given a list of cities and the distances
between every pair of cities. The goal is to find the shortest route that:
- Starts at one city,
- Visits each city exactly once,
- And returns to the starting city.
2. What is the Traveling Salesperson Decision Problem (TSP Decision Problem)?
The TSP Decision Problem asks a yes-or-no question:
- Given a set of cities, a set of distances between them, and a number ( k ), is there a route
that visits all the cities exactly once and has a total distance of ( k ) or less?
In simple terms, it asks whether you can find a tour of the cities where the total distance does
not exceed a specified number ( k ).
3. Why is the TSP Decision Problem NP-Hard?
The TSP Decision Problem is NP-Hard because:
- Verification: If someone gives you a solution (a route), it’s easy to check whether the total
distance of that route is less than or equal to ( k ). You just add up the distances. This can be
done in polynomial time.
- Hardness: Finding the actual shortest route (or even determining if a route exists within
distance ( k )) is very difficult. For large sets of cities, the number of possible routes grows
exponentially, and there’s no known efficient algorithm to solve the problem in polynomial
time.
Because finding the solution is computationally hard, TSP is classified as NP-Hard.
4. Example of TSP Decision Problem
Let’s go through a simple example to understand how the TSP Decision Problem works.
Example:
Imagine a salesperson needs to visit 4 cities: A, B, C, and D, and the distances between them
are as follows:
- Distance from A to B: 10 km
- Distance from A to C: 15 km
- Distance from A to D: 20 km
- Distance from B to C: 35 km
- Distance from B to D: 25 km
- Distance from C to D: 30 km
Problem Statement:
The question is: Is there a route that visits all the cities (A, B, C, and D) exactly once and
returns to the starting point, with a total distance of 80 km or less?
1. Step 1: Consider Different Routes
To solve this problem, you would have to check different possible routes and see if any of
them have a total distance of 80 km or less.
Some possible routes are:
- Route 1: A → B → C → D → A
- Route 2: A → B → D → C → A
- Route 3: A → C → B → D → A
2. Step 2: Calculate the Total Distance
- For Route 1 (A → B → C → D → A):
- A → B = 10 km
- B → C = 35 km
- C → D = 30 km
- D → A = 20 km
- Total = 10 + 35 + 30 + 20 = 95 km
- For Route 2 (A → B → D → C → A):
- A → B = 10 km
- B → D = 25 km
- D → C = 30 km
- C → A = 15 km
- Total = 10 + 25 + 30 + 15 = 80 km
In this case, Route 2 has a total distance of exactly 80 km.
3. Step 3: Answer
Since we found a route (Route 2) that visits all the cities and returns to the starting point
with a total distance of 80 km, the answer to the TSP Decision Problem for ( k = 80 ) is yes.
5. Key Points About the Traveling Salesperson Decision Problem (TSP Decision Problem)
- Input: A set of cities, the distances between them, and a number ( k ).
- Output: "Yes" if there’s a route that visits all cities exactly once and returns to the starting
point with a total distance of ( k ) or less, otherwise "No."
- NP-Hardness: While it’s easy to verify a solution (checking if a route’s total distance is
within the limit), finding the route itself is hard because the number of possible routes grows
exponentially with the number of cities.
6. Why Is TSP Important?
The Traveling Salesperson Problem is important in many real-world applications, including:
- Logistics and Delivery: Finding the most efficient routes for delivering goods.
- Manufacturing: Optimizing the order of operations for machines in a factory.
- Computer Networks: Efficiently routing data between nodes in a network.
Since it’s NP-Hard, finding efficient solutions for large-scale TSP instances is challenging,
and this is why it’s studied extensively in optimization and computer science.
Option 1: Assign Task 1 and Task 4 to Processor 1, and Task 2 and Task 3 to Processor 2.
Even for small examples, we had to try different assignments and check the makespan for
each one. In larger problems with more tasks and processors, this process becomes infeasible
without a good heuristic or approximation algorithm.