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

Daa Unit 2

1) Disjoint sets can be represented using a tree structure where each node represents a set and contains the set name and elements. 2) Common operations on disjoint sets include find, union, and weighted union. 3) The find operation determines which set an element belongs to by traversing the tree to the root node, while union combines two sets by making one root node the parent of the other. Weighted union improves performance by avoiding restructuring of the tree.
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)
46 views12 pages

Daa Unit 2

1) Disjoint sets can be represented using a tree structure where each node represents a set and contains the set name and elements. 2) Common operations on disjoint sets include find, union, and weighted union. 3) The find operation determines which set an element belongs to by traversing the tree to the root node, while union combines two sets by making one root node the parent of the other. Weighted union improves performance by avoiding restructuring of the tree.
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

UNI1-2 3)Weightcd Baton

4) Colapsial Fincd
Sets
Dsipint Con tain
Con eain (om
olves n't Common 1Simple Onion
the sets
Jf such type o Seks a the uneton of sets
then To sbtain
elaments Sets one tree aas
Disjoint the
sootnocle oF
known as cet
set
o ther tre e
n=10, the elements Can be child node of the
Ea: When the
E into 3 dis/oint sets
paatitioned
are
2 disjoint set
S ,7,8,1 F S ; and Sj
thenS;US; al euments of 1j,.
S S,2,1o3
s uch that x is in Sj
be repsesented in a tree
The Gets Cn

oomat (

Sat S

n SDS
S S
These at te possibla tree depresen tatiens

Df be seks
Dispint Sets Openabons
The flouing opeaationg can be erfoamed S,US2
on dis joint Sets 2A2boi
) Pijpint et Union e) Simpla briom
) Simple Find
Repres enbakhon ofs
thisarvay. vepresent te
Data Struckuse
elament of
thot con tain eunent
tore nodas
roi The axay, elument gives the parent
Pointer of the Correspon dinq Esee nodus

E 2 . PL:3 -el27
Simpu Union algevithm
tvea
algovithn ycot ohon
Jn this.
Each Toot noda has a pointer to h nodA
hild f r o t s tsee
tree
t becomas
set name
set to dateSmine ohih setan
element i Curently n, we ollbu o Algo SimpluDrion(i,i)
parent nk ts the vcot node f th
tee
Aray Represontation o S,, se: whse and ase DonodaS F

differenttrees
23 S 2.
PI--S31 ST Ez

w han we Pesrorm

the tvecs , ad S2
Simpla COnionlt, S)
en

S3
S
S The 3oot node of S,
tTeebecomms

mot rocde PS
tha

We vepvesent thetree nodos ustng


an 48
child noele fo the
Pli..n] where n ts the mal
euments,
,Axpo Reparstatahon*

2 Find.
daterminas the voot node e the kra
FrindCt)
the folas
process the folewi elament 1
wproces containin
Now
of
oUnien 6pesahon
Algs SimplaFind (i

Dnion C,22, Onton(,3),


.-. ,0noni,) le
(PLil2o) do
033 i PLiJ
retun i
(n-

time cguired t p3o cets n finds


The tto
S oCn)
at levelithe
fov i ind. opesatio,
tme Complaity is Oli)
Ths n- aiop OpevationsCan be No We Can mproe the ertomance
procesed in timne oln) perahOn y avoidinq
and ind
Union
tree.
deganexafive
the creation
use o weqh ted
we ak
For this ,

Uvnion(J)
Uhion(i,i )
Tule fa
Neighted u) Csllopsing fhd
3
no. onodes tre oith
in tha s a noda on path emi
th
the
than the oof nodo
nodas t
no.
toTs oot and P t roti) He
TDo i s ess
thetre oith xoot J , then
make set PLj) root[G]
thaise mak i t
the patent of Alao Colopsingfird (i)
paent o
hilel PC] >t) do
Algo welyhtedcnion(i,))
aneL: cCunt [7
PL:- Cout[i1 -PL
Ferp- Ptil+P L3,
F(Pt:1> PLi1) then SPLT1
PCi-s
S

PL1-temP
sen
else

wOXst Caie bgund


Tse a hieving
PL: tenP

- ree
a)Initiad Heke
2
2
follbwin Unisn 3
b H e i g h 2
Tyee Onio S,)
Backtvacking:
all
all the
the
and Dynamic progsamming
Jn Gyredy whieh we selet one
solutions among
possible
possible

