zip trees knuth80knuth80.elfbrink.se/.../2018/01/tarjan_zip_trees_knuth80.pdf · 2018. 2. 6. ·...
TRANSCRIPT
![Page 1: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/1.jpg)
Zip TreesRobertE.Tarjan
PrincetonUniversity&IntertrustTechnologies
Pitea,Sweden,9January2018
ToDon,whoinspiredmetodesignandanalyzealgorithms
![Page 2: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/2.jpg)
ObservationsOverthelast60years,computerscientistshavedevelopedmanybeautifulandtheoreticallyefficientalgorithms.
Butcomputerscienceisstill ayoungfield.
Wehaveoftensettledforthefirst(goodenough)solution.
Itmaynotbethebest– thedesignspaceisrich.
![Page 3: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/3.jpg)
Goal:simplicityIdentifythesimplestpossibleefficientmethodstosolvebasicproblems:algorithmsfrom“thebook”
ala“proofsfromthebook”(Erdős)Algorithmsassimpleaspossible,withprovable resourcebounds
forimportantinputclasses,andefficientinpractice
![Page 4: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/4.jpg)
“Makeeverythingassimpleaspossible,butnotsimpler”- Einstein
Sometimes,simplicityiscritical,notjustdesirable,notablyinconcurrent algorithms.
Makingaconcurrentalgorithmcorrectisnotoriously hard.Thesimplertheunderlyingidea,thegreaterthechanceofsuccess.
![Page 5: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/5.jpg)
Exampleofsimplicity:Zip Trees
(imagefromStreetArtonPinterest)
![Page 6: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/6.jpg)
Dictionary:containsasetS ofitems,eachwithassociatedinformation.
Operations:Access(x):Determineifx isinS.Ifso,returnx’s information.
Insert(x):(x notinS)Insertx anditsinformation.
Delete(x):(x inS)Deletex anditsinformation.
![Page 7: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/7.jpg)
BinarysearchUniverseofitems(orofaccesskeysorindexvalues)istotallyordered,allowingbinarycomparison
Binarysearch:MaintainS insortedorder.Tofindx inS:IfS empty,stop(failure).IfS non-empty,comparex tosomeitemy inS.Ifx =y,stop(success).Ifx <y,searchin{z inS|z <y}.Ifx >y,searchin{z inS|z >y}.
![Page 8: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/8.jpg)
Implementation:binarysearchtree
F
M
X
P
D
B E
![Page 9: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/9.jpg)
Binarytree:Eachnodex hasaleftchildx.leftandarightchildx.right,eitherorbothofwhichcanbenull.Anodeisbinary,unary,oraleaf ifithas0,1,or2nullchildren,respectively.
n =#(non-null)nodesdepthofx:lengthofpathfromroottox,roothasdepth0
heightofx:maxlengthofapathfromx toaleaf,leaveshavedepth0
![Page 10: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/10.jpg)
Binarysearchtree
Items(keyplusdata)innodes,onepernode,insymmetricorder(in-order):itemsinleftsubtreeareless,itemsinrightsubtree aregreaterinkeyorder.
TofindanitemtakesO(d +1)time,whered =depthofitem’snode,orofnullnodereachedbysearchifitemisnotintree.
![Page 11: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/11.jpg)
Binarysearchtree
F
M
X
P
D
B E
![Page 12: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/12.jpg)
BestcaseAllleaveshavedepthswithin1:depth⌊lgn⌋.
(lg:base-twologarithm)
Canachieveiftreeisstatic(orinsertionorderdeterminedoff-line)
E
MB
F I L O RD TA
G S
Q
K
C JH P U
![Page 13: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/13.jpg)
(Leaf)InsertionSearch.Replacenullbynodewithitem.InsertR F
M
X
P
D
B E
![Page 14: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/14.jpg)
LeafInsertionSearch.Replacenullbynodewithitem.InsertR F
M
X
P
D
B E
R
![Page 15: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/15.jpg)
WorstcaseNaturalbutbadinsertionorder:sorted.InsertA,B,C,D,E,F,G,…
Depthoftreeisn – 1.Worst-caseaccesscostisn.
=list!
A
B
C
D
E
F
G
![Page 16: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/16.jpg)
Waystoimproveefficiency
• Balance: AVLtrees(Adelson-Velskii &Landis1962),red-blacktrees(Bayer1972;Guibas &Sedgewick1978),weakAVLtrees(Sen&Tarjan 2009)…
• Self-adjustment: Splaytrees(Sleator &Tarjan1983)
• Randomization:Zip trees
![Page 17: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/17.jpg)
AnAVLtree(imagefromWikipedia)
![Page 18: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/18.jpg)
Ared-blacktree(imagefromWikipedia)
![Page 19: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/19.jpg)
ASplayTree
(imagebyJorgeStolfi)
![Page 20: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/20.jpg)
Rotation(restructuringprimitive)
rotateatxrotateatyy
x
x
y
A B
C A
B C
z z
right
left
20
![Page 21: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/21.jpg)
Zip Trees
Idea:Oninsertion,chooseaheightforanitemandinsertitatthegivenheight,orclosetoit.Chooseheightslikethoseinabest-caseBST:½thenodesatheight0,¼atheight1,1/8atheight2…
Choosetheheightsrandomly.
![Page 22: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/22.jpg)
![Page 23: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/23.jpg)
Wecannotchooseheightsexactly.
Instead,foreachnodetobeinsertedwechoosearank,asfollows:flipafaircoinandcountthenumberofheadsbeforethefirsttail.Therankofanodedoesnotchangewhileitisinthetree.
Therankofanodehasageometric distribution:anodehasrankk withprobability1/2k +1.
Wewanttheheightofanodetobewithinaconstantfactorofitsrank.
![Page 24: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/24.jpg)
Zip*TreeAbinarysearchtreeinwhicheachnodehasarankchosenrandomlyoninsertion,withnodessymmetricallyorderedbykeyandheaporderedbyrank,breakingranktiesinfavorofsmallerkey:
x.left.key <x.key <x.right.keyx.left.rank <x.rankx.right.rank ≤x.rank
*Zip:“tomoveveryfast”
![Page 25: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/25.jpg)
AZip Tree
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
![Page 26: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/26.jpg)
Zip treeinsertion?
Rootinsertion(Stephenson1980)
Letx betheitemtobeinserted.Followthesearchpathforx,unzipping itbysplittingitintoapathPofnodeswithkeyslessthanthatofxandapathQofnodeswithkeysgreaterthanthatofx.MakethetopnodeofPtheleftchildofx andthetopnodeofQ therightchildofx.
![Page 27: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/27.jpg)
F
P
X
R
D
C E
Q
Y
H
A MG
InsertN
![Page 28: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/28.jpg)
F
P
X
R
D
C E
Q
Y
H
A MG
InsertN N
![Page 29: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/29.jpg)
F
P
X
R
D
C E
Q
Y
H
A MG
InsertNUnzipsearchpath
N
![Page 30: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/30.jpg)
FP
X
R
D
C E
Q
Y
H
A MG
N
![Page 31: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/31.jpg)
Ziptreeinsertion:hybridofleaf&rootinsertion
(Sprugnoli 1980;Martinez&Roura 1998)
Toinsertx: Chooseitsrank.Searchforxuntilreachingthenodey thatx shouldreplace. Unziptherestofthesearchpath(fromydown)bysplittingitintoapathPofnodeswithkeyslessthanx’sandapathQofnodeswithkeysgreaterthanx’s.MakethetopofPtheleftchildofxandthetopofQ therightchildofx.Makex achildoftheoldparentofy.
![Page 32: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/32.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
![Page 33: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/33.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
InsertJ
![Page 34: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/34.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
InsertJrank=2
![Page 35: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/35.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
InsertJrank=2ReplaceH
![Page 36: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/36.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
InsertJrank=2ReplaceHUnzippathfromH
![Page 37: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/37.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
InsertJrank=2ReplaceHUnzippathfromH J2
![Page 38: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/38.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
J2
![Page 39: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/39.jpg)
Aziptree(imagefromStreetArtonPinterest)
![Page 40: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/40.jpg)
Ziptreedeletion:Inverseofinsertion
Searchforthenodex tobedeleted.Zip thepathfromx toitspredecessor(inkeyorder)withthepathfromx toitssuccessor(inkeyorder),bymergingthemindecreasingrankorder,breakingtiesinfavorofsmallerkey,toformasinglepathP.ReplacexasachildofitsparentbythetopnodeofP.
![Page 41: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/41.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
DeleteP
J2
![Page 42: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/42.jpg)
F
P
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2 3
MG0
3
11
DeletePZipthepathsfromPtoMandPtoQ
J2
![Page 43: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/43.jpg)
F
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2
MG0
3
11
DeletePZipthepathsfromPtoMandPtoQ J2
![Page 44: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/44.jpg)
F
X
R
D
C E
Q
Y
H
A0
1 0
0
1
21
2
MG0
3
11
J2
![Page 45: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/45.jpg)
Staticpropertiesofziptrees
Expectedrootrank:lgn +O(1)RootrankisO(logn)withhighprobabilityE(nodedepth)=1.5lgn+O(1)(Prodinger 1996)TreedepthisO(logn)withhighprobabilityTreestructureisuniquelydeterminedbyranks:
History-independentdatastructure
![Page 46: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/46.jpg)
Dynamicpropertiesofzip trees
Expectedrestructuringtimetoinsertordeleteanodeofrankk =O(k).ExpectedrestructuringtimeisO(1)ProbabilityofrestructuringtakingO(k)timeisexponentiallysmallinkInsertion/deletioncanbedonepurelytop-downNorotationcases,justunzippingandzippingNoswappingondeletion
![Page 47: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/47.jpg)
Arezip treesnew?
Azip treeisatreap (Aragon&Seidel1996)withadifferentwayofchoosingranksanddifferentinsertion/deletionalgorithms.Zip treesallowrankties;treaps don’t.Azip treeisabinary-treerepresentationofaskiplist(Pugh1990)
![Page 48: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/48.jpg)
Atreap(imagefromWikipedia)
![Page 49: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/49.jpg)
Askiplist(imagebyIgorOstrovsky)
![Page 50: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/50.jpg)
Zip Trees:Summary
Insertionsanddeletionsaresimpleandefficient,takeO(1)expectedrestructuring,andarepurelytop-down
History-independentNorestructuringonaccessStandardbinarytreerepresentation:lessspacethanskiplists
O(lglgn)balancebitspernodeCanbreakranktiesbyusingfractionalranks,
improvesE(depth)by8%Canmodifytosupportfrequency-biasedaccess
![Page 51: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/51.jpg)
Currentwork
Develop,analyze,andimplementefficientnon-blockingconcurrent zip trees
![Page 52: Zip Trees Knuth80knuth80.elfbrink.se/.../2018/01/Tarjan_Zip_Trees_Knuth80.pdf · 2018. 2. 6. · Zip tree insertion: hybrid of leaf & root insertion (Sprugnoli1980; Martinez & Roura1998)](https://reader033.vdocuments.us/reader033/viewer/2022053122/60aa378e7ab2324ce0130360/html5/thumbnails/52.jpg)
Thanks!