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

DAA Notes

Uploaded by

omkarmohare18
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)
14 views

DAA Notes

Uploaded by

omkarmohare18
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/ 17

Dat

Barkthacking Branch 4 Bound


Tial ard ExAoh: Tme complexity i actenu'alL)
inta)
Algo quickScont(at am],; istL , bata-Joca. oçpaoocb
decision bastà phoble
4 Sseasching tavesal problem
DES mannh

cuickSost (an , jl,)


Wa hae to place Nqyeans. on NxN chessboabd Such thot two
qpens doesht ataclk each othe
Binany Seanch o(lgn) a Time comple.xity: n
Nax - min 93n -2
Nange Sont - o To check qeen ayeen
Quick Sont Foh Lalt qp2n
digonally
Caady Krapsack - 0(alcg)dae onde
Job Squencing i-k
Aetivity aection - Onlag . nt Ohden d hinish time
Foh night qyen
Alman coding - 0alagn) inc onde:
o/ Kiqpsack
Chain Mathix - O -l=k
BsT
IS?
Floyd - 0 o3) (6, 4,2,) alncady placed
Bellman N- wati cas E-edyes
6 1 3 5
8
1 5
Dat
44 Paga

42. Nqyeen ALgri thm


4
7
a) Can a Naw Queen lbe placed 2
. 2.
3
lgonith placa(h,i)
4
7
2 fos =1 to k-t da
Czijei) on. (Abs (ziy]-i))(Abs (j -)
1
7 1 2
1 2 than Retonn alses
1 2 3 Retunn Tnue

AL solwt ions to N Qoeen Problem


Queen Algonithm Nagcns(Kyn)
(2,5,3,) olseady placed
on i=1 to n do
7 Placelk, ) then
3 1 4
1 L
7 5 3 ihk=n) than waite (xLi:n),
75 3 1 4 dlse NapnsCkl,n)
7 5
5 3
3
7 5 3 1 2
75 3 6 2 4
Dale

ixc tG)scz)
Bnanch bound Shat
is ah "dlgonithm Let ecz) =lowen bourd bound on the cast
dasign paradicgn which is Let b the uppe
gnaally tsed
sad enon solving eombintie Combinatolal optimizati. thot noce
poblems Thase probcms ahe typically xponential in tns tuppe then k;ll
S C1) sca) <upph.
ampaity
In wonst may xeqaie cxploing all pasible peamaati,e
Pounding &ued fos minimizatiaa paclblkm
Case

*State Sonce Suahchhea


Give all combination lonsoluticon
It helons to a
methad in which al
gEheagted baane any cthen live node canchildhes ol E node ay
beccme Enode' Objtie o hrapsac k Boblem is Maximi ze
Live node: node that has not bech We can conyent this nmakimizatian panbla, inte minimization by
xpanded
Enode inode cunaently being expanded
Knagsack - 2" choicec Calalate cost 26) --pi Cncludling ngtionL paat)
Calaulete Ua)--p zi CsithautE'nacbìanal pant (o/1))
TSA - Pomstatio

* Bounding
Boundi ah£ Used to avoid the
subthe that do not contain answer. node. genenation d
For any minization problem Suppase (1) an answes nde
with cost c1). Qun paobl rm is h ind min cost dns node
Leb I) lowé bound
boundsgrzat, than upen bond., we
l not zglone that paat
dassta

Pag

update uppa z0 --32

Kill that node


-38.
Le BB Apphogch
Sont in
scending ondeo wegh 22
co
o
uC = -(io+ 2)3 -
lo 10 2
-32
2 6

nl w) lL use. whose. cast in


Now w have two ive node We

c2)(o).
C :-2 ixiAhactional. Pa_t) 38 <-32

Je -(I10+10 +12) =-32


U)= -SPixiwithaut lnactio ng) (4)=-38
--(OxI +l0X2 +12x1)

U=-32 |)-(lotI2+
18X) -36
C0-38
U-32
Now we haye 3 biv hode.
U-22
Co -32.
U--32 U=-22 -32 38
c-36 -36

-20
C-20
Toor 50

+18) = -38
Uioz -(0+10

U) -(Io +10 +18) =-38 -(o +10)= -20


U
Cu -(o+1o) - 20

Uykuppeh
- 33 <-32
c3) - 32.
Kill node C3)
Kill node 1!

