More on Randomized Data Structures

Slides:



Advertisements
Similar presentations
CMSC420: Skip Lists Kinga Dobolyi Based off notes by Dave Mount.
Advertisements

More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random.
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
CSE 326 Randomized Data Structures David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Tirgul 7 Heaps & Priority Queues Reminder Examples Hash Tables Reminder Examples.
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
AVL Trees Amanuel Lemma CS252 Algoithms Dec. 14, 2000.
CSC 213 – Large Scale Programming Lecture 18: Zen & the Art of O (log n ) Search.
CSE373: Data Structures & Algorithms Lecture 8: AVL Trees and Priority Queues Linda Shapiro Spring 2016.
Splay trees Go&Ta How do you organize your world?
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
11/20/2016IT 2791 Is this an AVL tree?
School of Computing Clemson University Fall, 2012
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
AA Trees.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Topics covered (since exam 1):
Balancing Binary Search Trees
CPSC 221: Algorithms and Data Structures Lecture #6 Balancing Act
CSE 326: Data Structures Lecture #23 Data Structures
CPSC 221: Algorithms and Data Structures Lecture #6 Balancing Act
Balanced Trees AVL : Adelson-Velskii and Landis(1962)
Data Structures and Analysis (COMP 410)
Splay Trees.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Heap Sort Example Qamar Abbas.
Review for Final Exam Non-cumulative, covers material since exam 2
Review for Final Exam Non-cumulative, covers material since exam 2
Red Black Trees.
AVL Trees "The voyage of discovery is not in seeking new landscapes but in having new eyes. " - Marcel Proust.
Lecture 25 Splay Tree Chapter 10 of textbook
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Red-Black Trees Motivations
Bit Vector Linked List (Sorted and Unsorted) Hash Table Search Trees
CMSC 341: Data Structures Priority Queues – Binary Heaps
Dr. David Matuszek Heapsort Dr. David Matuszek
CSCI 104 Splay Trees Mark Redekopp.
Topics covered (since exam 1):
Tree Rotations & Splay Trees
Topic 10 Trees.
David Kaplan Dept of Computer Science & Engineering Autumn 2001
CPSC 221: Algorithms and Data Structures Lecture #6 Balancing Act
Topic 10 Trees.
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
CSE 373: Data Structures and Algorithms
SPLAY TREES.
Data Structures & Algorithms
Tree Rotations and AVL Trees
CMSC 341 Splay Trees.
AVL Trees CSE 373 Data Structures.
Heapsort.
CMSC 341 Splay Trees.
CSE 326: Data Structures Lecture #18 Fistful of Data Structures
AVL-Trees (Part 1).
Binary SearchTrees [CLRS] – Chap 12.
Heapsort.
Richard Anderson Spring 2016
CSE 326: Data Structures Splay Trees
CMSC 341 Splay Trees.
Topics covered (since exam 1):
Chapter 12 Heap ADT © 2011 Pearson Addison-Wesley. All rights reserved.
CSE 326: Data Structures Lecture #24 Odds ‘n Ends
Heapsort.
CSE 373 Data Structures Lecture 8
CMSC 341 Splay Trees.
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
326 Lecture 9 Henry Kautz Winter Quarter 2002
CO 303 Algorithm Analysis and Design
Splay Trees Binary search trees.
Topic 10 Trees.
Presentation transcript:

More on Randomized Data Structures

Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random inputs, but bad behavior on particular inputs e.g. Binary Search Trees  Instead of randomizing the input (since we cannot!), consider randomizing the data structure No bad inputs, just unlucky random numbers Expected case good behavior on any input

Average vs. Expected Time Average (1/N)   xi Expectation  Pr(xi)  xi Deterministic with good average time If your application happens to always (or often) use the “bad” case, you are in big trouble! Randomized with good expected time Once in a while you will have an expensive operation, but no inputs can make this happen all the time Like an insurance policy for your algorithm!

Randomized Data Structures Define a property (or subroutine) in an algorithm Sample or randomly modify the property Use altered property as if it were the true property Can transform average case runtimes into expected runtimes (remove input dependency). Sometimes allows substantial speedup in exchange for probabilistic unsoundness.

Randomization in Action Quicksort Randomized data structures Treaps Randomized skip lists

Treap Dictionary Data Structure Treap is a BST binary tree property search tree property Treap is also a heap heap-order property random priorities priority key 2 9 6 7 4 18 7 8 9 15 10 30 15 12

Treap Insert Choose a random priority Insert as in normal BST Rotate up until heap order is restored 2 9 insert(15) 2 9 2 9 6 7 14 12 6 7 14 12 6 7 9 15 7 8 7 8 9 15 7 8 14 12

Tree + Heap… Why Bother? Insert data in sorted order into a treap … 6 What shape tree comes out? 6 7 insert(7) 6 7 insert(8) 8 6 7 insert(9) 8 2 9 6 7 insert(12) 8 2 9 15 12 Notice that it doesn’t matter what order the input comes in. The shape of the tree is fully specified by what the keys are and what their random priorities are! So, there’s no bad inputs, only bad random numbers! That’s the difference between average time and expected time. Which one is better?

Treap Delete delete(9) 2 9 6 7 Find the key Increase its value to  Rotate it to the fringe Snip it off 6 7 9 15  9 7 8 7 8 15 12 9 15 15 12 6 7 6 7 Basically, rotate the node down to the fringe and then cut it off. This is pretty simple as long as you have rotate, as well. However, you do need to find the smaller child as you go! 6 7 7 8 9 15 7 8 9 15 7 8 9 15  9 15 12 15 12  9 15 12

Treap Delete (2) 6 7 7 8 6  9 15 12 7 8 6  9 15 12 7 8 9 15  9 15 12

Treap Delete (3) 7 8 6 9 15 12 7 8 6  9 15 12 7 8 6 9 15 12  9

Treap Summary Implements Dictionary ADT Memory use insert in expected O(log n) time delete in expected O(log n) time find in expected O(log n) time but worst case O(n) Memory use O(1) per node about the cost of AVL trees Very simple to implement little overhead – less than AVL trees The big advantage of this is that it’s simple compared to AVL or even splay. There’s no zig-zig vs. zig-zag vs. zig. Unfortunately, it doesn’t give worst case or even amortized O(log n) performance. It gives expected O(log n) performance.