nrl tr T is init st o on or mor nos suh tht thr is on sint no r, ll th root o T, n th rminin nos r prtition into n isjoint susts T, T,, T n, h o whih is tr, n whos roots r, r,, r n, rsptivly, r hilrn o r. r r r r omputr Sin pt V Th nury - MQuin W Rprsntin Th rprsnttion o nrl tr poss som hr hois: - My th numr o hilrn pr no vry ovr lr rn (possily with no loil uppr limit)? - Sttin n uppr limit rnrs som trs unrprsntl. - vn with n uppr limit, llotin ix numr o pointrs within h no my wst hu mount o sp. - Supportin vril numr o pointrs lso riss prormn issus. - ow n th pointrs orniz or sy trvrsl? os this rquir sonry t strutur within th no? - os th shm provi or iint srh? no insrtion? no ltion? r omputr Sin pt V Th nury - MQuin W
Link Nos mplmnttion Th inry no typ prsnt rlir n xtn or nrl tr rprsnttion. Th pointrs n mn y: - llotin uniorm-siz rry o no pointrs n limitin th numr o hilrn no is llow to hv; - llotin ynmilly-siz rry o no pointrs, ustom-it to th numr o hilrn th no urrntly hs (n r-sizin mnully s n); - usin link list o no pointrs; - usin vtor o no pointrs, rowin s n. h pproh hs pros n ons. r omputr Sin pt V Th nury - MQuin W List o hilrn Rprsnttion or h tr no, stor its t lmnt, (loil) pointr to its prnt no, n list o (loil) pointrs to its hilrn, usin rry s th unrlyin physil strutur: t Pr hl oul us ynmi list o nos inst omputr Sin pt V Th nury - MQuin W
Lt-hilrn/Riht-Silin Rprsnttion or h tr no, stor its t lmnt, (loil) pointr to its prnt no, n (loil) pointrs to its lt hil n its riht silin, usin rry s th unrlyin physil strutur: t Pr Lt hil Riht Silin omputr Sin pt V Th nury - MQuin W Prnt Pointr Rprsnttion or h tr no, stor its t lmnt n (loil) pointr to its prnt no, usin rry s th unrlyin physil strutur: omputr Sin pt V Th nury - MQuin W
quivln Rltions 7 Lt S st. n quivln rltion on S is olltion o orr pirs o lmnts o S suh tht: - or vry x in S, (x, x) is in rlxivity - or vry x n y in S, i (x, y) is in thn (y, x) is lso in symmtry - or vry x, y n z in S, i (x, y) n (y, z) r in thn (x, z) is lso in trnsitivity (x, y) is in thn w sy x is quivlnt to y. x is in S, th st o ll lmnts z o S suh tht (x, y) is in is ll th quivln lss o x, not [x]. omputr Sin pt V Th nury - MQuin W xmpl 8 Lt S th st o intrs throuh. in n quivln rltion on S: x is quivlnt to y i n only i x % n y % r qul. Thn: [] = {,,,,,, 8} [] = {,, 7,,,, } [] = {,, 8,,, 7, } Not tht vry lmnt o S is in xtly on o ths quivln lsss, n tht no two irnt quivln lsss hv ny lmnts in ommon. omputr Sin pt V Th nury - MQuin W
Thorms on quivln lsss Thm: Lt n quivln rltion on st S. Thn i x n y r lmnts o S, ithr [x] = [y] or [x] [y] =. Thm: Lt n quivln rltion on st S. Thn S quls th union o th istint quivln lsss unr. Th lttr thorm is usully sri s syin tht n quivln rltion prtitions st S into isjoint susts, rthr lik uttin pi o ppr into jisw puzzl. So wht os this hv to o with trs? W n rprsnt h quivln lss s nrl tr, n prtitionin s olltion (orst) o suh trs. omputr Sin pt V Th nury - MQuin W xmpl Rllin th rlir xmpl: [] = {,,,,,, 8} [] = {,, 7,,,, } [] = {,, 8,,, 7, } Th quivln lss [] my rprsnt y (ny) nrl tr ontinin th list vlus. or xmpl: 8 8 ivn this rprsnttion, how o w trmin i two vlus r quivlnt? omputr Sin pt V Th nury - MQuin W
trminin quivln Two vlus r quivlnt i thy r in th sm tr. Two vlus r quivlnt i th root nos o thir trs r th sm. W n in th root no y ollowin prnt pointrs upwr s r s possil. or this prolm, no othr typ o trvrsl is nssry, so th prnt "pointr" rprsnttion sri rlir is suiint. 8 omputr Sin pt V Th nury - MQuin W Pth omprssion owvr, quivln trs r not ll qully iint or trminin quivln. Th tr on th riht (low) is prrr us th pth rom h no to th root is o minimum lnth. ivn n quivln tr, suh s th on on th lt, w my improv its prormn y "omprssin" it vrtilly. Whnvr w strt t vlu, sy x, n srh or its root, w my thn tth th no ontinin x irtly to th root. This is known s pth omprssion. 8 8 omputr Sin pt V Th nury - MQuin W
uilin n quivln orst ivn st S n t spiyin whih lmnts r quivlnt (unr som quivln rltion ) w my uil olltion o trs tht rprsnt th quivln lsss o. nitilly, h lmnt is its own lss (ll nos r isolt). Two lmnts, x n y, r quivlnt i n only i th roots o thir rsptiv trs r th sm. isovrin tht two lmnts, x n y, r quivlnt implis tht thir quivln lsss must mr (thir rsptiv trs must join in som mnnr). Two nrl trs my join y mkin th root o on hil o th root o th othr. omputr Sin pt V Th nury - MQuin W xmpl Lt S = {,,,,,,,,, }. nitilly: 7 8 ivn ~: 7 8 ivn ~, 7 8 ~, ~, ~: omputr Sin pt V Th nury - MQuin W
xmpl Th lst stt orrspons to th orst: Now, ivn tht ~ w n to mr th irst two trs: irst in th root o h tr, n thn mk on root th prnt o th othr. t this point, th hoi o whih is to th prnt is ritrry. omputr Sin pt V Th nury - MQuin W xmpl Now w hv th ollowin orst. Suppos w r ivn tht ~ in, w n to mr two trs: r, w pply th Wiht Union Rul: tth th smllr tr to th root o th lrr tr. This rus th vr no pth. omputr Sin pt V Th nury - MQuin W
xmpl 7 Th n rsult is th ollowin orst: whih orrspons to th ollowin prnt pointr rprsnttion: 7 8 omputr Sin pt V Th nury - MQuin W