Splay Trees Binary search trees.

Slides:



Advertisements
Similar presentations
Splay Trees Binary search trees.
Advertisements

Splay Tree Algorithm Mingda Zhao CSC 252 Algorithms Smith College Fall, 2000.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
1 AVL Trees (10.2) CSE 2011 Winter April 2015.
AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
1 Red-Black Trees. 2 Black-Height of the tree = 4.
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
AVL Trees v z. 2 AVL Tree Definition AVL trees are balanced. An AVL Tree is a binary search tree such that for every internal node v of T, the.
Binary Search Trees Chapter 7 Objectives
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
By : Budi Arifitama Pertemuan ke Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 
Oct 26, 2001CSE 373, Autumn A Forest of Trees Binary search trees: simple. –good on average: O(log n) –bad in the worst case: O(n) AVL trees: more.
CS 61B Data Structures and Programming Methodology Aug 7, 2008 David Sun.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
Jim Anderson Comp 750, Fall 2009 Splay Trees - 1 Splay Trees In balanced tree schemes, explicit rules are followed to ensure balance. In splay trees, there.
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Splay trees Go&Ta How do you organize your world?
SPLAY TREE The basic idea of the splay tree is that every time a node is accessed, it is pushed to the root by a series of tree rotations. This series.
Binary Search Trees Chapter 7 Objectives
COMP261 Lecture 23 B Trees.
Mingda Zhao CSC 252 Algorithms Smith College Fall, 2000
Definitions and Bottom-Up Insertion
COMP9024: Data Structures and Algorithms
G64ADS Advanced Data Structures
Red-Black Trees v z Red-Black Trees Red-Black Trees
AVL Trees 5/17/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Red Black Trees Colored Nodes Definition Binary search tree.
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Topics covered (since exam 1):
Splay Trees Binary search trees.
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
Splay Trees.
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees 9/12/ :44 AM AVL Trees v z AVL Trees.
Splay Trees Binary search trees.
Red Black Trees.
Lecture 25 Splay Tree Chapter 10 of textbook
AVL Trees 11/10/2018 AVL Trees v z AVL Trees.
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Red-Black Trees 11/13/2018 2:07 AM AVL Trees v z AVL Trees.
TCSS 342, Winter 2006 Lecture Notes
Topics covered (since exam 1):
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees v z /20/2018 7:59 AM Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
Topics covered (since exam 1):
Red-Black Trees 11/26/2018 3:42 PM AVL Trees v z AVL Trees.
Red-Black Trees 2018年11月26日3时46分 AVL Trees v z AVL Trees.
The DSW Algorithm The building block for tree transformations in this algorithm is the rotation There are two types of rotation, left and right, which.
v z Chapter 10 AVL Trees Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
Red-Black Trees.
SPLAY TREES.
CMSC 341 Splay Trees.
Algorithms and Data Structures Lecture VIII
Red-Black Trees 1/16/2019 1:56 PM Splay Trees v z Splay Trees.
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
Topics covered (since exam 1, excluding PQ):
CMSC 341 Splay Trees.
AVL Trees 2/23/2019 AVL Trees v z AVL Trees.
Red-Black Trees 2/24/ :17 AM AVL Trees v z AVL Trees.
CMSC 341 Splay Trees.
Topics covered (since exam 1):
Red-Black Trees 5/19/2019 6:39 AM AVL Trees v z AVL Trees.
CMSC 341 Splay Trees.
Red Black Trees Colored Nodes Definition Binary search tree.
Red-Black Trees v z /6/ :10 PM Red-Black Trees
CS210- Lecture 19 July 18, 2005 Agenda AVL trees Restructuring Trees
Presentation transcript:

Splay Trees Binary search trees. Search, insert, delete, and split have amortized complexity O(log n) & actual complexity O(n). Actual and amortized complexity of join is O(1). Priority queue and double-ended priority queue versions outperform heaps, deaps, etc. over a sequence of operations. Two varieties. Bottom up. Top down.

Bottom-Up Splay Trees Search, insert, delete, and join are done as in an unbalanced binary search tree. Search, insert, and delete are followed by a splay operation that begins at a splay node. When the splay operation completes, the splay node has become the tree root. Join requires no splay (or, a null splay is done). For the split operation, the splay is done in the middle (rather than end) of the operation.

Splaying Given x, an internal node of the tree, we splay x by moving x to the root of T thru a sequence of restructurings. The specific restructurings chosen depend upon the relative positions of x, its parent y, and (if it exists) x’s grandparent z. We consider three possible cases:

Possible Substep 1 zig-zig: The node x and its parent are both left (or right) children. then replace z by x, maintaining inorder relationships z x 10 30 y y T4 20 20 T1 x z 30 T2 10 T3 T3 T4 T1 T2 before after

Possible Substep 2 zig-zag: One of x and y is a left child and the other is a right child. Then replace z by x, x having y and z as children and maintaining inorder. z x 10 20 y 30 T1 z y x 30 10 20 T4 T2 T3 T1 T2 T3 T4 before after

Possible Substep 3 zig: x does not have a grandparent. Then rotate x over y, maintaining inorder relationships y x 10 20 x 20 T1 y w w 30 10 30 T2 T3 T4 T1 T2 T3 T4 before after

A Splaying Step For a given x, start performing zig-zig or zig-zag when it has a grandparent, and zig when it does not, until x becomes the root of T. x’s depth: decreases by 2 after each zig-zig/zig-zag decreases by 1 after each zig

When to splay When searching for key k: one of When inserting key k: if k is found in node x, splay x otherwise splay the external node where search ends When inserting key k: splay the newly created internal node where k gets inserted

When to splay 2 When deleting a key k: splay the parent of the node w that gets removed (either the node containing k or one of its descendants). Time for performing each search, insertion or deletion proportional to the associated splay time We can see that so far, worst case can be (n) - so this is not a good data structure from a worst-case point of view

Per Operation Actual Complexity Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order. 1 1 2 1 2

Per Operation Actual Complexity Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order. 1 2 3 1 2 3 4 1 2 3

Per Operation Actual Complexity Worst-case height = n. Actual complexity of search, insert, delete, and split is O(n).