Soluion which is opkimal

Jo Bocktracking, we obtain the game optimal


Solution with ess no. osteps
cPeqht-3le
->Bounding function:
Sis a function hich neads t

be maimized or minimized for a given proble


Implicit Constraint:

These axe the yles which datesmine


skieh of he tuples in the soltion Space satisfy he
cxiteria ox bounding funtion
Ezplicit constzaint:
These ase the rules shich estsict

eve Soludion to bake on vales only From a given set.

Problem State
Evexy noda in the tree dafines problem starte,
Soluion Space:
A1L tuples that satisfy he explieit
Constoaints
ints dafines a po1sib le salution space for the

Pas tictlax instance o a


problem,
Sution state
These
These axe hese problem state for ohich
path from the yoot the problen state define a

buple in the Solut ion Space.


State pace tyee:
epresent solution Back trockinq mebhod is sid.to be
JP you
space in constraints tha nads to be
tre s called
stde&pace te
Sotne
then the based o
onn

the fom of a tree ,

Live node: been


sabisfhed
The node which has qenerafed and
children not yet been nerated N - u e n ' s Toblem :
1214 (4 Qunn 03
Gun )
all of ohose

E-neda( Ezpandaba noda)


The ive noda hose
. 4 Suis:
childzen axe Curenty being 9unexated is callad E-n. C4

neda C
C, C3

Dead nade
is a qenexafed nodo i.e, e ther not to 62

be expanded fusthex 07 one fob which all its child.


have been qenexared.

Applications o Back tracking


N-uen problem
) Greph colosing, pmblam
3) Sun oF subsets problem

Considlax a x4 ehers boaxd


Brute prce approach to placa
i s based on the There are Quens, the objective is

Fo any given problem, tr UT all possible these Queens on aX chess boerd in such aua
in the
te
SolTie ns that no Sucans should be placed
Brute foree paroblems have mul tiple Solstons Same go (column(Biaqonol postbion
nthis appoah, we try to ind o u saluhons The Ezplicit constvaints Sas 9 uons are to
to solve the Baekoaek be plate On a x hessboasnd in 4s
py obum By using
9 u
constraints
aoe no Quns Can be he Explist eonstyaints says at 8 uauns
The Jmpliut Can

be placad x g chass boaxd in


8wais
nSame vou/eolumn/diagonal.

bn

be heSolukion vetoy, etoy, wha t h e Srnplicies constrai nts ave ne 2Queens sho4
utx2,3, 24
eh wkich uan is plor.i e placed in $ame Tow(coumn diagonal
humbey
i s column
g 3
32
out io veckor are ; is the column nuwnbe
on uwhich ueen i)is placed.

Notposble .Algovithm
Nob posbl
Algo baueen (k,n)

foT i to n dlo

iFplace Ck,i ) Ben

f (k=n') Ben
printC L1.n3
else
Ngenk,n )

T h abave tree ts Called state Space Algo place(k,i)


tree /rebams tre if Q is placed at k Fow and iolumn
8 Quuns Wothesuise sekurns fal te and [ is qlbal as ray

fY-1 t k - i do
Comsidey a 8x8 chess b0axd
let he be 8 Qusens ( L 1 : i) o abs(1L5)-i) abs(j-k
The Objecive is to place tha seburhfalue
chess boad in such
Quees on
on
an .8 XS
an 3
rcbun tue
should be placed a tJay that no 2 Quans
Same fcolumn[diagone
m3 m3
me 2

3
V3

State Spoca
2

yvoph Co lovring Px bam


m 3
>Le be a qoph consisting of a Set of
vextices and a set of edqes
Letm be iven pogitive tatega
2
nroph Colo inq poblam
each ve ter in qvaph în Such a way
coloyin aoaCent
that 2 ver ticcshave Same Colodand

yem toloos o.eused


S luuons
he mn. ho. alogdequited Cslos We qa 8 dteren

th qaph is caled choomaic no.


of tho p*
Backtraeking sin DFS

Boundin
tuneho

hs prob lam is
pmblr /e Sw o
Subsets
tormplauity oF
Theime
3
set S n sbjccks
3.3.3
Given
tt 3 + 3.3 3.3.3 and a postive
N L eighes n
3 3
We have to find
tind a sbs et
3-1 inteaeo m

3uch hat
Su o Sudsets
) S cS
>qiven 5Et abjeka
2) Sum of Subset f elamen ts
A ,each intexnal. naddaomn) time isSpent set uinq
y ne valuts detesmina tha ch;ldsen 8) Find all Subsebs e f given
30
Sum o Subse poums.T m

