0% found this document useful (0 votes)
23 views

Analysis_of_Algorithm_assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Analysis_of_Algorithm_assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Florida International University

Analysis of Algorithms

Assignment 5

Instructor: Prof. S.S. Iyengar


Student: Nhat Nguyen Minh Hoang - 6525096
Question 1
(2 Points) Question 1.

a. Prove that the satisfiability of Boolean formula is NP-Complete.


b. Prove that the Circuit-Satisfiability Problem belongs to the class NP.

Solution 1
1A. Proof that Satisfiability (SAT) is NP-Complete
To prove that the Satisfiability Problem (SAT) is NP-Complete, we need to
show the following two properties:

1. SAT is in NP: We need to demonstrate that SAT is in NP, meaning


that given a proposed solution, we can verify its correctness in polynomial
time.
2. SAT is NP-Hard: We need to show that every problem in NP can be
reduced to SAT in polynomial time.

1. SAT is in NP The SAT problem involves determining whether there


exists an assignment of truth values to variables in a Boolean formula such that
the formula evaluates to true. The formula is given in Conjunctive Normal Form
(CNF), which is a conjunction of clauses, where each clause is a disjunction of
literals (variables or their negations).
To prove that SAT is in NP, we need to show that if we are given a candidate
solution (a specific assignment of truth values to the variables), we can check
whether it satisfies the formula in polynomial time.

• Given a truth assignment, we can evaluate each clause in the CNF formula
and check whether the entire formula evaluates to true.
• Each clause involves a small, fixed number of variables, so evaluating a
single clause takes constant time.
• Evaluating all the clauses takes linear time with respect to the number of
clauses, which is polynomial in the size of the formula.

Thus, given a candidate solution, we can verify whether it satisfies the for-
mula in polynomial time. Therefore, SAT is in NP.

2. SAT is NP-Hard To show that SAT is NP-Hard, we need to demonstrate


that every problem in NP can be reduced to SAT in polynomial time.
We perform a reduction from the already known NP-Complete problem 3-
SAT to SAT. The 3-SAT problem is a special case of SAT where each clause
contains exactly 3 literals. Since 3-SAT is NP-Complete, showing that 3-SAT
reduces to SAT implies that SAT is NP-Hard.

1
• Given any instance of 3-SAT (a Boolean formula in CNF where each clause
contains exactly 3 literals), we can treat this as a general SAT problem
because every 3-SAT formula is also a SAT formula.
• Therefore, we can trivially reduce a 3-SAT instance to a SAT instance.

Since 3-SAT is NP-Complete, and we can reduce 3-SAT to SAT in polynomial


time (in fact, 3-SAT is just a restricted version of SAT), it follows that SAT is
NP-Hard.

Conclusion Since:

• SAT is in NP, and


• SAT is NP-Hard (because 3-SAT can be reduced to SAT),
we can conclude that SAT is NP-Complete.
1B. Proving that the Circuit-Satisfiability Problem belongs to the
class NP
The Circuit-Satisfiability Problem asks whether there exists a truth assign-
ment to the inputs of a given Boolean circuit such that the output of the circuit
is true.
To prove that the Circuit-Satisfiability Problem belongs to NP, we must
show that a proposed solution can be verified in polynomial time.

1. Start by assigning the truth values to the inputs of the circuit.


2. Propagate these values through the circuit by evaluating each gate (AND,
OR, NOT, etc.) based on the assigned truth values for the inputs.
3. Check the output of the circuit. If the output is true, the assignment is
valid.

Since evaluating the circuit and checking the output takes time proportional
to the size of the circuit (which is polynomial in the size of the input circuit),
the verification can be done in polynomial time.
Thus, the Circuit-Satisfiability Problem is in NP because the proposed so-
lution (a truth assignment to the inputs) can be verified in polynomial time.

Question 2
(2 Points) Question 2.

a. Describe the Hamiltonian cycle with an example.


b. Prove that the Hamiltonian cycle problem is NP-Complete.

2
Solution 2
2A. Hamiltonian Cycle - with an example
A Hamiltonian cycle in a graph is a cycle that visits each vertex exactly once
and returns to the starting vertex, forming a closed loop. In other words, it is
a path that starts at a vertex, visits every other vertex exactly once, and then
returns to the starting vertex, creating a cycle.

Key Properties
• The cycle must pass through every vertex once and only once.
• It must return to the starting vertex.
• It is different from an Eulerian cycle, which requires the cycle to traverse
each edge exactly once.

Example Consider a graph with 5 vertices labeled A, B, C, D, and E, where


the edges are:
• A is connected to B, C, and D.
• B is connected to A, C, and E.

• C is connected to A, B, and E.
• D is connected to A and E.
• E is connected to B, C, and D.
A possible Hamiltonian cycle in this graph could be:

A→B→C→E→D→A

This cycle visits every vertex exactly once and returns to the starting vertex
A, forming a Hamiltonian cycle.

Importance Finding a Hamiltonian cycle is a well-known NP-Complete prob-


lem, meaning it is computationally difficult to determine whether such a cycle
exists in a general graph, especially for large graphs.
2B. Proving the Hamiltonian Cycle Problem is NP-Complete
To prove that the Hamiltonian Cycle Problem is NP-Complete, we need to
show two things:

• The Hamiltonian Cycle Problem is in NP.


• The Hamiltonian Cycle Problem is NP-Hard.

3
Step 1: Proving that the Hamiltonian Cycle Problem is in NP A
problem is in NP if, given a proposed solution, we can verify whether it is a
valid solution in polynomial time. For the Hamiltonian Cycle Problem, given a
cycle (a specific ordering of vertices), we can check in polynomial time whether
it:

• Visits every vertex exactly once.


• Returns to the starting vertex.

• Ensures each edge in the cycle exists in the graph.

Since checking these conditions takes linear time in terms of the number of
vertices and edges, the Hamiltonian Cycle Problem is in NP.

Step 2: Proving that the Hamiltonian Cycle Problem is NP-Hard


To prove NP-Hardness, we need to reduce a known NP-Complete problem to
the Hamiltonian Cycle Problem. The Traveling Salesman Problem (TSP) is a
known NP-Complete problem, and we will reduce it to the Hamiltonian Cycle
Problem.

Reduction from TSP to the Hamiltonian Cycle Problem


• TSP Definition: Given a complete graph where each edge has a cost asso-
ciated with it, the TSP asks whether there exists a cycle that visits every
vertex exactly once and has a total cost less than or equal to a specified
value.
• Reduction Steps:

– We take an instance of the TSP and construct a new graph.


– In the Hamiltonian Cycle Problem, the cycle must visit every vertex
exactly once and return to the starting point. Thus, we can reduce
the TSP to the Hamiltonian Cycle Problem by setting the cost of
every edge in the TSP graph to be equal.
– Now, instead of considering the costs, we simply need to check if a
cycle exists that visits each vertex exactly once and returns to the
starting vertex, as we would in the Hamiltonian Cycle Problem.

Transformation If there exists a Hamiltonian cycle in this transformed graph,


then there exists a solution to the TSP with the given constraints. The trans-
formation takes polynomial time, and thus, the Hamiltonian Cycle Problem is
NP-Hard because TSP is NP-Complete.

4
Conclusion Since we have shown that:
• The Hamiltonian Cycle Problem is in NP.
• The Hamiltonian Cycle Problem is NP-Hard (by reducing TSP to it).
We can conclude that the Hamiltonian Cycle Problem is NP-Complete.

You might also like