past balancing schemes require maintenance of balance info at all times, are aggresive use work of searches to pay for work of rebalancing

Similar documents
Splay trees (Sleator, Tarjan 1983)

Outline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!

Splay Trees. CMSC 420: Lecture 8

Lecture 2 14 February, 2007

Graphs and Trees Binary Search Trees AVL-Trees (a,b)-trees Splay-Trees. Search Trees. Tobias Lieber. April 14, 2008

Outline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

Search Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :52 AM

Search Trees. EECS 2011 Prof. J. Elder Last Updated: 24 March 2015

Amortized Complexity Main Idea

Lecture 5: Splay Trees

Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.

8: Splay Trees. Move-to-Front Heuristic. Splaying. Splay(12) CSE326 Spring April 16, Search for Pebbles: Move found item to front of list

Priority queues implemented via heaps

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Illinois Institute of Technology Department of Computer Science. Splay Trees. CS 535 Design and Analysis of Algorithms Fall Semester, 2018

Chapter 6. Self-Adjusting Data Structures

Inge Li Gørtz. Thank you to Kevin Wayne for inspiration to slides

N/4 + N/2 + N = 2N 2.

Biased Quantiles. Flip Korn Graham Cormode S. Muthukrishnan

Advanced Implementations of Tables: Balanced Search Trees and Hashing

Data Structures 1 NTIN066

A Unified Access Bound on Comparison-Based Dynamic Dictionaries 1

INF2220: algorithms and data structures Series 1

Assignment 5: Solutions

Notes on Logarithmic Lower Bounds in the Cell Probe Model

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Copyright 2013 Kevin Wayne

Disjoint-Set Forests

Ordered Dictionary & Binary Search Tree

AVL Trees. Properties Insertion. October 17, 2017 Cinda Heeren / Geoffrey Tien 1

Problem. Maintain the above set so as to support certain

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

CS 240 Data Structures and Data Management. Module 4: Dictionaries

Data Structures 1 NTIN066

Mon Tue Wed Thurs Fri

Tutorial 4. Dynamic Set: Amortized Analysis

AMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM

Optimal Color Range Reporting in One Dimension

Allocate-On-Use Space Complexity of Shared-Memory Algorithms

Each internal node v with d(v) children stores d 1 keys. k i 1 < key in i-th sub-tree k i, where we use k 0 = and k d =.

ENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October

Data Structures and Algorithms " Search Trees!!

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

Dictionary: an abstract data type

IE418 Integer Programming

Lecture 1 : Data Compression and Entropy

CS 5321: Advanced Algorithms Amortized Analysis of Data Structures. Motivations. Motivation cont d

Weight-balanced Binary Search Trees

Dictionary: an abstract data type

Skip-Splay: Toward Achieving the Unified Bound in the BST Model

The Complexity of Constructing Evolutionary Trees Using Experiments

Fundamental Algorithms

Weight-balanced Binary Search Trees

Lower Bounds for Dynamic Connectivity (2004; Pǎtraşcu, Demaine)

AVL Trees. Manolis Koubarakis. Data Structures and Programming Techniques

Data Structures and Algorithm. Xiaoqing Zheng

Amortized Analysis (chap. 17)

Binary Search Trees. Dictionary Operations: Additional operations: find(key) insert(key, value) erase(key)

Math Models of OR: Branch-and-Bound

Functional Data Structures

L feb abhi shelat

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Union-Find Structures

CS 466/666 Course Notes

Algorithms Theory. 08 Fibonacci Heaps

CS 395T Computational Learning Theory. Scribe: Mike Halcrow. x 4. x 2. x 6

Design and Analysis of Algorithms

arxiv: v2 [cs.ds] 30 Jun 2015

Verified Analysis of Functional Data Structures

Optimal Tree-decomposition Balancing and Reachability on Low Treewidth Graphs

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

Another way of saying this is that amortized analysis guarantees the average case performance of each operation in the worst case.

data structures and algorithms lecture 2

Computing Connected Components Given a graph G = (V; E) compute the connected components of G. Connected-Components(G) 1 for each vertex v 2 V [G] 2 d

Speculative Parallelism in Cilk++

! Insert. ! Remove largest. ! Copy. ! Create. ! Destroy. ! Test if empty. ! Fraud detection: isolate $$ transactions.

2-INF-237 Vybrané partie z dátových štruktúr 2-INF-237 Selected Topics in Data Structures

CS 310 Advanced Data Structures and Algorithms

arxiv: v1 [cs.ds] 22 Feb 2011

Cache-Oblivious Algorithms

Cache-Oblivious Algorithms

Amortized Complexity Verified

Part IA Algorithms Notes

Lecture VI AMORTIZATION

CS Data Structures and Algorithm Analysis

Lecture 2 September 4, 2014

Amortized Analysis. DistributeMoney(n, k) 1 Each of n people gets $1. 2 for i = 1to k 3 do Give a dollar to a random person

1. Introduction Bottom-Up-Heapsort is a variant of the classical Heapsort algorithm due to Williams ([Wi64]) and Floyd ([F64]) and was rst presented i

8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

Santa Claus Schedules Jobs on Unrelated Machines

Dynamic Ordered Sets with Exponential Search Trees

Lecture Notes for Chapter 17: Amortized Analysis

Dynamic Structures for Top-k Queries on Uncertain Data

Algorithms and Data Structures

Dynamic Length-Restricted Coding. Travis Gagie

CSE 202: Design and Analysis of Algorithms Lecture 3

CS 151. Red Black Trees & Structural Induction. Thursday, November 1, 12

Algorithm Design and Analysis

Average Case Analysis of QuickSort and Insertion Tree Height using Incompressibility

Transcription:

