26.08.09IT 60101: Lecture #121 Foundation of Computing Systems Lecture 12 Trees: Part VII.

Slides:



Advertisements
Similar presentations
AVL-Trees (Part 2: Double Rotations) Lecture 19 COMP171 Fall 2006.
Advertisements

Splay Tree Algorithm Mingda Zhao CSC 252 Algorithms Smith College Fall, 2000.
Splay Trees CSE 331 Section 2 James Daly. Reminder Homework 2 is out Due Thursday in class Project 2 is out Covers tree sets Due next Friday at midnight.
Binary Search Tree AVL Trees and Splay Trees
EECS 311: Chapter 4 Notes Chris Riesbeck EECS Northwestern.
Splay Trees CSIT 402 Data Structures II. Motivation Problems with other balanced trees – AVL: extra storage/complexity for height fields Periulous delete.
Data Structures Lecture 11 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
CPSC 320: Intermediate Algorithm Design & Analysis Splay Trees (for Amortized Analysis) Steve Wolfman 1.
AVL-Trees (Part 1) COMP171. AVL Trees / Slide 2 * Data, a set of elements * Data structure, a structured set of elements, linear, tree, graph, … * Linear:
AVL Trees / Slide 1 Delete Single rotation Deletion.
CSE 326: Data Structures Splay Trees Ben Lerner Summer 2007.
CSC 213 Lecture 7: Binary, AVL, and Splay Trees. Binary Search Trees (§ 9.1) Binary search tree (BST) is a binary tree storing key- value pairs (entries):
Chapter 6: Transform and Conquer Trees, Red-Black Trees The Design and Analysis of Algorithms.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Splay trees CS 202 – Fundamental Structures of Computer Science II.
AVL-Trees (Part 1: Single Rotations) Lecture COMP171 Fall 2006.
1 Theory I Algorithm Design and Analysis (3 - Balanced trees, AVL trees) Prof. Th. Ottmann.
1 Red-Black Trees. 2 Black-Height of the tree = 4.
Trees and Red-Black Trees Gordon College Prof. Brinton.
1 Efficient Packet Classification using Splay Tree Models Author: Srinivasan.T, Nivedita.M, Mahadevan.V Publisher: IJCSNS International Journal of Computer.
AVL Trees / Slide 1 Balanced Binary Search Tree  Worst case height of binary search tree: N-1  Insertion, deletion can be O(N) in the worst case  We.
CSE 326: Data Structures Lecture #13 Extendible Hashing and Splay Trees Alon Halevy Spring Quarter 2001.
CSC 2300 Data Structures & Algorithms February 16, 2007 Chapter 4. Trees.
Splay Trees Splay trees are binary search trees (BSTs) that:
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
David Kaplan Dept of Computer Science & Engineering Autumn 2001
Splay Trees and B-Trees
CS 61B Data Structures and Programming Methodology Aug 11, 2008 David Sun.
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.
CMSC 341 Splay Trees. 8/3/2007 UMBC CMSC 341 SplayTrees 2 Problems with BSTs Because the shape of a BST is determined by the order that data is inserted,
Course: Programming II - Abstract Data Types Red-Black TreesSlide Number 1 Balanced Search Trees Binary Search Tree data structures can allow insertion,
Red Black Tree Smt Genap Outline Red-Black Trees ◦ Motivation ◦ Definition ◦ Operation Smt Genap
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 8.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
Search Trees Chapter   . Outline  Binary Search Trees  AVL Trees  Splay Trees.
CMSC420: Splay Trees Kinga Dobolyi Based off notes by Dave Mount.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
CSC 213 – Large Scale Programming Lecture 21: Red-Black Trees.
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.
CSE 326: Data Structures Lecture #11 AVL and Splay Trees Steve Wolfman Winter Quarter 2000.
Tree Rotations & Splay Trees. BST Structure BST's only perform well when balanced But common cases lead to unbalanced trees.
1 CompSci 105 SS 2006 Principles of Computer Science Lecture 17: Heaps cont.
AVL Trees / Slide 1 Height-balanced trees AVL trees height is no more than 2 log 2 n (n is the number of nodes) Proof based on a recurrence formula for.
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.
Fundamental Data Structures and Algorithms Jeffrey Stylos February 8 th, 2005 Splay Trees Adapted from slides by Peter Lee October 4, 2001.
Binary Search Trees1 Chapter 3, Sections 1 and 2: Binary Search Trees AVL Trees   
AVL TREES By Asami Enomoto CS 146 AVL Tree is… named after Adelson-Velskii and Landis the first dynamically balanced trees to be propose Binary search.
CSC 2300 Data Structures & Algorithms March 13, 2007 Chapter 6. Priority Queues.
Red-Black Trees an 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.
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.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables II.
1 Red-Black Trees. 2 A Red-Black Tree with NULLs shown Black-Height of the tree = 4.
Lecture 23 Red Black Tree Chapter 10 of textbook
AVL Trees CSE, POSTECH.
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
AA Trees.
G64ADS Advanced Data Structures
Splay Trees.
SPLAY TREE Features Binary Search Tree Self adjusting balanced tree
AVL Tree.
Red Black Trees.
Lecture 25 Splay Tree Chapter 10 of textbook
TCSS 342, Winter 2006 Lecture Notes
Red-Black Trees.
Algorithms and Data Structures Lecture VIII
CMSC 341 Splay Trees.
AVL-Trees (Part 1).
Lecture 10 Oct 1, 2012 Complete BST deletion Height-balanced BST
Splay Trees Binary search trees.
Presentation transcript:

