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.

Презентация:



Advertisements
Похожие презентации
AVL-Trees COMP171 Fall AVL Trees / Slide 2 Balanced binary tree * The disadvantage of a binary search tree is that its height can be as large as.
Advertisements

AVL Trees CSE 373 Data Structures Lecture 8. 12/26/03AVL Trees - Lecture 82 Readings Reading Section 4.4,
HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Customer-to-Provider Connectivity with BGP Connecting a Multihomed Customer to Multiple Service.
What to expect? How to prepare? What to do? How to win and find a good job? BUSINESS ENGLISH COURSE NOVA KAKHOVKA GUMNASUIM 2012.
A S ANY LANGUAGE IN THE WORLD A SIGN LANGUAGE HAS MANY ADVANTAGES. F IRST OF ALL, IT IS QUITE RICH TO SHOW THE MOST IMPORTANT MEANINGS THAT EXIST IN ALL.
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Ideal Family Were prepared by Iryna Molokova and Ilona Synytsia.
Sequences Sequences are patterns. Each pattern or number in a sequence is called a term. The number at the start is called the first term. The term-to-term.
1/27 Chapter 9: Template Functions And Template Classes.
Multiples Michael Marchenko. Definition In mathematics, a multiple is the product of any quantity and an integer. in other words, for the quantities a.
MOUSE MANIPULATION 23. The 3 button mouse is your tool for manipulation of the parts and assemblies that you have created. With it you can ZOOM, ROTATE.
Lesson 2. How to say hello & goodbye ?. When we first meet someone whether it is a person we know or someone we are meeting for the first time, we will.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Module Summary The Cisco Discovery Protocol is an information-gathering tool used by network.
Indirect Questions How do you make indirect questions? When do you use this grammar?
How does media affect our lives? Elizaveta Michsherina 9 B.
© 2006 Cisco Systems, Inc. All rights reserved. MPLS v MPLS VPN Implementation Configuring VRF Tables.
ADVANCED DRESS-UP FEATURES 39. Once OK has been selected, your part will appear with the filleted area highlighted by orange lines at the boundaries.
The problem of String Matching Given a string S, the problem of string matching deals with finding whether a pattern p occurs in S and if p does occur.
Транксрипт:

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 of tree rotations is knowing as splaying. It is binary search tree Two types of splay tree i) single step (single rotation) ZIG ZAG

ii) Double step (Splaying) ZIG ZIG ZAG Splay is performed during Search, insert, delete Moves a node at the root Improved behavior during repeated access of data

Splay Operation To splay node x, traverse up the tree from node x to root, rotating along the way until x is the root. For each rotation: If x is root, do nothing. If x has no grandparent, rotate x about its parent. If x has a grandparent, if x and its parent are both left children or both right children, rotate the parent about the grandparent, then rotate x about its parent. if x and its parent are opposite type children (one left and the other right), rotate x about its parent, then rotate x about its new parent (former grandparent).

Node has no grandparent –Zig: If parent(k1) is the root, rotate parent(k1) to get k1 to the root (This is a terminal case).

The single rotation does not work here Because it use only left rotations z5 z4 z1 z3 z2 A DC E F B

Splaying The cost of any splay operation is O(log n). This implies that splay trees can actually adapt to perform searches on frequently requested items much faster than O(log n) in some cases.

Eg., z5 z1 z3 z2 A DC F B z4 E

Node and Parent are Same Side Zig-Zig If parent(x) is not the root and x and parent(x) are both left or both right children, rotate grandparent(x) followed by rotate parent(x).

Node and Parent are Different Sides Zig-Zag If parent(x) is not the root and x is a left child and parent(x) a right child or vice-versa, rotate parent(x) and then rotate the new parent(x).

Operations on Splay Trees Remove splay element to be removed if the element to be deleted is not in the tree, the node last visited on the search path is splayed disconnect left and right sub trees from root do one or both of: splay max item in TL (then TL has no right child) splay min item in TR (then TR has no left child) connect other sub tree to empty child of root

Insertion in order into a Splay Tree

An extreme example of splaying

When to splay? Whenever we search, insert, delete Which nodes are splayed after each operation? Search – If node found – use that node – If node not found use last node in the search path Insert – Use the new node Remove – Use the parent of the node that was actually deleted – I.e. the deepest node

Advantages: –Can be much more efficient if usage pattern is skewed. Good heuristics can have amortized running time similar to the running time of the best structure –Require less space as no balance information is required Disadvantages: –More local adjustments during look-up operations (balanced trees only make adjustments during updates) –Individual operations can be expensive – drawback for real- time applications