Abstract
We introduce the zip tree, (Zip: “To move very fast.”) a form of randomized binary search tree that integrates previous ideas into one practical, performant, and pleasant-to-implement package. A zip tree is a binary search tree in which each node has a numeric rank and the tree is (max)-heap-ordered with respect to ranks, with ties broken in favor of smaller keys. Zip trees are essentially treaps [8], except that ranks are drawn from a geometric distribution instead of a uniform distribution, and we allow rank ties. These changes enable us to use fewer random bits per node.
We perform insertions and deletions by unmerging and merging paths (unzipping and zipping) rather than by doing rotations, which avoids some pointer changes and improves efficiency. The methods of zipping and unzipping take inspiration from previous top-down approaches to insertion and deletion by Stephenson [10], Martínez and Roura [5], and Sprugnoli [9].
From a theoretical standpoint, this work provides two main results. First, zip trees require only \(O(\log \log n)\) bits (with high probability) to represent the largest rank in an n-node binary search tree; previous data structures require \(O(\log n)\) bits for the largest rank. Second, zip trees are naturally isomorphic to skip lists [7], and simplify Dean and Jones’ mapping between skip lists and binary search trees [2].
Research at Princeton University partially supported by an innovation research grant from Princeton and a gift from Microsoft.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Seidel and Aragon [8] hinted at the possibility of doing insertions and deletions by unzipping and zipping: in a footnote they say, “In practice it is preferable to approach these operations the other way around. Joins and splits of treaps can be implemented as iterative top-down procedures; insertions and deletions can then be implemented as accesses followed by splits or joins.” But they provide no further details.
- 2.
This issue is not merely theoretical. Reuse of random seeds has led to real-world “denial-of-service” attacks for a number of programming libraries. See http://ocert.org/advisories/ocert-2011-003.html.
References
Chernoff, H.: A measure of asymptotic efficiency for tests of a hypothesis based on the sum of observations. Ann. Math. Stat. 23(4), 493–507 (1952)
Dean, B.C., Jones, Z.H.: Exploring the duality between skip lists and binary search trees. In: Proceedings of the 45th Annual Southeast Regional Conference, pp. 395–400. ACM Press (2007)
Haeupler, B., Sen, S., Tarjan, R.E.: Rank-balanced trees. ACM Trans. Algorithms 11(4), 1–26 (2015)
Hibbard, T.N.: Some combinatorial properties of certain trees with applications to searching and sorting. J. ACM 9(1), 13–28 (1962)
Martínez, C., Roura, S.: Randomized binary search trees. J. ACM 45(2), 288–323 (1998)
Prodinger, H.: Combinatorics of geometrically distributed random variables: left-to-right maxima. Discrete Math. 153(1–3), 253–270 (1996)
Pugh, W.: Skip lists: a probabilistic alternative to balanced trees. Commun. ACM 33(6), 668–676 (1990)
Seidel, R., Aragon, C.R.: Randomized search trees. Algorithmica 16(4–5), 464–497 (1996)
Sprugnoli, R.: Randomly balanced binary trees. Calcolo 17(2), 99–117 (1980)
Stephenson, C.J.: A method for constructing binary search trees by making insertions at the root. Int. J. Comput. Inf. Sci. 9(1), 15–29 (1980)
Tarjan, R.E., Levy, C.C., Timmel, S.: Zip trees. arXiv e-prints arXiv:1806.06726 (2018)
Tarjan, R.E.: Data structures and network algorithms. Society for Industrial and Applied Mathematics, Philadelphia (1983)
Timmel, S.: Zip trees: a new approach to concurrent binary search trees. http://arks.princeton.edu/ark:/88435/dsp01gh93h214f. Senior Thesis, Department of Mathematics, Princeton University (2017)
Vuillemin, J.: A unifying look at data structures. Commun. ACM 23(4), 229–239 (1980)
Acknowledgements
We thank Dave Long for carefully reading the manuscript and offering many useful suggestions, most importantly helping us simplify the iterative insertion and deletion algorithms that appear in the extended version of this paper [11]. We thank Sebastian Wild for correcting the bound on expected node depth in treaps in Sect. 2 and for his ideas on breaking rank ties. Finally, we are grateful to Dominik Kempa for providing us with C++ zip-tree implementations, benchmarks, and general comments.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2019 Springer Nature Switzerland AG
About this paper
Cite this paper
Tarjan, R.E., Levy, C.C., Timmel, S. (2019). Zip Trees. In: Friggstad, Z., Sack, JR., Salavatipour, M. (eds) Algorithms and Data Structures. WADS 2019. Lecture Notes in Computer Science(), vol 11646. Springer, Cham. https://doi.org/10.1007/978-3-030-24766-9_41
Download citation
DOI: https://doi.org/10.1007/978-3-030-24766-9_41
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-24765-2
Online ISBN: 978-3-030-24766-9
eBook Packages: Computer ScienceComputer Science (R0)