Abstract
Let T be a binary search tree of n nodes with root r, left subtree \(L=\text {left}(r)\), and right subtree \(R=\text {right}(r)\). The preorder and postorder of T are defined as follows: the preorder and postorder of the empty tree is the empty sequence, and
where \(\oplus \) denotes sequence concatenation. (We will refer to any such sequence as a preorder or a postorder). We prove the following results about the behavior of splaying [21] preorders and postorders:
-
1.
Inserting the nodes of preorder(T) into an empty tree via splaying costs O(n). (Theorem 2.)
-
2.
Inserting the nodes of postorder(T) into an empty tree via splaying costs O(n). (Theorem 3.)
-
3.
If \(T'\) has the same keys as T and T is weight-balanced [18] then splaying either preorder(T) or postorder(T) starting from \(T'\) costs O(n). (Theorem 4.)
For 1 and 2, we use the fact that preorders and postorders are pattern-avoiding: i.e. they contain no subsequences that are order-isomorphic to (2, 3, 1) and (3, 1, 2), respectively. Pattern-avoidance implies certain constraints on the manner in which items are inserted. We exploit this structure with a simple potential function that counts inserted nodes lying on access paths to uninserted nodes. Our methods can likely be extended to permutations that avoid more general patterns. The proof of 3 uses the fact that preorders and postorders of balanced search trees do not contain many large “jumps” in symmetric order, and exploits this fact using the dynamic finger theorem [5, 6]. Items 2 and 3 are both novel. Item 1 was originally proved by Chaudhuri and Höft [4]; our proof simplifies theirs. These results provide further evidence in favor of the elusive dynamic optimality conjecture [21].
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.
We absorb the search cost into the rotations.
- 2.
Note that \(O(\log n)\) amortized cost per splay is a corollary of this.
- 3.
The following definitions and theorems are taken from [13, Chapter 1.3], almost verbatim.
- 4.
A priori, the traversal conjecture follows from dynamic optimality conditioned on Splay being optimal with low “additive overhead.” The authors recently proved that this corollary is actually unconditional [15].
- 5.
This is because the manner in which Splay restructures the access path is independent of nodes outside the path.
- 6.
In fact, this property is shared by any permutation \(\pi \) for which every node in T appears in \(\pi \) before those in its left and right subtrees.
- 7.
The first two invariants dictate that the ancestors of sub-roots form a right-toothed comb.
- 8.
Technically, since \(|L|/|S|<(|L|+1)/(|S|+1)\), we need to pick S sufficiently large for a given alpha, and offset the recurrence term by a corresponding constant. This does not asymptotically affect the result.
References
Adel’son-Vel’skii, G., Landis, E.: An algorithm for the organization of information. Sov. Math. Dokl. 3, 1259–1262 (1962)
Akra, M., Bazzi, L.: On the solution of linear recurrence equations. Comput. Optim. Appl. 10(2), 195–210 (1998)
Chalermsook, P., Goswami, M., Kozma, L., Mehlhorn, K., Saranurak, T.: Pattern-avoiding access in binary search trees. In: FOCS, pp. 410–423 (2015)
Chaudhuri, R., Höft, H.: Splaying a search tree in preorder takes linear time. ACM SIGACT News 24(2), 88–93 (1993)
Cole, R.: On the dynamic finger conjecture for splay trees. Part II: the proof. SICOMP 30(1), 44–85 (2000)
Cole, R., Mishra, B., Schmidt, J., Siegel, A.: On the dynamic finger conjecture for splay trees. Part I: splay sorting \(\log n\)-block sequences. SICOMP 30(1), 1–43 (2000)
Demaine, E., Harmon, D., Iacono, J., Kane, D., Pǎtraşcu, M.: The geometry of binary search trees. In: SODA, pp. 496–505 (2009)
Fox, K.: Upper bounds for maximally greedy binary search trees. In: WADS, pp. 411–422 (2011)
Goyal, N., Gupta, M.: Better analysis of binary search tree on decomposable sequences. Theor. Comput. Sci. 776, 19–24 (2019)
Guibas, L., Sedgewick, R.: A dichromatic framework for balanced trees. In: FOCS, pp. 8–21 (1978)
Haeupler, B., Sen, S., Tarjan, R.: Rank-balanced trees. TALG 11(4), 30 (2015)
Iacono, J., Langerman, S.: Weighted dynamic finger in binary search trees. In: SODA, pp. 672–691 (2016)
Kozma, L.: Binary search trees, rectangles and patterns. Ph.D. thesis, Saarland University (2016)
Kujala, J., Elomaa, T.: The cost of offline binary search tree algorithms and the complexity of the request sequence. TCS 393, 231–239 (2008)
Levy, C., Tarjan, R.: A new path from splay to dynamic optimality. In: SODA, pp. 1311–1330 (2019)
Lucas, J.: Canonical forms for competitive binary search tree algorithms. Technical report, Rutgers University (1988)
Munro, I.: On the competitiveness of linear search. In: ESA, pp. 338–345 (2000)
Nievergelt, J., Reingold, E.: Binary search trees of bounded balance. SICOMP 2(1), 33–43 (1973)
Pettie, S.: Splay trees, davenport-schinzel sequences, and the deque conjecture. In: SODA, pp. 1115–1124 (2008)
Pettie, S.: Applications of forbidden 0–1 matrices to search tree and path compression-based data structures. In: SODA, pp. 1457–1467 (2010)
Sleator, D., Tarjan, R.: Self-adjusting binary search trees. J. ACM 32(3), 652–686 (1985)
Sundar, R.: On the deque conjecture for the splay algorithm. Combinatorica 12(1), 95–124 (1992)
Tarjan, R.: Amortized computational complexity. SIAM J. Algebraic Discrete Meth. 6(2), 306–318 (1985)
Tarjan, R.: Sequential access in splay trees takes linear time. Combinatorica 5(4), 367–378 (1985)
Wilber, R.: Lower bounds for accessing binary search trees with rotations. SICOMP 18(1), 56–67 (1989)
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
Levy, C.C., Tarjan, R.E. (2019). Splaying Preorders and Postorders. 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_37
Download citation
DOI: https://doi.org/10.1007/978-3-030-24766-9_37
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)