Unit-a.
Brule fovea % pivtdo and tongeus.
Pamte force = string matelubg Eehasistive steasch -
Traveling «qlesman problenn -
| Adsighmante problem .
Muthpl
knapsack problem —
Divioe and tongues mutrodology —
cahion af dange ategers and strartinlt matrfoc
mulipteation — closest pats and convex. thull problems.
Pectanse And tonguan :- Tpologfeal sorhing —Transfom
“ae \ PAetowhing — Heaps and Heap Sort.
Brute Aovee i :
Brwbe dover 139 a Straight forward approach ‘te
ales + problem, wiablp iach, bated ote poblen
LgabemaAk anf “aapissivons,. a Me, concept pwvolvad |
: a me
Bhupe Pree approach “Just do tt! |
Far Eazporantfahion problem: |
Compute andor 4 pon 2+1° pumbs a and a |
iis
nono negahice Intager ?«
aN es ARs FA
uU~or
‘n tienes
YD Consecupie categer checking algorithn
Aor computing, gACm/nd
3 pefinition »
tublp hication +
oy Bote force epprenct, con be used 407 :
mrad plication, 3 s burg. matching.
k
aged) alporSsom for madstae
L abet
Sorting, gnagchiog's
f pak teagt some
fo ypetd Arasonable— altgordion of
j, pabeance: Site.
16 40 (indtation on Fst
practical value with :=> Application fp areta-fover approach fe ns problem o
Sorting — S$électfen Sort & Pintle PTE *
kK Brke Horeca 18 Applfeoble te wide D macal -
Problems . henarat approach for fen oes ate
ant to Point uk problems
ae ages
i 4 Pi ee
9 Selectyon sore Sfete by scanning Hr entire
Given Usk cra’ ged tes lamadlese ( ebernenibl anda "3~
Ze sith the Abr st element » putiiag the sags, sen er
Ab irs Hinat possoren, ai tan, Koxred ae -
2)
Ase
etexting aes Lecond
Pi oP Say),
clement to dnd We Smallest amongins, lash ro! alapronts
nd eacharigedg ba uitr tre tecond efemant
Aion:
by pething ta
Aecoud dmallect element fp tis Pinal \podtdto
a Ten Sean he Ireatey
2 on, ian pars trough ahs Upae ,| abgsosfnm
geatehes! 407 A omalleet prem) anion 3! tra. base,
wfta “Ape ‘
h-f elemons and swaps te
Ae ) 4s 688° Fosi2q, 34, 89
ge wma for bBpt AF 34 8F
Saale Be ston. AaaE EF PF
\ fee atg (2 daa)s Fe, BENET ;
io og. oa as aie. Beg
19 29. «34 4s be ae (Jo.Bubble Sort:
ose Oar Compare adyacont elamants og tex 75k
and erchange Tham if trey ore our of orden.
Te ‘bubble up! te laugert clamank to tis
lave position on tus list:
a ee Dus next pasg bubbles tp ter. decond (urgese
+ Agtes ny passes me (Pet aortesd, i
A 2 : 1<
bacon, A, A Aan cla Lar
fn tna
A 307th pubble Bort CA Co---n-1tD
U corte a given aad bY beibbfe | 6824)
i
Ue Drpsk * Am oAnaig. (4 DO-- nary & andga 4
\ : ekaments
pag Aen Rid gorred ko
G ourpre *
sagt non decrsarcng orden:
for! feo dy na) do ,
for Jo 9 pe ncaa,
pat geiy< acs
do
swap ATI and AGH
AR RA 8
aq Ib,
Sar ge as 68 4 29
is apraighe forwaid .
> ts) \:
Dp. bubbles ore
elomante n+
2 anotyet
2D Tapa oie 3
> Baste ope ato
given bg. ren | mrober A
n Ja kelp) compartsan.
5 necigi. Hogs Ae 7? ,
guiag sae and Be a7ee" bey The pfollowwtog 3
neal nood 13
ee = ie See
20 Seo oh cC Ca-R-1> O40
we wen
cn199 & Oinrd—
>
89¢545 68 Fo 29 24 =
2
4s 894568 10 25
? OY. 19
m
4s és: 8949 Fot> 24 ian a
45 bg 89 294 90,2524 i
ase fe ge)
z
25 34 Goth
4s 6e 89
29 34 «17+ f Go
is 2 A
AS <3 68 +> 994524
% 19 | go
4586s tog
3925 24 19 J 43
4s be 29) :3@.5 e94%s109) 90
as 68 29° Bq. 19 | 89 ai
eke.
+ Brute Aoree String mastering +
Shag materung problem.
Dnhcen & oping OM Charackers called
ana teak and A String Fm chorackers (msn? Called
tie pater ; dind a Substesng ef he fexk thak
matches he parrern :
2 we vant te ind f- tua sdelon of far legemae
chatacker of he Birse matching. gucbeh sing. ab tha. park
Buch that
ERs Por eee bray {
HP ee Eee = Pm!
we by, eT
bo «ee by aa bray weet Ef iy
t u athe’
fe See PEER bt hteON
Alsorrion
Brute force offing Mateh CT CO-~ nats P Doe. m=ry)
U torplemants brute Sorca. Spofag madch~B
hora cbons
A anput shy auay TConn1d a”
Aspessenting a deck And
an auay PLo--.m-lj
Aepreenting a pattern
am an ACERS
0 output: Tre toden gy tan obirskh characke? £2
fas dexk: mak spares a matehsg substog or
AE he eaith is unsuceess fet» :!
for feo te a-m do
jee
while j Problem can be modeled by a weighted graph
auitn He Baphis vertices Kepreserting tha cites and tre
Age weights spedpprs ta Adtances.
7? Pron tes problemi can be staked | as te
problem ey indies. tue Shortest Mamt)-tontan Cini
teal. acaPh «4
( :
= tye ldontan aby cute 3B delice: as a eycle
thak passes Hough all he VeAeok @ prs Graph
eaacly Once +
9 Yamildonian rad an also be defined a8
A daguance. nel advacent vestioes \ Vigo Vito Pq te
were tas first verter of tHe deqrence B the Sams
08 dn lark. ona and all ofne, h-f Vextitas Ve
Abtin ck sTino
compres
D> Oon-0!
\
Vn Toy,
2 bocsdisa he atari? a)8
Abo d5e 5a a= eraties, ol \ 2 PRmat
8 esbi5doa A= 5t8 4349-23
2b odispsa Aa St)aagael ophimat
Adobe. a,, A= G43 ¢845°23
Q>d se sbsa
A= De HEI yr
Knapsatk problem
> Bite b Stem, of Know) Weighbd Wy) Wal”
valued Vijvpy sv) and al knapsack of eapacteg s
Find hee, most yaluable Subset rE, tems tnak Ae
ab ne knapedi |: ‘
si
Tine, complesiy1,24 Me -t 54
L133 W nee Feasible
Las ta fo: feastbhle
1 2/33 Bi dso
42,45 @ 435
13,45 4 $65 :
812033 le nok feasible
12745 Is not feasthle
a1444 1G vot feasible
£2,345
net feasfble
not feasible -
£12,344 — 14
THs traveling salesman and Enapsack problems
O. ghel tne ‘best known examples 4 Npihard probleme .
Adssignmeank problem.
Oc D> Teere c22 9 People who noed + ba assignad
do execute n_jobs » One person per job -
DP Tee cask will sheruase Af Tee te Pate
WB axsigned to tre jim fob ts a Kn dun qhantry ehh a
Aor eath pais Wey aT, ay pO
7, Tae, poe Bb te tind an aI are ‘Corty
ne minimum total east:
> A Bmatt eshonce: ep Wis problem rotlows
Beftn tue rade entrtes nepratenting his assignment
cones ZC 1 ‘i uh
VJebi' | Jobs) Tob Jeb F
coy Peston og a aha gee
Pergon 2 t 4. 3
LA uy, Person 3 fe) Bee. ! é
Pergon + r 6
ae ea4 .
c= z ea ‘ pine compleety
a 2
se le = Blo?
76 494
<1134> cosh = Wt 4eleg 18
<1 2,4,3> Cost = F4G484+9=30
X<13,2045 cose = U4 B+8tar rt
1) 3/4,27 Cos = FH 348rh~ 26 eke--
X1,4,0/37 OSE = THF4OHI= 33_
@sSé = Ft Fritb =
Opbinat Assignment 1g (024173942 = 2ESHIFG AL
example stu cose matrin <2) 3, 4,17 sbdlicabes |
Ties aseignment of person! fo sob 2, Peison 2 +s soba,
Person 2 40 Job 4\ and person’ 4 to Tob), Sa
\ mea Ray
Divetcle inns, egpigulin’ ne ‘
Fk work according. to tw Apllowning generat
Plan
> 4A problem is divided apts everat’ ub problems
fos. shame type » fdeally e res equal ‘Size
sg leed '
> The Sub problams Aa Lol §
> Ts Aofutions fo tha cub peotleenis, Oke, combined to
Feb 4 delution fo Ns oxjgtnal problem.
FE, eh us onsider tne problem of on
fam of K wernberd App toe Anny
Ty nyt, we can dfeide te’ problem into duo aster’!
Ato dame problem +