IT 60101: Lecture #121 Foundation of Computing Systems Lecture 12 Trees: Part VII

IT 60101: Lecture #122 Splay Tree A binary search tree is one of the most important non- linear data structures. a variety of methods are available to keep the tree balanced and hence to guarantee that operations such as searching, insertion and deletion can be done in O(log 2 n) time in the worst case. Height-balancing by AVL-rotations (AVL trees) Node colouring (red-black trees) No doubt that these trees are efficient so far searching, insertion and deletion of a node is concerned. But there are some situations, when the ways of balancing may not guarantee the optimal performance.

IT 60101: Lecture #123 Splay Tree For example, consider the binary search trees T1 and T2 Both the trees T 1 and T 2 contain the same set of key elements say, k 1, k 2, k 3, k4, k 5 in their five nodes such that k 1 < k 2 < k 3 < k 4 < k 5

IT 60101: Lecture #124 Splay Tree Key Number of Number of Number of accesses comparisons comparisons in tree T 1 in tree T 2 k 1 11×2 1×3 k 2 11×1 1×2 k ×3 10×1 k 4 22×2 2×3 k 5 33×3 3×2 Total no. of comparisons 46 27

IT 60101: Lecture #125 Splay Tree Definition A splay tree is a binary search tree and it adjusts its balance dynamically providing lower access time of higher occurrence nodes.

IT 60101: Lecture #126 Splay Tree Operations Searching Insertion Deletion Splaying

IT 60101: Lecture #127 Splaying Operation The basic idea of the splaying operation in a tree is that after a node is accessed, it is pushed to the root. –Not a simple swap operation (this may violates binary search tree property) –Way out Restructuring is by a series of AVL rotations

IT 60101: Lecture #128 Splaying Operation: Bottom Up AVL Rotations

IT 60101: Lecture #129 Splaying Operation: Bottom Up AVL Rotations

IT 60101: Lecture #1210 Splaying Operation: Bottom Up AVL Rotations

IT 60101: Lecture #1211 Splaying Operation: Bottom Up AVL Rotations

IT 60101: Lecture #1212 Splaying Operation: Bottom Up AVL Rotations

IT 60101: Lecture #1213 Side Effect of Bottom Up AVL Rotations Although repeated applications of single AVL-rotation work, it possibly deteriorates the situation for the other nodes on (original) their access paths. As evident in the splaying operation just discussed, we see that the repeated applications of single AVL rotations have the effect of pushing k 2 all the way to the root and subsequently making easy the future accessing of k 2. Unfortunately, it has pushed up another node k 1 almost as deep as k 2. Another side effect happens to a node like k 3 which was earlier closer to root now goes far away from the root A possible way to avoid the side effects is to follow splaying strategy of both double and single AVL- rotations, but selectively.

IT 60101: Lecture #1214 Splaying Operations

IT 60101: Lecture #1215 Splaying Operations

IT 60101: Lecture #1216 Splaying Operations

IT 60101: Lecture #1217 Splaying Operations

IT 60101: Lecture #1218 Splaying Operations

IT 60101: Lecture #1219 Case 1: Zig or Zag Case 1: zig or zag If the parent of the x is the root of the tree then if x is the left child –perform zig else (i.e. x is the right child) –perform zag

IT 60101: Lecture #1220 Case 2: Zig-Zig or Zag-Zag Case 2: zig-zig or zag-zag If x has both a parent (p) and a grandparent (g) If x is the left child of p and p is the left child of g –perform zig-zig else (i.e. x is the right child of p and p is the right child of g) –perform zag-zag

IT 60101: Lecture #1221 Case 3: Zig-Zag or Zag-Zig Case 3: zig-zag or zag-zig If x has both a parent (p) and a grandparent (g) If x is the right child of p and p is the left child of g then –perform zig-zag else (i.e. x is the left child of p and p is the right child of g) –perform zag-zig

IT 60101: Lecture #1222 Illustration of Splaying Operation

IT 60101: Lecture #1223 Illustration of Splaying Operation

IT 60101: Lecture #1224 Illustration of Splaying Operation

IT 60101: Lecture #1225 Illustration of Splaying Operation

IT 60101: Lecture #1226 Illustration of Splaying Operation

IT 60101: Lecture #1227 For detail implementation of splaying operation on binary search trees see the book Classic Data Structures Chapter 7 PHI, 2nd Edn., 17th Reprint