Skip to main content

Splaying Preorders and Postorders

  • Conference paper
  • First Online:
Algorithms and Data Structures (WADS 2019)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 11646))

Included in the following conference series:

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

$$\begin{aligned} \text {preorder}(T)&= (r)\oplus \text {preorder}(L)\oplus \text {preorder}(R)\\ \text {postorder}(T)&= \text {postorder}(L)\oplus \text {postorder}(R)\oplus (r), \end{aligned}$$

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. 1.

    Inserting the nodes of preorder(T) into an empty tree via splaying costs O(n). (Theorem 2.)

  2. 2.

    Inserting the nodes of postorder(T) into an empty tree via splaying costs O(n). (Theorem 3.)

  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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    We absorb the search cost into the rotations.

  2. 2.

    Note that \(O(\log n)\) amortized cost per splay is a corollary of this.

  3. 3.

    The following definitions and theorems are taken from [13, Chapter 1.3], almost verbatim.

  4. 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. 5.

    This is because the manner in which Splay restructures the access path is independent of nodes outside the path.

  6. 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. 7.

    The first two invariants dictate that the ancestors of sub-roots form a right-toothed comb.

  8. 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

  1. Adel’son-Vel’skii, G., Landis, E.: An algorithm for the organization of information. Sov. Math. Dokl. 3, 1259–1262 (1962)

    Google Scholar 

  2. Akra, M., Bazzi, L.: On the solution of linear recurrence equations. Comput. Optim. Appl. 10(2), 195–210 (1998)

    Article  MathSciNet  Google Scholar 

  3. Chalermsook, P., Goswami, M., Kozma, L., Mehlhorn, K., Saranurak, T.: Pattern-avoiding access in binary search trees. In: FOCS, pp. 410–423 (2015)

    Google Scholar 

  4. Chaudhuri, R., Höft, H.: Splaying a search tree in preorder takes linear time. ACM SIGACT News 24(2), 88–93 (1993)

    Article  Google Scholar 

  5. Cole, R.: On the dynamic finger conjecture for splay trees. Part II: the proof. SICOMP 30(1), 44–85 (2000)

    Article  Google Scholar 

  6. 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)

    Article  Google Scholar 

  7. Demaine, E., Harmon, D., Iacono, J., Kane, D., Pǎtraşcu, M.: The geometry of binary search trees. In: SODA, pp. 496–505 (2009)

    Google Scholar 

  8. Fox, K.: Upper bounds for maximally greedy binary search trees. In: WADS, pp. 411–422 (2011)

    Google Scholar 

  9. Goyal, N., Gupta, M.: Better analysis of binary search tree on decomposable sequences. Theor. Comput. Sci. 776, 19–24 (2019)

    Article  MathSciNet  Google Scholar 

  10. Guibas, L., Sedgewick, R.: A dichromatic framework for balanced trees. In: FOCS, pp. 8–21 (1978)

    Google Scholar 

  11. Haeupler, B., Sen, S., Tarjan, R.: Rank-balanced trees. TALG 11(4), 30 (2015)

    Article  MathSciNet  Google Scholar 

  12. Iacono, J., Langerman, S.: Weighted dynamic finger in binary search trees. In: SODA, pp. 672–691 (2016)

    Google Scholar 

  13. Kozma, L.: Binary search trees, rectangles and patterns. Ph.D. thesis, Saarland University (2016)

    Google Scholar 

  14. Kujala, J., Elomaa, T.: The cost of offline binary search tree algorithms and the complexity of the request sequence. TCS 393, 231–239 (2008)

    Article  MathSciNet  Google Scholar 

  15. Levy, C., Tarjan, R.: A new path from splay to dynamic optimality. In: SODA, pp. 1311–1330 (2019)

    Chapter  Google Scholar 

  16. Lucas, J.: Canonical forms for competitive binary search tree algorithms. Technical report, Rutgers University (1988)

    Google Scholar 

  17. Munro, I.: On the competitiveness of linear search. In: ESA, pp. 338–345 (2000)

    Google Scholar 

  18. Nievergelt, J., Reingold, E.: Binary search trees of bounded balance. SICOMP 2(1), 33–43 (1973)

    Article  MathSciNet  Google Scholar 

  19. Pettie, S.: Splay trees, davenport-schinzel sequences, and the deque conjecture. In: SODA, pp. 1115–1124 (2008)

    Google Scholar 

  20. Pettie, S.: Applications of forbidden 0–1 matrices to search tree and path compression-based data structures. In: SODA, pp. 1457–1467 (2010)

    Google Scholar 

  21. Sleator, D., Tarjan, R.: Self-adjusting binary search trees. J. ACM 32(3), 652–686 (1985)

    Article  MathSciNet  Google Scholar 

  22. Sundar, R.: On the deque conjecture for the splay algorithm. Combinatorica 12(1), 95–124 (1992)

    Article  MathSciNet  Google Scholar 

  23. Tarjan, R.: Amortized computational complexity. SIAM J. Algebraic Discrete Meth. 6(2), 306–318 (1985)

    Article  MathSciNet  Google Scholar 

  24. Tarjan, R.: Sequential access in splay trees takes linear time. Combinatorica 5(4), 367–378 (1985)

    Article  MathSciNet  Google Scholar 

  25. Wilber, R.: Lower bounds for accessing binary search trees with rotations. SICOMP 18(1), 56–67 (1989)

    Article  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Caleb C. Levy .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics