Before applying rotation 2 after rotation x is the

Info icon This preview shows pages 9–15. Sign up to view the full content.

View Full Document Right Arrow Icon
(before applying rotation) 2. (after rotation) x is the root, so stop
Image of page 9

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

View Full Document Right Arrow Icon
© 2004 Goodrich, Tamassia, Dickerson Splay Trees 10 Example Result of Splaying tree might not be more balanced e.g. splay (40,X) before, the depth of the shallowest leaf is 3 and the deepest is 7 after, the depth of shallowest leaf is 1 and deepest is 8 (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) before after first splay after second splay
Image of page 10
© 2004 Goodrich, Tamassia, Dickerson Splay Trees 11 Splay Tree Definition a splay tree is a binary search tree where a node is splayed after it is accessed (for a search or update) deepest internal node accessed is splayed splaying costs O(h), where h is height of the tree – which is still O(n) worst-case O(h) rotations, each of which is O(1)
Image of page 11

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

View Full Document Right Arrow Icon
© 2004 Goodrich, Tamassia, Dickerson Splay Trees 12 Splay Trees & Ordered Dictionaries which nodes are splayed after each operation? use the parent of the internal node that was actually removed from the tree (the parent of the node that the removed item was swapped with) erase(k) use the new node containing the entry inserted put(k,v) if key found, use that node if key not found, use parent of ending external node get(k) splay node method
Image of page 12
© 2004 Goodrich, Tamassia, Dickerson Splay Trees 13 Amortized Analysis of Splay Trees Running time of each operation is proportional to time for splaying. Define rank(v) as the logarithm (base 2) of the number of nodes in subtree rooted at v. Costs: zig = $1, zig-zig = $2, zig-zag = $2. Thus, cost for playing a node at depth d = $d. Imagine that we store rank(v) cyber-dollars at each node v of the splay tree (just for the sake of analysis).
Image of page 13

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

View Full Document Right Arrow Icon
© 2004 Goodrich, Tamassia, Dickerson Splay Trees 14 Cost per zig Doing a zig at x costs at most rank’(x) - rank(x): cost = rank’(x) + rank’(y) - rank(y) - rank(x) < rank’(x) - rank(x).
Image of page 14
Image of page 15
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