Lecture-9_P_NP
Lecture-9_P_NP
• NP‐hard and NP‐complete are two categories of problems in computer science and
mathematics that are known to be difficult to solve efficiently.
• NP (nondeterministic polynomial time) is a complexity class that represents problems
that can be verified in polynomial time, but not necessarily solved in polynomial time.
• NP‐hard problems, on the other hand, are problems that are at least as hard as the
hardest problems in NP. In other words, if an NP‐hard problem could be solved in
polynomial time, then all problems in NP could also be solved in polynomial time.
• NP‐complete problems are a subset of NP‐hard problems that are themselves in NP.
• This means that if a polynomial time algorithm could be found for one NP‐complete
problem, then a polynomial time algorithm could be found for all problems in NP.
• NP‐complete problems are therefore considered to be the most difficult problems in
NP.
• Examples of NP‐hard problems include the traveling salesman problem and the
knapsack problem.
• Examples of NP‐complete problems include the Boolean satisfiability problem.
• Many important problems in computer science and mathematics, such as
scheduling problems and optimization problems, are known to be NP‐hard or NP‐
complete.
• Example of a Boolean satisfiability problem:
• The Boolean satisfiability problem (often abbreviated as SAT) is a fundamental • Given the Boolean formula F = (A OR B) AND (NOT B OR C) AND (NOT
problem in computer science and mathematics that involves determining whether
A OR NOT C), where A, B, and C are Boolean variables, we want to
there exists an assignment of Boolean values (true or false) to a set of variables
that makes a given Boolean formula true. determine whether there exists an assignment of true or false values
• In other words, given a Boolean formula in conjunctive normal form (CNF), the SAT to the variables that makes the formula true.
problem asks whether there exists a combination of true and false assignments to • To solve this problem, we can create a truth table that enumerates all
the variables in the formula that satisfies the formula (i.e., makes it evaluate to possible assignments of true and false values to the variables.
true). If such an assignment exists, the formula is said to be satisfiable; otherwise, • Then, we evaluate the formula for each assignment and check
it is unsatisfiable.
whether any assignment makes the formula evaluate to true.
• The SAT problem is NP‐complete, meaning that it is believed to be very difficult to
solve in the worst case for large instances of the problem, and no efficient • Here is the truth table for this problem:
algorithm is known that can solve all instances of the problem quickly.
Nonetheless, the SAT problem is widely studied and has many practical
applications in fields such as automated reasoning, software verification, and
electronic design automation.
F = (A OR B) AND (NOT B OR C) AND
A B C
(NOT A OR NOT C)
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 0
• As we can see, only the second row of the truth table has a
value of 1 for the formula, which corresponds to the
assignment A=0, B=0, C=1.
• Therefore, the Boolean formula F is satisfiable, and there exists
at least one assignment of true or false values to the variables
that makes the formula true.