Covresponding to g colosina
}nce, tDa Eme is boundoo by 6 o ,i1,13,(,18 3
Sabse is incueded t else 0

mn S.m'n=E
nm m- t
o(nm" venset Soution is
6]
State spac ee SoUwtion Spos
Soubion 0,0,03,i0,1,1,0,03,
0,0,1,0,0,13

Shp1 Stast i an empey set he


Step 2 Add to e subset the nazt elament from
list
' an stop wtthot
Ste 3 Jf Subset is having Sum

subset as a S udaon.

:/ steph f subset s .
subset antil we
not feasible
fnd most sui tabu
backtyack threug
then
walut

sleps: Jf. subsethaveTsvisited feasiblu than vepeat Prom step


aU elamen ts finding
wrtheut
Step6 3F ou
O stale subset and i no backtrackirg possite
is

ith ho solauhion.
then sop

Subs et Sum Acion

s Add teumant.
Add d eknnt
s,t
,

27 Adodelknt
5,1o,2, 3 Jnfeasibu col"

s,to,12,15
s,lo, 12, 1s
5,to, 133 28 Add u elerent
Infeasib sobbron
es,to,3, 43
5 , ,13, 18 6
Feasbe dolszon
&lo, 1Sy (30)
,1o,5 Gsoph oleving
Soens inkeqr, itis
s,12,17 ae feasib Let Gbe a vaph and M be t y
be calored in
,3 f i n d hethey
nedes of can

hat no. adiacant nodethaue he


23, Sueh a
wa
S,
m:

8S-3, 34, 4, same. coloy


Sum
Ason paebem has versions
Subse Th
probl
3
Ado elamant 1) M coloying docision

37 nfeasible selkien 2 M colsabili ty aptimzaton

3,34 ehromatic namber.


Add elument Mis called
than
Jneasibsal" dagaa ogiren graph
3,4,12 JF D is
12 apaph be colesed with
can D+ ceavS
2
Feasit Salutrovn
3,2 ff i be
said ts be plana
cam

qvoph is
A ho
diauo n
n o Pan in such wa that
2 edges COSS each othey

map ot th planag naP Convestteo t


Epses entatn o
Alor i then epeat

Algo mcelriny (k) [ e l (ztk] +t) mod (mr)


recuvsive Back Tsa,
5aek Takins

ws fned tsing it (11 o) then retusn


This algo repesentedby its boln
Scharne. The qsaph s
an fo ton do
adiacency ratsix G..n, ..n]. A assi hunt
,2, m e vetice of 9aph ST iCGlki]40) and z(4)- zLj3)
adjacn vesticas ase assiqhed
oluséinc inten. ten break)
3
aye pin ted K is Andex of the mos
veyted Colo iFj ==
(x+D) then reum
3 untilfolse)

vepeat
heztvalue ()
F U Jo) than vehuyn
F Ckn) thun wnite(zn)
else
mcologinq (kt1)
until (fe)

Alo hexhelue ( )
3.. 1[thas been asigndintege valuds in
hange 1 om S-7 adjatent vesties have distind
integes A vae for z[k] is Astesmined n Bhe
Dm 7[k) is assig ned next hishect rno. ud
hieh main tairing distinction fom the adjacent
Vesbees of Vatek.4 mo Swch oby ezist han
*

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy