0% found this document useful (0 votes)
40 views28 pages

Daa Unit5

The document discusses complexity classes in computer science, including P, NP, CoNP, NP-hard, and NP-complete, which categorize problems based on their solvability and verification time. It explains the characteristics and examples of each class, highlighting the significance of the Boolean satisfiability problem (SAT) and the Cook-Levin theorem, which establishes SAT as NP-complete. The document also outlines the definitions of relevant terms such as Boolean variables, literals, clauses, and CNF form.

Uploaded by

ancybjohn26
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)
40 views28 pages

Daa Unit5

The document discusses complexity classes in computer science, including P, NP, CoNP, NP-hard, and NP-complete, which categorize problems based on their solvability and verification time. It explains the characteristics and examples of each class, highlighting the significance of the Boolean satisfiability problem (SAT) and the Cook-Levin theorem, which establishes SAT as NP-complete. The document also outlines the definitions of relevant terms such as Boolean variables, literals, clauses, and CNF form.

Uploaded by

ancybjohn26
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/ 28

ardidate bet -te

tRemaeimiZ
makean, and
Candidatk
de6n
each viaw nko oweuy,ysu
Can
eit a
fos.m king Tondomiz The
Gusteat but Gdidat
adtdate

best

Gnit bart cdidae


Gadidete,ptot te
bet al Candidate
adidote ound.t
te bust

Rdomizp (adaty
bat_ondidats =Candidad oJnbl

GdidakG] is betto then bust Gandidat ten


iP
best Gudidae rCendidats
Yetasa bet cditht
fa ant &ores:7e,9o, 85, &",95

3- Gmpa
bad

a
clunent
ay
kx Slants into too sab- actadg
tfan Pvet. The bub-ayg
Quwelegt
ten

wcle Bot

hyát ebmust) Quwcle sot an

oY
Padail de &ot an

elem.t a te pvot ,admzd


t laat dian

pohsmona.
PadlemiZa_eule bat

DadomiedCulesst (a,staot, Piet hdea-1)


DandomZad Culesort(aor, Piat_indee tl ,cod)

Piet-indes Dadanlhat,tnd)
Swap aro Pnt- inde wit ar endJ
tetatn paht (a01, t-t,end)
Prt din (aor, Steot,end)
pirt cas[end
i Stadt-)
rj=s taot to end-i do
ax 03L Plvot then

Sanp an J oik
piet

Tandom pivet
Calls
am asund
6

Pot t Nmld.

avoy 2i1, 6,3, 5,34

5. 3. 4
oviP
3
pivet damst (e) auita tat slemt (t)
Any 12 G4 $ 3&
bParien

Pvst ndex. lety we

*.Aoap te pivet slornt () oite lait samat (3)


Avy
Pvet and ty

Asted Aubaatays ,1, 2';3, 4, 4,5,&J

a piet

T 2 3
P

andl eemets gat tian te pit


ouitR

T Slamat

['2.,46, 4,7,
12 ! 4

cheole
S 3

3 &

L'sbany

Arely panti t pit


2 3 &
Not Sored
claok pin t
4
/ i sCHart
t J-i)
=tart

3 s 4
72

2135 4&

23S 4 16
23s927
2,3 S
P

P
fr korg 2,3, 4,s

| 2 34 S 6 1 &
1

oc CuoenCes

Pateon ant sabatigs tR Ter t

dat

te match
Pateon

e
hash valas match, ten Canp

te match.

hogh

lex E A Bcc DDAE FG


DD
Tect: aagab
Patten: aab

Sranple
a
Test . Cea cc a qe dba.
Patteon dba Aimphaty
lo

m=3 (yk t petkr) 37

patdon i-9

Pat m d b a
m-l Pl27xt
fatthn bal vale
db'a
4xlb+2xto41x1oehebae
vale Valu

) 4oo+26t 1: 42} we Can le 12

Hyh Gde Bx Patton dba=hsl


Gd Clanckn
2
CC a 3x1o t 3x0tIxlo° = 33 )
Cac ’ aat3 1- 3x1o xIo+ 3x1b (a) 3x14Ixtot
3Xlo
facton. 3 lo +3 = 313 )313
ace |X|ot 3x143ylo° 1eot ot 3 [33
loot

Caa 3 x164x|o! +X1o° = 3oot lotl 3I)

dba , xbt2yo4x 1o oott).e42/


mateh und

Noe rgupunoug hit


te mateh
Cue a

vab ddt)

t heçh
4alee olm) ime
oln-mt)
f0(ntm)
o(ntm)

Rat, kopltat, Patks):


ongta pattsn

hat inda
A

Ainima

Gouris emphyJ
Minimum koke
be no Edy blw
ond b
Aveske Ges anandinsced gnphie a kuba