1 Splay Trees Sleator and Tarjan, Self Adjusting Binary Search Trees JACM 32(3) 1985 The claim planning ahead. But matches previous idea of being lazy, letting potential build up, using it to pay for expensive operation. Background. binary search trees bad worst case behavior, so balance Lots of variants. All mark. most rotate. idea of self adjusting Show splay tree is as good as any of them! Static finger theorem. Dynamic finger conjecture. Philosophy describe a rotation (draw). past balancing schemes require maintenance of balance info at all times, are aggresive idea: be lazy, only rebalance when must use work of searches to pay for work of rebalancing Intuition: When my search descends to smaller child, happy because can only happen O(log n) times before done So, fat children are bad Cause fat children to have high potential Make fat children go away potential pays for cost Simple idea: single-rotate to root (cheap next time!). Doesn t work. more sophisticated rotations work. Idea: halve depth of all nodes on search path. Note: don t actually destroy fat children just promote them unfortunate: analysis is black magic. no idea how discovered. 1

Draw pictures of rotations. Search algorithm: Walk down tree to find item Splay item to root 1.1 Access Theorem Search only. Later show insert, delete. Analysis: different choices of weights. Note analysis only, don t affect implementation. Potential function: weight w x on each node x size s(x) is total weight of subtree nodes number of nodes rank r(x) = lg s(x) (base 2 log) best depth of subtree at x potential Φ = r(x) Main lemma: Amortized time to splay node x given root t is at most 3(r(t) r(x)) + 1 = O(log(s(t)/s(x))). Intuition: r(t) t(x) is depth of x. So then amortized search time is small if x is high in tree (fat subtree) (just like normal BST) (but we will see power of changing notion of fat subtree ) Analyze change for one splay step new sizes/ranks s,r. Show potential change is 3(r (x) r(x) except +1 for last single rot. telescope sum for overall result (since final r (x) = r(t). Analyze one step: Do zig-zig (hardest). zig-zag in paper. old y parent x and z parent y. Only those nodes change ranks Real cost 2. Potential r (x)+ r (y)+ r (z) r(x) r(y) r(z) 2

Simplify: 2+ r (x)+ r (y)+ r (z) r(x) r(y) r(z) 2+ r (y)+ r (z) r(x) r(y)since r (x) = r(z) So just need to show 2 + r (z) r(x) 2(r (x) r(x)) Some intuitive analysis: Math: Usage: r (z) r (x), i.e. r (z) r(x) r (x) r(x) So done if 2 r (x) r(x) Trouble if r (x) r(x) < 2 i.e., r(x) almost as big as r (x) Means most of tree weight is under r(x), ie x is fat child 2+ r (x)+ r (z) r(x) r(x) =2 + r (x)+ r (z) 2r(x) Consider rotation step: initially z above x so fat, then z below x so not fat i.e. r (z) r(x) In which case r (z) r(x) term cancels additive 2 Must show 2 + r (z) r(x) 2(r (x) r(x)) i.e., that r (z)+ r(x) 2r (x) 2 Now note r (z) r (x)+ r(x) r (x) =lg s (z)/s (x)+ lg s(x)/s (x) And note s (z)+ s(x) s (x) since are seperate subtree So, eqn is loga + log(1 a) for some 0 <a < 1 =log a(1 a) which is maximized by maximizing a(1 a) at a = 1/2 which yields 2 One more tricky problem with potential function. Have to account for initial potential (remember: real cost equals amortized cost minus change in potential. So must add overall decrease on potential to amortized cost in order to bound real cost. 3

m accesses on n nodes item i weight w i, w i = W. initial potential at most n log W final potential at least log w i max change at most log W/w i i.e. add once to amortized cost of splaying item i amount O(log W/w i ). (note potential change equals cost of splaying each item once) 1.2 Applications Balance theorem: total access for m ops is O((m + n)log n) (as good as any balanced tree) weight 1/n to each node. potential drop n log n amortized cost of search: 1 + 3 log n Static Optimality: (as good as any fixed tree) item i accessed p i m times lower bound for static access: m p i log 1/p i (entropy) item weight p i W =1 access time for item i at most 3(1 log p i )+1 = O(1 + log 1/p i ) potential drop O( log 1/p i ). Static finger theorem: w i =1/(1 + i f ) 2 w i 2 1/k 2 = O(1) access time O(log i f ) potential drop O(n log n) Working set theorem: At access j to item i j,let t j be number of distinct items since that item was last accessed. Then time O(n log n + log t j ). 4

Unified theorem: cost is sum of logs of best possible choices from previous theorem. Balance theorem: total access O((m + n)log n) (as good as any balanced tree) weight 1 to each node. potential drop n log n amortized cost of search: 1 + 3 log n Static Optimality: (as good as any fixed tree) item i accessed p i m times lower bound for static access: m p i log 1/p i (entropy) item weight p i W =1 access time for item i at most 3(1 log p i )+1 = O(1 + log 1/p i ) total O( (p i m)log 1/p i ) potential drop O( log 1/p i ). Static finger theorem: w i =1/(1 + i f ) 2 w i 2 1/k 2 = O(1) access time O(log i f ) potential drop O(n log n) 1.3 Updates Update operations: insert, delete, search (might not be there) define split, join set w i = 1 so splay is O(log n). to split, splay and separate splay O(log n), potential drops to join, access largest item and merge splay O(log n), root potential only up by O(log n) splits and joints have amortized cost O(log n) insert/delete via split/join important to splay on unsuccessful search 5

Remarks Top down splaying. can choose to splay only when path is long (real cost to large so need to amortize). Drawback: must know weights. can choose to stop splaying after a while. good for random access frequenies. Open: dynamic optimality. Open: dynamic finger tarjan: sequential splay is O(n) 6