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

DAA Unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
33 views12 pages

DAA Unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
Be SSloht Sets o- No Common elements on the eete © known as biefornt Sele, 40 So = ¢ DR fomt Set Set Opewatfons 2- These ave too opesations « They 27e # 4+ Sfimple Union a: Sfmple Fibd Onkon g * We Represent the Stinple Union f Tree data eleuctuse- + In all the elements , any one element 1% voot (or) parent elernent. exg S= G2, 3h s.= bast SUS, = Lasers} Procecduse 3 4+ Tnflfally consfdes all the elements treated as Sepavate toee a P(r} — pazent of node P. 3. Fou soot node Plf]=-1. qe OFter performing each Unfon Operation update pli]. Example ® 198 gS yy SS ait O © © @ © © Abelalalsle “Ue i-t{abufs sede da days Unibo (142) Union (294) Unido (5,6) ® © @ © CombFhe (112) (254) Combine (1,3) (5,6) Union(1,3) Union (155) a (x @ oO Algoarthms Sfinple unfon (°,7) + Searching an element % the given set ¥e known as SFaple Find. =. TER a succesful seasch vetusns set representative Phemmes: elements: root /pasent Example Union (152) Search = 4 @ @ C) yee, % % successful Search because 4 % present i toes Tk setusne the Value 4. 0 —— &« Algorithm ¢ Find (P) hele (P0120) PS pl?] 5 °°. vetusn P5 xarople g oO e pl 2 te bl es ea @ ) a = oD fod (4) faq P(i]z0 P(aJ=3 204% fea p(a]=1 20 Back Trackfog 2 Tt o . boule fotce approach ad kifog techniqye we use «In Back toacl Rg all posetble coluon wtih a lee, numbes means we vl of steps: fq back teackihg tech ofue, we Solve a pooblem th an «By using ZAnt way when Compared to other methods Itke greedy effi : method and clypamf proqvammiig. Example Take 3 Students 61, 82,G1 and avsange fh = chairs, (state Space toee) Genesal Method 3- * Tr thi technique we Seasch for cet of opltnal solutions which satiBfes some Constratdt: : * The back teack?og algerthm detesmthes the colutioo by systematically searching the Solution space for the qiven problem. Algor?thans Backtsack (mn) kst; wobtle (Kf) rr (these ase remaing an untied x (kJ e th G4, xf27,---- x(k-i]) and @, (x01 ,--.. xte]) % true) t fe (x1, —---x(] a path to answer node) waite (xt=K))5 Ko K+I; else K= KH; § 3 LS lll Example 8 Take 3 students B81, B2) 4 bounding Funchian tha Bl (qr) stuctent Should be fo the mitdle of Boys (Bis Pr) we Use backtoack?ng and Fd all pos: 7 GSl should not be fo mtdle s (lala) Ba Gy : (erfen x Gu v Heve Bi Gy x Killed by bound: ° ocl¥oo ‘ 2 & & i Ss Here bounding function % tue, So Gn % i middle so back tzack. (tal x x Kélled by bounding Function, Se Heve, -B2) Gy ese bounding functin f tue , 50 back track (Go back) and areange fh 3 chats wrth a thes mt tn ot A A A A AD DD AY BD AD AD D-DD OD" Appltatioos a These axe @ types of opplicatfons: They ave 1. Queen's pzoblen 2. Sum Hy Subsete problern- 2+ Gzaph Coloring. N Queen's problem 2 + N Queen's problem & one of the Fportant application back tracking. + We colve WN Queen problem by toacking 4- Queens. + Consfdes 4x4 chess boasd and 4 Queens, The objective & to place 4 Queene t 4xq chess board stich that no too qpcens Should be placed Tf the Same Tow, Same Column, and tame dfagonal- Example 4x4 chess board o 1 ac .®: 2 {QiX|xK IK SHEE board (eI{c] EMENSNO OND GONG GS WW WOU el elle eA Y/Y YY UV Step ©% c=0, 7-0 check, board (o][o] = cafe Now Sesement columo by 4 Step oe cel, t2O0 check, board (0 |['] # Safe, because place Mh same Now fevement sow by a4 Step4.48 C=l, tel Check, boasd [1] (1] 4 Safe, because f places fh diagonal. Now fresement vous by 4 Step 4-2 3 C=l, 22 Check, board (2](t] = safe, because no qpteens fh rou 2 and column 4 Now fhesement column by 4 Step 2.0% c=2, 7-0 check; boavd (ol [2] # tafe, because already @,-% present: Now fievement vow by 4. Step 21% Co2,7=] Check , board [1] (2] # safe, because ft becomes diagonal for @.Q,: Now Thevement. rou by a Step 22200 C= 2) tea Check , board C2] (2 f cafe, because Pt bas alseady Qo: | a ahi hin ct i iil Now fresement sow by 4. Step BBS c=2, 753 check, beavd {a} C2] # Safe because *% becomes Afaqonal for Qs - Moar farvenenk colenencbye-d We seached last vow of column 2 , there % no safe postifon. we have to back track. Nokes ple bave ke semove last placed Queen the one == at posftion: b(2 TC] semoved new yous AtN=3 Column =1 2S Oo. o [a Be + @ 2, a 2 3 CAEAZ step 113 2 fle l,%=3 boasd C2] (J = safe fesement column by 4 (a Xe [x px Px De [> @ Qe Step ao% c=a,t=0 boavd (oJ [2] # safe: fresernent vou by 4 step ale C=Q, t=) : boasd [1] (2] = Safe Fheverment column by 4 Step. 310% C= 3) 7=O beard fo]{s] # safe thevement vow by 4 Cw0CE_ Og ————__ LLU Step 3.12 c=, T=! board (1Jl2] # Safe Now fesement Tow by 4 rack, B28 C=], Ted board (2](s] # safe Now fresement row byt Step S32 cea, 023 board (s]fs] # safe $0) we veached the last column and last row. Do back track fag wermove last placed Queen boaed (1 J(2] % vermoved col=2 vow =I+1=2 et 2.3 Step-228 c=2, 722 ° fed |) | board (2](2] # Safe | New Freserment row by 4 > [ Xx 3 Q\K Step 213% C= 2) B23 board (3](2] ¢ safe we reached last vow and last Column. do backtrack?ng boasd [e]fo] % cemoved new set “Bou =| col =o (LLPP APLAR IBODAN An nn Step og C=0, 2-1 board (iT (oJ = cafe thevement columo by 4 Step 103 cal, %=0 board Co}(1] 7 safe Now fherement elim by 4 Step Wee C=Hljve) boasd (iJ {iJ # safe Now fhesement edlama by 4 step 28 CHlyver board [2 ]{i] = safe Novo Pacsement Column. by 1 Step a0 3 C=21350 boasd Co] [oJ = Safe Now fhesement column by 4 Step 30 2 C=3, %=0 board (o1(s] # safe- Now thesement row by 4 step a1 3 C= 3, P=) board {11(3] 4 safe Now frevemen{ vous by 4 step 323 C=3) Pe Ope 28 >. board (2T[s] =Safe 0 Qs Fihally we placed all 4 Queens, Q. { Sure gf Subsets Problem 3 ‘ SSP Gh Subsets Roblem & eo a ° bk Sa S81)S29--Sp bi | The problem f to find a subset of & Tver SEE SE RSs Nn | a m % equal bo a gfven postlfve oO postive Thtegers whose su Ne Toteges Vd’. S28, ¢83~----- 5 Example @ Foo $= 113,454 and dae State Space Tsee % Baek. Lash Geaph Colowtng * In Gpaph colosing problem we colo the vertices of graph fn sucha way that no two adjacent vesttes Shave the Same colour: 2 + To this problem woe have qfven a chromali nurnbes . th, whith Ts the least numbes of colours needed to color a graph. OP Ys mee \/ Red , Blue ,Gzeen- oO Blue Red OPN» as af Green Re: Example 3 (88, 4.G,R) State Space Trees

You might also like