Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CSE 326: Data Structures Lecture #12 Splay It Again, Sam Steve Wolfman Winter Quarter 2000."— Presentation transcript:

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

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

3 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.)

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

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

6 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 =  )

7 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?

8 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; }... }

9 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); }

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

11 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

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

13 Insert Example 91 6 47 2 Insert(5) split(5) 9 6 7 1 4 2 1 4 2 9 6 7 1 4 2 9 6 7 5

14 Delete Example 91 6 47 2 Delete(4) find(4) 9 6 7 1 4 2 1 2 9 6 7 Find max 2 1 9 6 7 2 1 9 6 7

15 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

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

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

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

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

20 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

21 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

22 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

23 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)

24 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?)


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

Similar presentations


Ads by Google