More on Randomized Data Structures. Motivation for Randomized Data Structures We’ve seen many data structures with good average case performance on random.

Slides:



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

CS 225 Lab #11 – Skip Lists.
AVL Trees CS II – Fall /8/2010. Announcements HW#2 is posted – Uses AVL Trees, so you have to implement an AVL Tree class. Most of the code is provided.
Outline Scapegoat Trees ( O(log n) amortized time)
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.
Data Structures Data Structures Topic #13. Today’s Agenda Sorting Algorithms: Recursive –mergesort –quicksort As we learn about each sorting algorithm,
Section 8.8 Heapsort.  Merge sort time is O(n log n) but still requires, temporarily, n extra storage locations  Heapsort does not require any additional.
InOrder Traversal Algorithm // InOrder traversal algorithm inOrder(TreeNode n) { if (n != null) { inOrder(n.getLeft()); visit(n) inOrder(n.getRight());
Binary Search Trees Briana B. Morrison Adapted from Alan Eugenio.
AVL-Trees (Part 1) COMP171. AVL Trees / Slide 2 * Data, a set of elements * Data structure, a structured set of elements, linear, tree, graph, … * Linear:
Tirgul 4 Sorting: – Quicksort – Average vs. Randomized – Bucket Sort Heaps – Overview – Heapify – Build-Heap.
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
Skip Lists Michael Oudshoorn. CS351 Software Engineering (AY05)2 Skip Lists Binary Search Trees: O(log n) –If, and only if, the tree is “balanced” Insertion.
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
Binary Search Trees vs. Binary Heaps. Binary Search Tree Condition Given a node i –i.value is the stored object –i.left and i.right point to other nodes.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
TTIT33 Algorithms and Optimization – DALG Lecture 6 Jan Maluszynski - HT TTIT33- Algorithms and optimization Algorithms Lecture 5 Balanced Search.
Priority Queues  Queues: first-in first-out in printer schedule  Disadvantage: short job, important job need to wait  Priority queue is a data structure.
1 TCSS 342, Winter 2005 Lecture Notes Priority Queues and Heaps Weiss Ch. 21, pp
CSE 326 Randomized Data Structures David Kaplan Dept of Computer Science & Engineering Autumn 2001.
© 2006 Pearson Addison-Wesley. All rights reserved12 A-1 Chapter 12 Heaps.
Tirgul 7 Heaps & Priority Queues Reminder Examples Hash Tables Reminder Examples.
Tirgul 4 Order Statistics Heaps minimum/maximum Selection Overview
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
Skip Lists Mrutyunjay. Introduction ▪ Linked Lists Benefits & Drawbacks: – Benefits: – Easy Insert and Deletes, implementations. – Drawbacks: – Hard to.
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.
Priority Queues and Binary Heaps Chapter Trees Some animals are more equal than others A queue is a FIFO data structure the first element.
Balanced Search Trees Fundamental Data Structures and Algorithms Margaret Reid-Miller 3 February 2005.
Binary SearchTrees [CLRS] – Chap 12. What is a binary tree ? A binary tree is a linked data structure in which each node is an object that contains following.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
CSE221/ICT221 Analysis and Design of Algorithms CSE221/ICT221 Analysis and Design of Algorithms Analysis of Algorithm using Tree Data Structure Asst.Prof.
S. Raskhodnikova and A. Smith. Based on slides by C. Leiserson and E. Demaine. 1 Adam Smith L ECTURES Binary Search Trees Algorithms and Data Structures.
CS 253: Algorithms Chapter 13 Balanced Binary Search Trees (Balanced BST) AVL Trees.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
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.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
What is a heap? Always keep the thing we are most interested in close to the top (and fast to access). Like a binary search tree, but less structured.
CSC 213 – Large Scale Programming Lecture 18: Zen & the Art of O (log n ) Search.
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
Review for Final Exam Non-cumulative, covers material since exam 2 Data structures covered: –Treaps –Hashing –Disjoint sets –Graphs For each of these data.
1 CompSci 105 SS 2006 Principles of Computer Science Lecture 17: Heaps cont.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
Week 13 - Wednesday.  What did we talk about last time?  NP-completeness.
Heap Sort Uses a heap, which is a tree-based data type Steps involved: Turn the array into a heap. Delete the root from the heap and insert into the array,
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
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.
Balancing Binary Search Trees
CSE 326: Data Structures Lecture #23 Data Structures
Introduction Applications Balance Factor Rotations Deletion Example
Cse 373 April 12th – TreEs.
Red-Black Trees Motivations
Sorting.
Binary Trees: Motivation
CSE 326: Data Structures Lecture #18 Fistful of Data Structures
Binary Search Trees Chapter 7 Objectives
AVL-Trees (Part 1).
Richard Anderson Spring 2016
Chapter 12 Heap ADT © 2011 Pearson Addison-Wesley. All rights reserved.
CSE 326: Data Structures Lecture #24 Odds ‘n Ends
More on Randomized Data Structures
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)   x i Expectation  Pr(x i )  x i 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

Treap Insert  Choose a random priority  Insert as in normal BST  Rotate up until heap order is restored 6767 insert(15)

Tree + Heap… Why Bother?  Insert data in sorted order into a treap … What shape tree comes out? 6767 insert(7) 6767 insert(8) insert(9) insert(12)

Treap Delete  Find the key  Increase its value to   Rotate it to the fringe  Snip it off delete(9)  9

Treap Delete (2) 9 9 9

Treap Delete (3) 9 9

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