Rushi ta imment-1
Cse- 9
nro )INo:-O )2 itho Deiw Apaluss
) DisT0iNT SET DATA STR UCTURE
Two sets oe calleed, Aisjoimt dets hey dont fae omy
eleme uw Comm on tthe mtuueti set s mul Aet
A ata stbuutue that stoues disjoint "Bubset s elemevds
is called disjoint et dota stucime Tt Klho knou
os
Uuio- fiuel data stuuetune
xapleTke is set elemedti 3 0,1,2,3,4,53 There oe
6 elements S N: 6. Uke M aswoto mamaje the
conmechvty
the ele mentg.
Aumbtoy ALB eljeai ae conmpcted enly i asLA]= auCA
a s ume thot R ús ueot element, then' dvCRI - R
Each eloment is the Sest o iteae n a l dhe subsets ecause
0suL i , whene i ieleMment n the det
nien l,0)
RootCo) us set as posientoot (1).Tha value s a r 3
wull choemom Ito0
3 y5
2iow(O,2)
sueot lo)
Nouw, we l l set Root (2) 0 s paent of
Volue e alo3 wil chamyeuomO to 2
O
3Uiew(4) uoot
Juoot
(
Roo&C4) us set as orent Aoot (3)
Valu y
o a c wul chone om 8to
O 23 y ds5
cA 2 ol E 5
A)Union l,4) 4eot
Root (4) ús set as pott ueot 1)
alue ass [23 chonges "om 2to y
O 2 3 d4
Nauo, we cam suosun uind msraton check whethe
ALB ae Conmetted
LOO A B ane aame dhe i t means that A B
ae sone &ubset and are Comyected
tud l ) 9 hane some suoot ie. . t
0sue
tommeteol oLult s Toue
ndd 3, 6) 3 5 sume SuDot
do mot hawe
Thus earns chey a e not onyeeted 2 u u l t iralue.
Zblement ation
uint PC3 nd CNI;
u
mi tialize ()
{
toi t i:O; i<N; ut)
PC-
int qmol (unt )L
(Pl9 ==) Jutwnn;
Ltwm find (PC)
3
v i l unisn wt a, unt b)
Jnt ne a)
wwt d ))
) etunn
PEy
2 MEDIAN AND ORDER STATISTICS
SEeT
eliaw cam be delned as the element n the dala set
whio debasuates thë highe Ro o the dota Aomble
L o the Jow hall
hHe dthe unbut ine pdk we ake cthe iddlle element
t e d daka T inbut.
sine J e we oitk am
ae ddle two elements im Leted sbueom
loimd Hhe kt paLd gtadisbics al set e n
elenmtrd
allo am steps should be folloed.
T) t the mbut asay un w.owasing ncRR
Retwn the dlement ot K-1 mde in Losked omay
muw(gement)
k aimum ( o t elenment)
median= M*
Deunradi en Raundomi d- Seled (A,P,v,)
hCD-V) dhen getun ALP]
r-Yathen (A, P,2)
K 9-P+
i - K) then setum A[]
S4 (i<K) Hhen tusm Ramdomirud Select (A, P, T-l,
Srtwm Ramdomiud-Select A,r+l, V,d-K)
/wm Cowpleniety O(nJogn)
ampl- - 7 28
oa 6o13 5 83 2
we
6 s pi vot bout,ten anay s '
25B48E
Now, K H-1+H =
Neu,SontadArar8 1o I13
At - +,elements
Code Umt muanC)
uimt auC ) = $6, 1o, 13,5,8,3,2,11
wt Na 8i2 la)/Ai a [oJ)3
int Ka4
& t i t S(oM7 A +N);
Aet 4 unt>: iteato t S. bgn )
aduance (ite , K-I)
Cout << J t 2 < " \ m " :
utwm 0