Arprimation Ahaitkm:)Gregy Asne


)
ND ue

APPRoY- VERTEX -Coyes


Tniialy value
C hal es nall

do

ead whila
Cz

r2f t),(oa) (ua), (6x), G.4), (s,i), o), 6+).


Ac:be
£
in
it
Ped

AplYCheoke an

J4p2) msye all


X

F'foa),t),.(a), (or), G), (s), 0n), aß;


Neot ue
X
Ea),(:), (h4) (a,s), (r.o), (oo) ona.

NeDt cue

veat baue bdene e (31)

(s) h E

3
rfha),Cow,oso};

X
(D
null,

". 9inimam
P, NP, CoNP, NP hard and NP complete | Complexity Classes

In computer science, there exist some problems whose solutions are not yet found,
the problems are divided into classes known as Complexity Classes. In complexity
theory, a Complexity Class is a set of problems with related complexity. These classes
help scientists to group problems based on how much time and space they require to solve
problems and verify the solutions. It is the branch of the theory of computation that deals
with the resources required to solve a problem.
The common resources are time and space, meaning how much time the algorithm takes
to solve a problem and the corresponding memory usage.
 The time complexity of an algorithm is used to describe the number of steps required
to solve a problem, but it can also be used to describe how long it takes to verify the
answer.
 The space complexity of an algorithm describes how much memory is required for
the algorithm to operate.
Complexity classes are useful in organising similar types of problems.

Types of Complexity Classes


This article discusses the following complexity classes:
1. P Class
2. NP Class
3. CoNP Class
4. NP-hard
5. NP-complete
P Class
The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic
machine in polynomial time.
Features:
 The solution to P problems is easy to find.
 P is often a class of computational problems that are solvable and tractable.
Tractable means that the problems can be solved in theory as well as in practice. But
the problems that can be solved in theory but not in practice are known as
intractable.
This class contains many problems:
1. Calculating the greatest common divisor.
2. Finding a maximum matching.
3. Merge Sort
NP Class
The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection
of decision problems that can be solved by a non-deterministic machine in polynomial
time.
Features:
 The solutions of the NP class are hard to find since they are being solved by a non-
deterministic machine but the solutions are easy to verify.
 Problems of NP can be verified by a Turing machine in polynomial time.
Example:
Let us consider an example to better understand the NP class. Suppose there is a
company having a total of 1000 employees having unique employee IDs. Assume that
there are 200 rooms available for them. A selection of 200 employees must be paired
together, but the CEO of the company has the data of some employees who can’t work in
the same room due to personal reasons.
This is an example of an NP problem. Since it is easy to check if the given choice
of 200 employees proposed by a coworker is satisfactory or not i.e. no pair taken from
the coworker list appears on the list given by the CEO. But generating such a list from
scratch seems to be so hard as to be completely impractical.
It indicates that if someone can provide us with the solution to the problem, we can find
the correct and I ncorrect pair in polynomial time. Thus for the NP class problem,
the answer is possible, which can be calculated in polynomial time.
This class contains many problems that one would like to be able to solve effectively:
1. Boolean Satisfiability Problem (SAT).
2. Hamiltonian Path Problem.
3. Graph coloring.
Co-NP Class
Co-NP stands for the complement of NP Class. It means if the answer to a problem in
Co-NP is No, then there is proof that can be checked in polynomial time.
Features:
 If a problem X is in NP, then its complement X’ is also in CoNP.
 For an NP and CoNP problem, there is no need to verify all the answers at once in
polynomial time, there is a need to verify only one particular answer “yes” or “no”
in polynomial time for a problem to be in NP or CoNP.
Some example problems for CoNP are:
1. To check prime number.
2. Integer Factorization.

NP-hard class
An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of
problems such that every problem in NP reduces to NP-hard.
Features:
 All NP-hard problems are not in NP.
 It takes a long time to check them. This means if a solution for an NP-hard problem
is given then it takes a long time to check whether it is right or not.
 A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-
time reduction from L to A.
Some of the examples of problems in Np-hard are:
1. Halting problem.
2. Qualified Boolean formulas.
3. No Hamiltonian cycle.

NP-complete class
A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the
hard problems in NP.
Features:
 NP-complete problems are special as any problem in NP class can be transformed or
reduced into NP-complete problems in polynomial time.
 If one could solve an NP-complete problem in polynomial time, then one could also
solve any NP problem in polynomial time.
Some example problems include:
1. Hamiltonian Cycle.
2. Satisfiability.
3. Vertex cover.

Complexity
Characteristic feature
Class

P Easily solvable in polynomial time.

NP Yes, answers can be checked in polynomial time.

Co-NP No, answers can be checked in polynomial time.

All NP-hard problems are not in NP and it takes a long time to


NP-hard
check them.

NP-complete A problem that is NP and NP-hard is NP-complete.

2-Satisfiability (2-SAT) Problem


Boolean Satisfiability Problem
Boolean Satisfiability or simply SAT is the problem of determining if a Boolean
formula is satisfiable or unsatisfiable.
 Satisfiable : If the Boolean variables can be assigned values such that the formula
turns out to be TRUE, then we say that the formula is satisfiable.
 Unsatisfiable : If it is not possible to assign such values, then we say that the
formula is unsatisfiable.
Examples:

Note : Boolean satisfiability problem is NP-complete


Cook–Levin theorem or Cook’s theorem


In computational complexity theory, the Cook–Levin theorem, also known as Cook’s
theorem, states that the Boolean satisfiability problem is NP-complete. That is, it is in NP,
and any problem in NP can be reduced in polynomial time by a deterministic Turing
machine to the Boolean satisfiability problem.
Stephen Arthur Cook and L.A. Levin in 1973 independently proved that the satisfiability
problem(SAT) is NP-complete. Stephen Cook, in 1971, published an important paper
titled ‘The complexity of Theorem Proving Procedures’, in which he outlined the way of
obtaining the proof of an NP-complete problem by reducing it to SAT. He proved Circuit-
SAT and 3CNF-SAT problems are as hard as SAT. Similarly, Leonid Levin
independently worked on this problem in the then Soviet Union. The proof that SAT is
NP-complete was obtained due to the efforts of these two scientists. Later, Karp reduced
21 optimization problems, such as Hamiltonian tour, vertex cover, and clique, to
the SAT and proved that those problems are NP-complete.
Hence, an SAT is a significant problem and can be stated as follows:
Given a boolean expression F having n variables x1,x2,….,xn, and Boolean operators, is
it possible to have an assignment for variables true or false such that binary
expression F is true?
This problem is also known as the formula – SAT. An SAT(formula-SAT or simply
SAT) takes a Boolean expression F and checks whether the given expression(or formula)
is satisfiable. A Boolean expression is said to be satisfactory for some valid assignments
of variables if the evaluation comes to be true. Prior to discussing the details of SAT, let
us now discuss some important terminologies of a Boolean expression.
 Boolean variable: A variable, say x, that can have only two values, true or false, is
called a boolean variable
 Literal: A literal can be a logical variable, say x, or the negation of it, that
is x or x̄; x is called a positive literal, and x̄ is called the negative literal
 Clause: A sequence of variables(x1,x2,….,xn) that can be separated by a
logical OR operator is called a clause. For example, (x1 V x2 V x3) is a clause of three
literals.
 Expressions: One can combine all the preceding clauses using a Boolean operator to
form an expression.
 CNF form: An expression is in CNF form(conjunctive normal form) if the set of
clauses are separated by an AND (^), operator, while the literals are connected by
an OR (v) operator. The following is an example of an expression in the CNF form:
 f = (x1 V x̄2 V x3) ∧ (x1 V x̄3 V x2)
 3 – CNF: An expression is said to be in 3-CNF if it is in the conjunctive normal form,
and every clause has exact three literals.
Thus, an SAT is one of the toughest problems, as there is no known algorithm other than
the brute force approach. A brute force algorithm would be an exponential-time
algorithm, as 2n possible assignments need to be tried to check whether the given Boolean
expression is true or not. Stephen Cook and Leonid Levin proved that the SAT is NP-
complete.
Cook demonstrated the reduction of other hard problems to SATs. Karp provided proof
of 21 important problems, Such as Hamiltonian tour, vertex cover, and clique, by reducing
it to SAT using Karp reduction.
Let us briefly introduce the three types of SATs. They are as follows:
1. Circuit- SAT: A circuit-SAT can be stated as follows: given a Boolean circuit, which
is a collection of gates such as AND, OR, and NOT, and n inputs, is there any input
assignments of Boolean variables so that the output of the given circuit is true? Again,
the difficulty with these problems is that for n inputs to the circuit. 2n possible outputs
should be checked. Therefore, this brute force algorithm is an exponential algorithm
and hence this is a hard problem.
2. CNF-SAT: This problem is a restricted problem of SAT, where the expression
should be in a conjunctive normal form. An expression is said to be in a conjunction
form if all the clauses are connected by the Boolean AND operator. Like in case of
a SAT, this is about assigning truth values to n variables such that the output of the
expression is true.
3. 3-CNF-SAT(3-SAT): This problem is another variant where the additional
restriction is that the expression is in a conjunctive normal form and that every clause
should contain exactly three literals. This problem is also about
assigning n assignments of truth values to n variables of the Boolean expression such
that the output of the expression is true. In simple words, given an expression in 3-
CNF, a 3-SAT problem is to check whether the given expression is satisfiable.

You might also like