KiL node 5
Ans ) (1.
Cannot kill 1 LF

C=-39 C=-32
Now we have 2 live nodes
FIFO BB U=-32
Lo C=-38 C-30
6
Ua = s -(lo +10412 t1s) Not possible as_it excad W 2 38
U=-32
9-38
sapscity uppLa, = -32
ft3
2(a)-PixL
>-32 -(10 +10 +12 +I8 x2 -38
Co = -(lo +10 +12TB-8 32
z(i0+ 10+12)-32
9i-32uppen 33)
Kill node g
Ce-(ot0+12+ 13)3)=3R
ony 1 iv node z
Now we ha Ds-Cyo t2)=-22
Page
52

18)=-38
Ui2= -CIo +I0 +18)=-32
Cn=-( lo+Jo +
Us= -22

Us=-io +n)=22
Kil node13
Uz=-12+13) -30 Ans

C=-0> Uppeh (-32


Kill node 7
Ua=-(1ot10 +12) =-32 * Tha velling Sales hna n Paoalem Branch Bound)
ts=-38
To ganenate aeoce mataix
Reduce Row: AaoN Î` Said to be heduced i it contains ct
Cg = -(lo +10+13) =-38 least one- ZeAO value 'in eachhow andest o the yalua,
ba anon nagativenumbeh
Cs-32 ppes )Red oce olumn A_ clumn, i said to be aedvced iit containg
Kll yodek at least ong_zeh0 vale in each colomn ard hast the valve cdN
be hon
Cs-36 7 uppeh hegative nomben
kill node 5

Cuà-32 ZuppL
Kill node L
Uy = - Jo+[o+12) =-32
Cu =-I0+1o+12)=-32
clsssna

clsse
toqe S
Date
Page
55

1)C25
Eg) Adjaancy Matix fon the gnaph C=35 31
20
Redsction C)= 21 +4= 25
30
36
-2 28
2 22
18 Cen z 25 52(
|6
MBMi2

Step ) Ro heductioh:
Select mìn val no each mo
36 2 Hehe no ow { columa had oction
2
8 2
o
2 4 12
3 12
18 3
16 16

21 Lost
subthact min
20
MR’Mig.
13 GO 2
St R Ca= 3 to 1 =co
16
12
Column heduction o8
|2 )2 ) cos
2o
2

Step 2 olomn htductioneach colum. )

Stlact min valus hom |2.

zh th
12 2.
Mr 2,
3
3 12
l2
28
2
+0
3+25
is
) staht (as
88888
12
12
SO 31
Reduction Column tìon heduc Row
12
12
1)+29+ N2 3
12 12
CO
heduction Row 1=0 to 5 8 CsRi=e Set
MRMs
25
3 o8o
2
12
2 3
12
= 1 to 3 = RSet
57
Doge 58

Row eductioh M25 > Mss


3to 1 =
SutRs oo Ca z
8
o
g
8o 36
= 28

Set R_= oC3= 3to 1 = ppeh = 28


2)
GO 2

8
Roy heduction
88
8
GO

S2

M42 M2s
Set

GO
23
clsss
Data
Page
2y3/24

pPhobie ms in P tim
* bw NDTM solve yon NP pxoblems
Non. Detzrministi agonth
S Wihite othee 'poblem (Reduction )
SoluL 1 problen f alate

Ii has thhce hunctios


How to waiz NO Aqo ohe o) the elennt o sets
Chaice CS) :Qnbituihy chocses
an vbsuccesslúl campetio)

Seas ()iSignals SuCGLSsho. comletien.


Tine compleaity hoh <dczAMinicticwill att bt always
a s thah that innjs detominstic

* Non DetuAninisic Algoaithan Jor o'y knapsack

Fo i-1 to n du

W W+Li)* w[i1

'se SuccAssO,:
clhssante
nat 22 3 21,
Foge 62
Da

Relation betwen NP ¢ p *NP Hand NP- Comolete Prohlems


NP t and onlyit
NP Hand:A phobiemLis NP Had L'i (SAT
Incheasing that satihiability neduces to aL).
which is not ol Cmajply in secani
Now PCNP SAT is NP babd problem
PNP NP Hand Problerm
SAT &L
LdSAT

A psablem Lis NP complete i and only Lis NP Hahd


A is edb ces toB
A can be convetd intoBin polncmial. tinme
thore is polynomial time algonithm Joh R betetr then wL can
also solve A with sama algohithm inpolmomial time A Cook's Theonam
NP
SAT sih P
CNE
satis}iability
3 vahiaoles
and anlyi
P= NP
koop) NP-ta

L3=0
(oVo Vo (Iv vo

SATdol1 knapsuck
classte
Dat
Page

Staing Matching. <m 3<7


6 47
KMP Sknuth NoHsis Paatt) b= =b v
Lineah time comoexity PL3]= 2
Requinas phoces ng JL6] 1
finds soix peix fon avay ssi ble substaing
pa teh his Info Is sbahed in pi table /sm 4<7
ts Lps (P) 2 3 5 6
i m=lgth ()
Oo 1 2 3 o

wh
iem). Pis]= =P[33)

1<7
1

clse
JLL1]=o
420
Lse 2<7
5Z
JLL2]= 3 1
Dat
ug 67
)Doi
Dogr 66

2) P= ababd

Jse.
2 JLLL] =0

JLLo] =0 abcd abe ab


5)es: ao bc ada gbe.
23- 5678 9.

X 3A b
2 0 2
lse
2 56Z 9 10

2 3
67 9
Qa bc d qabe
a==d
JL L2] = 1 2 34 5 6 78 9
b a a c d

2)=3,

J[3]= 2
clssLe
)Dat 69

nL] len (txt)


mllen(pat) Pat jT=tali]
NhiléCisn PatLjztxtlil
PatLj) txtLi]
i piant("paten found at "ejihi)

else
Pat L4l4tatL/]
b
E O 1 2

Qq b a aa c
index 1 2 S
C b
tt
PatLj]t txli]

J
02. 2
a a a b
7
2 3
b Pati; stxtli)
Pat Ljetxt Li)
7|

Ga Mou Sthin Matching Algaitha,the pattenn as follovS.


I uS2s tuNO methods an pest prephocess hg
Bad chahacta heuist ic
Pat LJ ~txti] upto "God subpic heunistic

Pat lj] txt (i) * Bat Chahactah HaunistiC


-1)
Bad Chonacta Pasition max1,lagth o pattesn -index -
2 3 7

GT A G
b _qa a b a a a b a aqC
aa q baaqc
Bad Mate Chonacten, Shyt Valu.
G
9-o-l =#,þI,1
9-|-1=7
PatL =xtli] A 9-2-1 6
Pat Lj] =txtLiJ
Fon
i12,43s.
Pat Lj)=txtLil st
chana ctes postion
in text
desan! t match ,sht by sht vale
PatLj] txtli]
I any pas itian othe than
st position dosent match, sht
4-7=1 pattus.
Pottern found at
dessnte
clssmte
Date
Page 72

(asi
The numbes d chanactens matchad belo a misnatch cscuns
poeseni Sonme wboh un matahd cha¡acty (it. asa
Foh Text hojeh bad chasacter
toble
Case2
Only slix mathd chanactes belona miatched. CCUNSy Qhe

2 34 S 6 7 8 9

Eg o 2 3h 5 7
2

G A G
9 Bad Mateh Chahacen
3 0 B) 1
Sht valut

Case 2 2 34 5
2. 3
7%01=7,ky2
8-l-|2#,T-=4,2, 1
G A 5 6 7

99
C
bb
6
3 21
o
5_6778
esste

babab
b
xFasten
Randonizd Algcaithbm (Type of non-detamin ist ic Algp
Omputati on s Compahed to detenministic alo
6 4 5 6 Z 7_S
bab
baba input,it will give ditgeaht autpot
Monto Caho Alaohi hs
023 5 67 Las Vegas Algorihm.
78 More Caslo Algeni thg lenk Baad on Lawo lange number)
Paobability
)Uncentainity
Ale Some tim. it may pnoduce incohhact nesult based n

a bha blab shipt by &mte It will take same tine to Kecute algoaithm evLy tìmL
ab ba bab
shit by
-1 3 45 shit bys Ootcom Bhebt Phoba blastic
a bbabab Timt. Compleaity -detaminstic
*Las Ve¡as Algonitan
Fon tuxt ’ check bad chaactz tabe st chah utcom - Cohhect
Fo patteah -check s H
Trng compluxity will always vaay

Steps cf Moste Canlo


Payom a detzarinistic algpnitam
Combine the resutt all the samples

You might also like