Splay trees Go&Ta 10.3. How do you organize your world?

Slides:



Advertisements
Similar presentations
AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
Advertisements

AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
Red-Black Trees 4/16/2017 8:38 AM Splay Trees v z Splay Trees.
CSE 326: Data Structures Splay Trees Ben Lerner Summer 2007.
© 2004 Goodrich, Tamassia, Dickerson Splay Trees v z.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Splay trees CS 202 – Fundamental Structures of Computer Science II.
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.
CSC 2300 Data Structures & Algorithms February 16, 2007 Chapter 4. Trees.
Splay Trees Splay trees are binary search trees (BSTs) that:
Splay Trees and B-Trees
1 Red-Black Trees. 2 Definition: A red-black tree is a binary search tree where: –Every node is either red or black. –Each NULL pointer is considered.
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
Binary Search Trees. BST Properties Have all properties of binary tree Items in left subtree are smaller than items in any node Items in right subtree.
CSC 213 – Large Scale Programming. Implementing Map with a Tree  Accessing root much faster than going to leaves  In real-world, should place important.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
CMSC420: Splay Trees Kinga Dobolyi Based off notes by Dave Mount.
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.
D. ChristozovCOS 221 Intro to CS II AVL Trees 1 AVL Trees: Balanced BST Binary Search Trees Performance Height Balanced Trees Rotation AVL: insert, delete.
Tree Rotations & Splay Trees. BST Structure BST's only perform well when balanced But common cases lead to unbalanced trees.
Data Structures AVL Trees.
CompSci 100E 41.1 Balanced Binary Search Trees  Pathological BST  Insert nodes from ordered list  Search: O(___) ?  The Balanced Tree  Binary 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.
AVL trees1 AVL Trees Height of a node : The height of a leaf is 1. The height of a null pointer is zero. The height of an internal node is the maximum.
IT 60101: Lecture #121 Foundation of Computing Systems Lecture 12 Trees: Part VII.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
AVL Trees 1. Balancing a BST Goal – Keep the height small – For any node, left and right sub-tree have approximately the same height Ensures fast (O(lgn))
Review for Exam 2 Topics covered: –Recursion and recursive functions –General rooted trees –Binary Search Trees (BST) –Splay Tree –RB Tree –K-D Trees For.
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
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
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.
1 Red-Black Trees. 2 A Red-Black Tree with NULLs shown Black-Height of the tree = 4.
11/20/2016IT 2791 Is this an AVL tree?
Lecture 23 Red Black Tree Chapter 10 of textbook
AA Trees.
Red-Black Tree Neil Tang 02/07/2008
Red-Black Tree Neil Tang 02/04/2010
BCA-II Data Structure Using C
G64ADS Advanced Data Structures
Binary search tree. Removing a node
Topics covered (since exam 1):
Red Black Trees
Balanced 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.
Introduction Applications Balance Factor Rotations Deletion Example
Balanced Trees AVL : Adelson-Velskii and Landis(1962)
Splay Trees.
SPLAY TREE Features Binary Search Tree Self adjusting balanced tree
Binary Search Tree Chapter 10.
Red Black Trees.
Lecture 25 Splay Tree Chapter 10 of textbook
Binary Trees, Binary Search Trees
AVL Tree A Balanced Binary Search Tree
Topics covered (since exam 1):
Binary Search Tree AVL Tree
Topics covered (since exam 1):
Tree Rotations & Splay Trees
Red-Black Trees.
SPLAY TREES.
Red-Black Trees 1/16/2019 1:56 PM Splay Trees v z Splay Trees.
Topics covered (since exam 1, excluding PQ):
CMSC 341 Splay Trees.
Non-Linear Structures
CMSC 341 Splay Trees.
Topics covered (since exam 1):
CMSC 341 Splay Trees.
Splay Trees Binary search trees.
Topic 10 Trees.
More on Randomized Data Structures
Presentation transcript:

Splay trees Go&Ta 10.3

How do you organize your world?

“move to front” heuristic …

splay trees A method that modifies a binary search tree (bst) Something like a rotation in AVL There are 3 operations: zig-zig, zig-zag, and zig

splay treeszig-zig T2 T3T4 T1 z y x x and y are right children (or left children, symmetry)

splay treeszig-zig T2 T3T4 T1 z y x T2 T3 T4 T1 z y x zig-zig

splay treeszig-zag T4 T2T3 T1 z y x one of x and y is a left children and the other is a right child (also symmetry)

splay treeszig-zag T4 T2T3 T1 z y x T4 T2T3 T1 zy x zig-zag

splay treeszig T2 T3T4 T1 y x w x has no grandparent (also symmetry)

splay treeszig T2 T3T4 T1 y x w zig T4 T2T3 T1 yw x

splay trees We repeat these splay steps until x becomes the root When do we splay? we insert k into the bstree x is the new node with key k we search for k in the bstree x is node with key k or node where we stopped search we delete k from the bstree delete method ultimately removes a leaf the leaf is x

splay trees Advantages: frequently accessed data moves nearer to root the “move to front” heuristic average performance is O(log(n)) simple no additional information/data required add-on to bstree

splay trees Disdvantages: worst case height can be linear O(n)

splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?

splay treesrefresher Nodes in a Complete Binary Tree

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: …

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: …

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree

splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree Average path length is then O(log(n))

splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?

splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth? Answer: average depth would be more meaningful

splay trees Show me a demo