CSE 326: Data Structures Lecture #12 Splay It Again, Sam Steve Wolfman Winter Quarter 2000.

Slides:



Advertisements
Similar presentations
§6 Leftist Heaps CHAPTER 5 Graph Algorithms  Heap: Structure Property + Order Property Target : Speed up merging in O(N). Leftist Heap: Order Property.
Advertisements

COL 106 Shweta Agrawal and Amit Kumar
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
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.
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: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
CSE 326: Data Structures Lecture #7 Branching Out Steve Wolfman Winter Quarter 2000.
CSE 326: Data Structures Splay Trees Ben Lerner Summer 2007.
CSE 326 Binary Search Trees David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
1 COSC 2P03 Lecture #5 – Trees Part III, Heaps. 2 Today Take up the quiz Assignment Questions Red-Black Trees Binary Heaps Heap sort D-Heaps, Leftist.
CSE 326: Data Structures Lecture #10 Balancing Act and What AVL Stands For Steve Wolfman Winter Quarter 2000.
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
CSE 326: Data Structures Lecture #13 Extendible Hashing and Splay Trees Alon Halevy Spring Quarter 2001.
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.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
CSE 326: Data Structures Lecture #17 Priority Queues Alon Halevy Spring Quarter 2001.
CSE373: Data Structures & Algorithms Lecture 5: Dictionaries; Binary Search Trees Aaron Bauer Winter 2014.
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
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Balanced Binary Search Tree 황승원 Fall 2010 CSE, POSTECH.
Starting at Binary Trees
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 
CMSC420: Splay Trees Kinga Dobolyi Based off notes by Dave Mount.
Lec 15 Oct 18 Binary Search Trees (Chapter 5 of text)
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
CS221: Algorithms and Data Structures Lecture #3 Mind Your Priority Queues Steve Wolfman 2014W1 1.
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.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Review for Exam 2 Topics covered (since exam 1): –Splay Tree –K-D Trees –RB Tree –Priority Queue and Binary Heap –B-Tree For each of these data structures.
CSE 326: Data Structures Lecture #11 AVL and Splay Trees Steve Wolfman Winter Quarter 2000.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
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.
1 CSE 326: Data Structures Trees. 2 Today: Splay Trees Fast both in worst-case amortized analysis and in practice Are used in the kernel of NT for keep.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees Linda Shapiro Winter 2015.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Bottom-Up Red-Black Trees Top-down red-black trees require O(log n) rotations per insert/delete. Color flips cheaper than rotations. Priority search trees.
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.
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Lauren Milne Summer 2015.
CSE 326: Data Structures Lecture #6 Putting Our Heaps Together Steve Wolfman Winter Quarter 2000.
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.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Linda Shapiro Winter 2015.
CSE 326: Data Structures Trees
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
Red Black Trees Colored Nodes Definition Binary search tree.
CS 201 Data Structures and Algorithms
Splay Trees.
Hashing Exercises.
Cse 373 April 26th – Exam Review.
i206: Lecture 13: Recursion, continued Trees
Lecture 25 Splay Tree Chapter 10 of textbook
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
CSE 326: Data Structures: Midterm Review
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
BST Insert To insert an element, we essentially do a find( ). When we reach a NULL pointer, we create a new node there. void BST::insert(const Comp &
Lecture 10 Oct 1, 2012 Complete BST deletion Height-balanced BST
CSE 326: Data Structures Splay Trees
CS 6310 Advanced Data Structure Wei-Shian Wang
326 Lecture 9 Henry Kautz Winter Quarter 2002
Red Black Trees Colored Nodes Definition Binary search tree.
Presentation transcript:

CSE 326: Data Structures Lecture #12 Splay It Again, Sam Steve Wolfman Winter Quarter 2000

Today’s Outline Finish off splay trees Summary of the class so far Discuss Projects III & IV Free time

Why Splaying Helps If a node n on the access path is at depth d before the splay, it’s at about depth d/2 after the splay –Exceptions are the root, the child of the root, and the node splayed Overall, nodes which are below nodes on the access path tend to move closer to the root Splaying gets amortized O(log n) performance. (Maybe not now, but soon, and for the rest of the operations.)

Splay Operations: Find Find the node in normal BST manner Splay the node to the root

Splay Operations: Insert Ideas? Can we just do BST insert?

Digression: Splitting Split(T, x) creates two BSTs L and R: –all elements of T are in either L or R ( T = L  R ) –all elements in L are  x –all elements in R are  x –L and R share no elements ( L  R =  )

Splitting in Splay Trees How can we split? (SPOILERS below ^L) –We have the splay operation. –We can find x or the parent of where x should be. –We can splay it to the root. –Now, what’s true about the left subtree of the root? –And the right?

Split split(x) TLR splay OR LRLR  x  x > x< x void split(Node * root, Node *& left, Node *& right, Object x) { Node * target = root->find(x); splay(target); if (target < x) { left = target->left; target->left = NULL; right = target; }... }

Back to Insert split(x) LR x LR > x< x void insert(Node *& root, Object x) { Node * left, * right; split(root, left, right, x); root = new Node(x, left, right); }

Splay Operations: Delete find(x) LR x LR > x< x delete x Now what?

Join Join(L, R): given two trees such that L < R, merge them Splay on the maximum element in L then attach R LR R splay L

Delete Completed T find(x) LR x LR > x< x delete x T - x Join(L,R)

Insert Example Insert(5) split(5)

Delete Example Delete(4) find(4) Find max

Splay Tree Summary All operations are in amortized O(log n) time Splaying can be done top-down; better because: –only one pass –no recursion or parent pointers necessary There are alternatives to split/insert and join/delete Splay trees are very effective search trees –relatively simple –no extra fields required –excellent locality properties: frequently accessed keys are cheap to find

Lists and Multi-Lists Lists –Array-based –Linked list-based –Sparse Multi-lists –List of lists: complete –List of lists: sparse –Cross-list

Stacks and Queues Stacks –array-based –linked list-based Queues –array-based –linked list-based

Priority Queues Naïve Binary heap d-Heap Leftist Heap Skew Heap

Dictionaries and Search Sets Naïve Binary Search Tree B-Tree AVL Tree Splay Tree

Asymptotic Analysis and Proof by Induction Asymptotic analysis –symbols: O, o, , , and  –types: worst, best, average, common, amortized –objectives: time, space –quality: tight vs. loose –the fix sheet –analyzing code –interpretation of analysis Proof techniques –by counterexample –by contradiction –by induction base case induction hypothesis induction step

Project III Word frequency counting –Splay trees –AVL trees Writeup out on Friday Get your groups (of 2-3) together quickly Due a week from Monday Should be fairly easy

Project IV Writeup out two weeks from now. Groups of 4-5 Four options –Maze generation: k-d trees and disjoint-sets –Maze visualization: k-d trees –Compression: adaptive heaps, dictionaries –MUD/MOO: graphs, hash tables, etc. More than meets the eye –Maze generation + visualization + MUD = automatically generated, walk-thru, 3-D MUD

To Do Get set for the midterm Find a group for Project III Relax over the weekend (at least as far as this class is concerned)

Coming Up Midterm (February 4 th ) Hash Tables k-d Trees Disjoint-set union-find with up-trees and path compression (does that not sound rocking?)