0% found this document useful (0 votes)
81 views12 pages

Motchuy (Yattlevn Hatch) : Atoun9 Alg0uithm Wid

The document discusses different classes of problems based on their computational complexity: P problems can be solved in polynomial time. NP problems cannot be verified in polynomial time but can be verified in polynomial time if a solution is provided. NP-complete problems are the hardest problems in NP and any NP problem can be reduced to an NP-complete problem. It is unknown if P equals NP. Approximation algorithms provide near optimal solutions in polynomial time for NP-complete problems when exact solutions cannot be found efficiently.

Uploaded by

Vishal Singh
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)
81 views12 pages

Motchuy (Yattlevn Hatch) : Atoun9 Alg0uithm Wid

The document discusses different classes of problems based on their computational complexity: P problems can be solved in polynomial time. NP problems cannot be verified in polynomial time but can be verified in polynomial time if a solution is provided. NP-complete problems are the hardest problems in NP and any NP problem can be reduced to an NP-complete problem. It is unknown if P equals NP. Approximation algorithms provide near optimal solutions in polynomial time for NP-complete problems when exact solutions cannot be found efficiently.

Uploaded by

Vishal Singh
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/ 12

UNIT-05

Uete
motchuy (Yattlevn Hatch)
Joab abc ad
abc
Nauve
Stng atoun9 alg0uithm wid

Nacve
AlgOnthm
ave alGoutHlm ds all valid
The ssts
a hat_ Chrcks.
the Ccltiow Pl1..mj =T[S+1. .. S+m]
lar cak then -m+1
DOMLblo Valus &.(P=paterv, Tatext|Stw
S Shiyt)
AHESFRIJ6T-ALGrORITHH

NAIVE-STRING MATCHER (T,P)


1 D T:1engths
m- P[enqth
3H0rS =0 to n-m
P1- m]= T|S+1 S+m]
p/int "attern ocUTS i t Shuft "s

Runr
Kunruy ime 0((n-m+1)m)

S1urgmatchurg by autonata 7

LG DFA Centaning Suubatuunj. Pp10

T= OllotTo/otT
RutHalt at
uen nal stotu

Atcept
halt ct final stat
mycomeaano
B 0,
C
1
kwp Stung matching
Robin

T S34268s 16
P2685

Che9se a pum nwrbe 913


268S mod 13
Lind pmed q
lements
ouxfoui pduy
S3 42 mod 13
12

63426 mdd 13 Spdbu

4z8 4668 mod 13

Succeshul hit 268S mod 13


68S9 d 13
mo
8
8s96 mod 13 3
Algoti thm
RABIN-KARP. HATCHER (T:P d, q)
n n
Tleng th
2 m- P. lenqthu
3 h d mod 9
P: 0

6
to:0
fo6 tom
P- dp+pliJ) mod q
to
cd to T(J) macd q +

9 fos S-0 to
n-m
0 p= =ts
bn Companion
o J ==T S+
if m]
poin Pattesn a Occurs Dete
oith Shuft"s Parye

d (ts- T
4
tstI 1S+1]h) + T[SIm+1]) mod y
im
O((n-m+1)m)
alAsSMAS
KMP Stuy matchug Date
Page

uth mgb p:hatt


DLD PPL
Cempulu A

uix wnctiem
COMPUT E - PREFIX - FONCTION ( P )

m Plenqth
let m) be a ne aq
3 71-0
4
K:0
or 9 2 to m

hle k zo and P[K+1J# P[q1


R: TR]
iP[k+J:: Plq]
K: KtI
T la3- k

Otu3n iT

23 4 S6

o213/07
23 S
6
Pob|baba bjaal 3
78 9

TEO0 2 o 8
KMP-HATCHER (TP)
asSMAte.
Date
n Tlength
Poge
m- P length
amnuuteCOMPUTE - PREfIx -f ONCTIONtP)

/numbN ochanactens matchud


fo ton c a n the taxt rom lelt to uglt
hile 9>o and Plq 11 7T[i]
nex charcatn does not matbu
f P l q : = Tlil_
99t1 /neet chatacd rct chu
9m al P matdeol?
point Pattexn occurS srth Shdt " t-

LoB fan the nxt mateh

blab ba
23
P ba bC

4am
lom found at 6-4 = 2

11 L4)0
q2

3 S6 18 9 0 11/2 13 1IS %t2


2
Palbla|6] blalolbla 9pqo
3 S6
ololt2lo1 2/341516/l6l/2/olial
DAA

P Ond NP PsoblemS

P-_problems The, paoblems hih re

