§3 Worst-Case vs. Amortized

Slides:



Advertisements
Similar presentations
Fibonacci Heaps Especially desirable when the number of calls to Extract-Min & Delete is small (note that all other operations run in O(1) This arises.
Advertisements

Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
Advanced Data structure
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
On Demand String Sorting over Unbounded Alphabets Carmel Kent Moshe Lewenstein Dafna Sheinwald.
Nick Harvey & Kevin Zatloukal
Dijkstra/Prim 1 make-heap |V| insert |V| delete-min |E| decrease-key Priority Queues make-heap Operation insert find-min delete-min union decrease-key.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 11 Tuesday, 12/4/01 Advanced Data Structures Chapters.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
ANALYSIS OF SOFT HEAP Varun Mishra April 16,2009.
1 Binomial heaps, Fibonacci heaps, and applications.
The Power of Incorrectness A Brief Introduction to Soft Heaps.
+ 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,
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another.
CMSC 341 Binomial Queues and Fibonacci Heaps. Basic Heap Operations OpBinary Heap Leftist Heap Binomial Queue Fibonacci Heap insertO(lgN) deleteMinO(lgN)
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Fibonacci Heaps.
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
1 Fibonacci heaps: idea List of multiway trees which are all heap-ordered. Definition: A tree is called heap-ordered if the key of each node is greater.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
Fibonacci Heaps. Fibonacci Binary insert O(1) O(log(n)) find O(1) N/A union O(1) N/A minimum O(1) O(1) decrease key O(1) O(log(n)) delete O(log(n) O(log(n))
CSE332: Data Abstractions Lecture 7: AVL Trees
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
Red Black Trees Colored Nodes Definition Binary search tree.
CS38 Introduction to Algorithms
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Balancing Binary Search Trees
Binomial heaps, Fibonacci heaps, and applications
Chapter 17: Amortized Analysis I
Binomial Heaps On the surface it looks like Binomial Heaps are great if you have no remove mins. But, in this case you need only keep track of the current.
Heaps Binomial Heaps Lazy Binomial Heaps 1.
Binomial heaps, Fibonacci heaps, and applications
Insert in amortized cost O(1), Merge in O(lgn) DeleteMax in O(lgn)
Binomial Heaps Chapter 19.
Binomial Tree Adapted from: Kevin Wayne Bk-1 B0 Bk
Priority Queues MakeQueue create new empty queue
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
CSE 326: Data Structures: Midterm Review
Part-D1 Priority Queues
A simpler implementation and analysis of Chazelle’s
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
ערמות בינומיות ופיבונצ'י
CS 583 Analysis of Algorithms
Fundamental Structures of Computer Science
Priority Queues (Chapter 6.6):
Strict Fibonacci Heaps
CS 583 Analysis of Algorithms
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
Binary and Binomial Heaps
Binomial heaps, Fibonacci heaps, and applications
HEAPS.
Binomial heaps, Fibonacci heaps, and applications
Amortized Analysis and Heaps Intro
Fibonacci Heaps.
Richard Anderson Spring 2016
Binomial heaps, Fibonacci heaps, and applications
Priority Queues (Chapter 6):
Priority Queues Supports the following operations. Insert element x.
Pairing Heaps Actual Complexity
Priority Queues Binary Heaps
Red Black Trees Colored Nodes Definition Binary search tree.
More on Randomized Data Structures
Presentation transcript:

§3 Worst-Case vs. Amortized Motivating example: Repeated binary increment, #bit flips when counting to n? Inc & decrement ? 1 10 11 100 101 …… 111…111 One increment of value <n: O(log n) n increments: j<n log j = Θ(n·log n) Bit #0 flips n/2 times, bit #1 incurs n/4 flips, bit #2: n/4 flips,  ≤ 2n = Θ(n): constant (2) per inc Potential method of analysis: Let cj denote cost of j-th operation, Φj:=#1s in counter after j-th op.  before (j+1)-st op. 1jn cj/n  maxj (cj+Φj−Φj-1) + (Φ0−Φn)/n Φ0 = 0, Φj  0 = 2 - Φn/n

§3 Amortized Analysis 1jn cj/n  maxj (cj+Φj−Φj-1) + (Φ0−Φn)/n Motivating example: Repeated binary increment, #bit flips when counting to n? Inc & decrement ? Definition: Fix an implementation A of abstract data type D with methods M1, M2,…,Mk. Let T(n) denote the worst-case cost of any n-element sequence C of calls C1,C2,…,Cn  {M1,…,Mk}. Then the amortized cost of A is defined as T(n)/n. Don't confuse: amortized cost expected cost Potential method of analysis: Let cj denote cost of j-th operation, Conceive Φj such that right hand side is „small“ average-case cost 1jn cj/n  maxj (cj+Φj−Φj-1) + (Φ0−Φn)/n

Worst, Average-Case, Expected, Amortized Algorithm A, fixed input size n: worst case runtime average case (eg uniform distribution) best case Inputs: A B C D E F G H I J K asymptotically as n→∞

Worst, Average-Case, Expected, Amortized Randomized algorithm A, fixed input X: worst case runtime expected case best case Trial # 1 2 3 4 5 6 7 8 9 10 11 worst-case over all X of length n asympt. as n→∞

Worst, Average-Case, Expected, Amortized Data type D, method M worst case runtime amortized cost best case Call # 1 2 3 4 5 6 7 8 9 10 11 … n Methods M1,…Mk: worst-case over seq. of length n

§3 Relaxed Binomial Trees A relaxed Binomial Tree of order k1 consists of a root with k children, jth (j=1…k) being a binom.tree of order j-1 relaxed Bk B0 B0 Bk Bk-1 B1 B2 B1 relaxed "Mark" indicates child #j may have order =j-2  j-2 Lemma: A relaxed Binomial Tree of order k has Fk+2Ω(1.6k) nodes Binom.Tree of deg. k: =2k nodes AVL Tree of deg. k:  Fk+3 nodes Merge Prune Proof by induction + homework: 1 + F1 + F2 + … + Fk = Fk+2  φk φ := (1+√5)/2 > 1.6 Fibonacci no.s Fk 1 1

§3 Fibonacci Heaps Bk H A relaxed Binomial Tree of order k1 consists of a root with k children, jth (j=1…k) being a relaxed binom.tree of order j-2 Bk B0 B0 Bk-1 B1 H min : child j may have order j-2 A Fibonacci Heap H is a list of t heap-ordered relaxed binomial trees with pointer to the min. Lemma: A relaxed Binomial Tree of order k has Fk+2Ω(1.6k) nodes Lemma: A relaxed Binomial Tree of n nodes has order k  O(log n) Extract min.key: O(log n) Decrease key: O(1) Merge two Fib.heaps: O(1) Insert element: O(1) Create 1-elem.Fib.heap: O(1) amor- tized cost

§3 Extract Minimum t cj + Φj–Φj-1  O(log n) A relaxed Binomial Tree of order k1 consists of a root with k children, jth (j=1…k) being a relaxed binom.tree of order j-2 Bk B0 B0 Bk-1 B1 H min : child j may have order j-2 A Fibonacci Heap H is a list of t heap-ordered relaxed binomial trees with pointer to the min. Lemma: A relaxed Binomial Tree of n nodes has order k  O(log n) t Extract min.key: O(log n) amor- tized cost Delete target of min.pointr Merge two Fibonacci heaps. Consolidate s.t. each tree order k occurs only once! bucket sort new? ! ! cj + Φj–Φj-1  O(log n) jn cj/n  maxj (cj + Φj – Φj-1) + (Φ0−Φn)/n Potential Φ := Θ( t )  O(log n) Φ0=0, Φn≥0

§3 Decrease Key cj + Φj–Φj-1  O(1) Φ0=0, Φn≥0 Bk H A relaxed Binomial Tree of order k1 consists of a root with k children, jth (j=1…k) being a relaxed binom.tree of order j-2 Bk B0 B0 Bk-1 B1 H min : child j may have order j-2 A Fibonacci Heap H is a list of t heap-ordered relaxed binomial trees with pointer to the min. Lemma: A relaxed Binomial Tree of n nodes has order k  O(log n) Decrease key: O(1) amor- tized cost cut subtree mark parent if already marked: reset, cut & cascade up X cj + Φj–Φj-1  O(1) Potential Φ := C · t Potential Φ:=Θ(t+2m) Φ0=0, Φn≥0

§3 Cuts, Marks, and Cascading Decrease key: O(1) cut subtree mark parent if already marked: reset, cut & cascade up X cj + Φj – Φj-1  O(1) Potential Φ:=C·(t+2m) Φ0=0, Φn≥0