Analysis_of_Algorithm_assignment
Analysis_of_Algorithm_assignment
Analysis of Algorithms
Assignment 5
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:
• 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.
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.
Conclusion Since:
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.
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.
• 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.
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:
Since checking these conditions takes linear time in terms of the number of
vertices and edges, the Hamiltonian Cycle Problem is in NP.
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.