Selvable in belynomjal time kru


as p- pooblems.
EXamples Bub ble Soot
Binasy seaz Ch
Selection Sost
9wck Soot
Non d t ttuninUstic T d Hesge Sort
PouomNd

hich are
NP-PsoNems- The poo blems
are knoon as
NeHable in pblynomal time
Dp-pooblems. duia bo blem
1hic
Eamples NP IS the class f polysemal os
Its easy to Check the cosrectryess e
Claimoo anMEn
ALL
AAL poObleros inp COn be Sovetd ith pelyrermd
in NP.
Hm alsOcthn in

Paru intsaatable.
I S n o t knoon hethes p=NP Hown
preblarns CUr Knowm
pepan tat t
Con be peved hat Dete
P - NP.
Pege
PNP) wu ,h C
PTobla r Ne
that aL nEithe in Pno7 inNP
CtTYste
Thu p .belen
blem to cios P
jt'
t ird a oludior ottapovm
Co to f.
pLeblcm

t'se to
ehick 9tution tat may haue
haue ban
Vesy t edious to ftnd
Pcias Th C l o f Cemits tho
poblems tat au aoluab in_potynomis
Hme t h e psueblams a be elves
i n O(nk)

NPC (np Completenen)


B s NP Compeai ifit
Suiedtwe CAnolith Ons

6isinNP t m edueible
Pelynomio
t n nP

erd phofe7
atiofies h
but net
Lesan Hnas
6 A NP-

oumall
L uduces to
4Hat Carhe
- hand
palynovwial me,
lued in
Ia
m
pn4b{un Date
Lt P P Page
do be PC9 fhiu
pxeed rO_Lel
o stt Hhmt
algaithu
hy
for iB
ek ent Rod,
CRh C OPpOxinotn

thotacea Deyneual tima irDtante


SolutiCn alseuthm ek B

pelynneHa-4 m
|algbnithm to detde B e a

paeynenmius-mu alseuthm to
duud A

Harnil tenian Cycle


E T$P
algornthm- Many
any puoblem
Aproxi mat1on NP
are NP-_
psachical S1ghfane Cemplete
are too important to aband on
hut
btaunuh ar pLmal
nedty beause
Selutudn naclable aprotle
S NP Cmplutu wukoly to
palyemial t ina lssnith
La xaty but Hhuy de
that all hspe sLostThuse
uet

a
ip
ueapphsasbA Dsethis aund NP-
atul Iaputs dra
Smull n alsanuth expemuuti cl_
may taeaeCHY Satisacnzs
SLmd,imay g le possible to ng
hOY-pdtmal SolutienS n P o y n e a l pmL
/uthun r he woTStCaNe 9YCn ths aeNaILY -
or_cn
npIache neaT opi
mality is cten
. A alsaith
Ptws
luhOnM (altod sSMAte
optmal Date
Cpphoximatuo nlaithun us o
)poge
ChapuJuphusuds pCpeual
uealL P-
Oppexnati onn alsathoyo a
Cenpile p'obarm
xap
Vextex Cove phobltm
Vetex Covr o a wolwuded aph
a Dubt tel 1ts vwtic Suc h a fa
thru
eey
eny dg (u.u) othghaph,
in the vetey Mtheugh tha.
cever
6h IS

haneuy Ventey (ove, he Set Covêu al


Cuven an d i s u t s
daw o h Gwe aph
venhex pthltn
CevePe
is to hd
qap, fhs
3 VOnkex

b 2

(3)
(beol0 ( b,e,cl)
A PPROY-VERTEX - COVER(G1) erpy

(4 0)0 4, 1)
3 wle '+0

do let (U,0) be an abi tTasy dqu E

-CUfu,u]
meue mtaery dge tnid ert on

thor
TehunC i
TSP uSin uOYIm0lugi?

(G1,c)
Date SSMALe
APPROX
T S P - 10OR Page
V L J u be q
uentexIE
Slec a
UYfex
Sprmn theeT f
a minmum
G
faom 100t USIhg PRIH(G,G
MST-RIN[G1.

Let be the ist . vert ces Visi tod


walk b T
p3eorder see
etunn he hamilfonj0) Cycle fLot ViSit
he vevies in the ovder L

(A
3 HST 3
2

he - order
AD A-D-C-8 -A
2+6 +3+S = 16

A-8-C-h-d-e-f 1-A
Rondamused 9o
Randoised qwick Sort
KGan)
Kandemized Pastitien (A-

r)
P
Roandom (p.r)
exchange A[T] A[]
Tetuin
Paxtition( A p,T

You might also like