more on randomized data structures. motivation for randomized data structures we’ve seen many data...
TRANSCRIPT
![Page 1: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/1.jpg)
More on Randomized Data
Structures
![Page 2: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/2.jpg)
Motivation for
Randomized Data StructuresWe’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
![Page 3: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/3.jpg)
Average vs. Expected TimeAverage (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!
![Page 4: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/4.jpg)
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.
![Page 5: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/5.jpg)
Randomization in Action Quicksort Randomized data structures
TreapsRandomized skip lists
![Page 6: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/6.jpg)
Treap Dictionary Data Structure
Treap is a BST binary tree property search tree
property
Treap is also a heap heap-order
property random priorities
1512
1030
915
78
418
67
29
prioritykey
![Page 7: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/7.jpg)
Treap Insert Choose a random priority Insert as in normal BST Rotate up until heap order is restored
67
insert(15)
78
29
1412
67
78
29
1412
915
67
78
29
915
1412
![Page 8: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/8.jpg)
Tree + Heap… Why Bother? Insert data in sorted order into a treap …
What shape tree comes out?
67
insert(7)
67
insert(8)
78
67
insert(9)
78
29
67
insert(12)
78
29
1512
![Page 9: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/9.jpg)
Treap Delete Find the key Increase its value to Rotate it to the fringe Snip it off
delete(9)
67
78
29
915
1512
78
67
9
915
1512
![Page 10: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/10.jpg)
Treap Delete (2)
78
67
9
915
1512
78
67
9
915
1512
78
67
9
915
1512
![Page 11: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/11.jpg)
Treap Delete (3)
78
67
9
915
1512
9
78
67
915
1512
78
67
915
1512
![Page 12: More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random](https://reader036.vdocuments.us/reader036/viewer/2022071806/56649d015503460f949d473f/html5/thumbnails/12.jpg)
Treap Summary Implements Dictionary ADT
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