Splay - CSE 4101/5101 Prof Andy Mirzaian Splay Tree Self...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 4101/5101 Splay Tree: Self Adjusting BST Prof. Andy Mirzaian
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees 2-3-4 Trees Red-Black Trees SELF ADJUSTING WORST-CASE EFFICIENT competitive competitive? Linear Lists Multi-Lists Hash Tables DICTIONARIES 2
Image of page 2
References: Lecture Note 3 AAW animation 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Self-Adjusting Binary Search trees § Red-Black trees guarantee that each dictionary operation (Search, Insert, Delete) takes O(log n) time in the worst-case . They achieve this by enforcing an explicit “balance” constraint on the tree. § Can we endow self-adjusting feature to the standard BST by the use of appropriate rotations to restructure the tree and improve the efficiency of future operations in order to keep the amortized cost per operation low? Is there a simple self-adjusting data structure that guarantees O(log n) amortized time per dictionary operation? YES , Splay trees . § As with Red-Black trees, Splay trees give the following guarantee: Any sequence of m dictionary operations on an initially empty dictionary takes in total O(m log n) time, where n is the max size of the dictionary during this sequence. However, a single dictionary operation on Splay trees in the worst-case may cost up to Θ (n) time. § Splay Trees maintain a BST in an arbitrary state, with no “balance” information/constraint. However, they perform the simple, uniformly defined, splay operation after each dictionary operation. A splay operation on BSTs is analogous to Move-to-Front on linear lists. 4
Image of page 4
Generic Splay § GenericSplay(x): Consider the links on the search path of node x in BST T. This operation performs one rotation per link on this path in some appropriate order to move node x up to the root of T. § The number of rotations (at a cost of O(1) per rotation) done by GenericSplay(x) is depthT(x), i.e., depth of x in T before the splay. Access cost of node x is O(1+ depthT(x)). § Generic Splay tree: This is an arbitrary BST such that after each dictionary operation we perform GenericSplay(x), where x is the deepest node accessed by the dictionary operation that is still in the tree. The cost of the dictionary operation, including the splay, is O(1+depth(x)). Which node is x? Ø Successful search: x is the node just accessed. Ø Unsuccessful search: x is parent of the external node just accessed. Ø Insert: x is the node now holding the insertion key. Ø Unsuccessful Delete: same as unsuccessful search. Ø Successful Delete: x is parent of the spliced-out node. § Any sequence of m dictionary operations takes O(m+R) time, where R is the total number of rotations done by the generic splay operations in the sequence. So, we need to find an upper bound on R. 5
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Naïve Splay NaïveSplay(x): A series of single rotations up the tree: while p[x]  nil do Rotate(p[x],x) Exercise: Show that there is an adversarial sequence of n dictionary operations on an initially empty BST on which NaïveSplay takes (n2) time total, i.e., amortized (n) time per dictionary operation.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern