Amortized Analysis. p2. Amortized analysis: Guarantees the avg. performance of each operation in the worst case. Aggregate method Accounting method Potential.

Slides:



Advertisements
Similar presentations
ERROR-DETECTING AND ERROR- CORRECTING CODES ․ A simple scheme for detecting errors is to append a parity check digit to each block of message. Even parity:
Advertisements

Homework - Chapter 03 Solution.
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 3 Tuesday, 2/9/10 Amortized Analysis.
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
CPSC 411, Fall 2008: Set 6 1 CPSC 411 Design and Analysis of Algorithms Set 6: Amortized Analysis Prof. Jennifer Welch Fall 2008.
Efficient aggregation of encrypted data in Wireless Sensor Network.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
第 4 章 迴歸的同步推論與其他主題.
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2005 Lecture 3 Tuesday, 2/8/05 Amortized Analysis.
第三章 變數與繫結 陳維魁 博士 儒林圖書公司. 2 大綱  變數的定義  變數元件  儲存區配置問題  參考的透明性  完全計算  捷徑計算  繫結 (binding)  繫結時間  精選習題.
Young/Freeman University Physics 11e. Ch 18 Thermal Properties of Matter © 2005 Pearson Education.
Tirgul 9 Amortized analysis Graph representation.
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
第一章 演算法:效率、分析與量級 1.1演算法 1.2發展有效率演算法的重要性 1.3演算法的分析 1.4量級(Order)
UMass Lowell Computer Science Graduate Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Lecture 3 Tuesday, 2/10/09 Amortized Analysis.
1 第四章 多變數函數的微分學 § 4.1 偏導數定義 定義 極限值 ■. 2 定理 極限值的基本定理 (1) 極限值的唯一性 : 若 存在,則 其值必為唯一。 (2) 若 且 ( 與 為常數 ) , 則 且 為常數且.
Greedy Algorithms. 2 Greedy Methods ( 描述 1) * 解最佳化問題的演算法, 其解題過程可看成是由一 連串的決策步驟所組成, 而每一步驟都有一組選擇 要選定. * 一個 greedy method 在每一決策步驟總是選定那目 前看來最好 的選擇. *Greedy.
Amortized Anaysis of Algorihms, A.Yazici, Spring 2007CEng Amortized Analysis of Algorithms Adnan YAZICI Dept. of Computer Engineering Middle East.
Theory I Algorithm Design and Analysis (8 – Dynamic tables) Prof. Th. Ottmann.
Amortized Analysis (chap. 17) Not just consider one operation, but a sequence of operations on a given data structure. Average cost over a sequence of.
Chapter 2 Getting Started Insertion Sort: 能有效率地排序小數字的演算法 範例 :
Amortized Analysis.
Supply-side collaboration and its value in supply chains 指導教授:林燦煌博士 指導教授:林燦煌博士 研 究 生:黃笙源 研 究 生:黃笙源 Yonghui Fu, Rajesh Piplani European Journal of Operations.
資料結構實習-一 參數傳遞.
Lecture 7 Sorting in Linear Time. Sorting in Linear Time2 7.1 Lower bounds for sorting 本節探討排序所耗用的時間複雜度下限。 任何一個以比較為基礎排序的演算法,排序 n 個元 素時至少耗用 Ω(nlogn) 次比較。
觀測量的權 權的觀念與計算.
CS333 / Cutler Amortized Analysis 1 Amortized Analysis The average cost of a sequence of n operations on a given Data Structure. Aggregate Analysis Accounting.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
2010 MCML introduction 製作日期: 2010/9/10 製作人 : 胡名霞.
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
Andreas Klappenecker [based on the slides of Prof. Welch]
質數 (Prime) 相關問題 (III) — 如何找出相對大的質數 Date: May 27, 2009 Introducer: Hsing-Yen Ann.
Chapter 7 Sampling Distribution
Cluster Analysis 目的 – 將資料分成幾個相異性最大的群組 基本問題 – 如何衡量事務之間的相似性 – 如何將相似的資料歸入同一群組 – 如何解釋群組的特性.
17.Amortized analysis Hsu, Lih-Hsing. Computer Theory Lab. Chapter 17P.2 The time required to perform a sequence of data structure operations in average.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 2 (Part 2) Tuesday, 9/11/01 Amortized Analysis.
計數值抽樣計劃 使用 MIL-105D 表. 表 10-1 Sample Sizes Code Letters.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
1 Knapsack Cryptosystems 2 ◎ Merkle-Hellman Knapsack Cryptosystem 觀察: (1) 0/1 knapsack problem (i.e. sum of subset) 例:已知 C = 14, A = (1, 10, 5, 22, 3)
CH 14-可靠度工程之數學基礎 探討重點 失效時間之機率分配 指數模式之可靠度工程.
Amortized Analysis Not just consider one operation, but a sequence of operations on a given data structure. Average cost over a sequence of operations.
CS 473Lecture 121 CS473-Algorithms I Lecture 12 Amortized Analysis.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 5: Advanced Design Techniques.
Amortized Analysis The problem domains vary widely, so this approach is not tied to any single data structure The goal is to guarantee the average performance.
Amortized Analysis Typically, most data structures provide absolute guarantees on the worst case time for performing a single operation. We will study.
1 Chapter 17: Amortized Analysis I. 2 About this lecture Given a data structure, amortized analysis studies in a sequence of operations, the average time.
Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2004 Simonas Šaltenis E1-215b
Amortized Analysis We examined worst-case, average-case and best-case analysis performance In amortized analysis we care for the cost of one operation.
Amortized Analysis Some of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore.
CSCE 411H Design and Analysis of Algorithms Set 6: Amortized Analysis Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 6 1 * Slides adapted.
資料結構(計財系).
Amortized Analysis. Problem What is the time complexity of n insert operations into an dynamic array, which doubles its size each time it is completely.
Introduction to Algorithms Amortized Analysis My T. UF.
Amortized Analysis In amortized analysis, the time required to perform a sequence of operations is averaged over all the operations performed Aggregate.
Amortized Analysis.
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Amortized Analysis (chap. 17)
CSCE 411 Design and Analysis of Algorithms
Chapter 17: Amortized Analysis I
Presentation by Marty Krogel
Amortized Analysis The problem domains vary widely, so this approach is not tied to any single data structure The goal is to guarantee the average performance.
Chapter 17 Amortized Analysis Lee, Hsiu-Hui
CSCE 411 Design and Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms
Presentation transcript:

Amortized Analysis

p2. Amortized analysis: Guarantees the avg. performance of each operation in the worst case. Aggregate method Accounting method Potential method Aggregate method A sequence of n operations takes worst-case time T(n) in total. In the worst case, the amortized cost (average cost) per operation is T(n)/n

p3. Eg.1 [Stack operation] PUSH(S,x): pushes object x onto stack S POP(S): pops the top of stack S and return the popped object Each runs in O(1) time ( 假設只需一單位時間 ) 故 n 個 PUSH 和 POP operations 需  (n) time 考慮 MULTIPOP(S, k): pops the top k objects of stack S MULTIPOP(S, k) While not STACK-EMPTY(S) and k  0 do { POP(S) k  k-1 } 故執行一 MULTIPOP 需 min{s, k} 個步驟

p4. 問題 : 執行上述 PUSH, POP, MULTIPOP n 次 假設 initial stack 為 empty 試問每一 operation 在 worst-case 之 amortized cost? Each object can be popped at most once for each time it is pushed. 上述問題只需 O(n) time O(n)/n = O(1) 每個 operation 平均所需的時間

p5. Eg.2 [Incrementing a binary counter] A k-bit binary counter, counts upward from 0 A[k-1] A[k-2]…A[1] A[0] highest order bit lowest order bit Increment(A) { i  0; while i<length[A] and A[i]=1 do A[i]  0; i  i+1; if i<length[A] then A[i]  1; } Ripple-carry counter A[7]A[6]A[5]A[4]A[3]A[2]A[1]A[0]

p6. 問題 : 執行 n 次 ( 依序 ) Increment operations. 在 worst-case 每一 operation 之 amortized cost 為何 ? A[0] 每 1 次改變一次 A[1] 每 2 次改變一次 A[i] 每 2 i 次改變一次 故 amortized cost of each operation 為 O(n)/n = O(1)

p7. Potential method D 0 : initial data structure c i : actual cost of the i-th operation D i : data structure after applying the i-th operation to D i-1  : potential function  (D i ) is a real number : the amortized cost of the i-th operation w.r.t potential function is 若  (D n )   (D 0 ), 則 total amortized cost 為 total actual cost 之一 upper bound

p8. Eg. 1 [Stack operation] 定義 potential function  : stack size  (D 0 )=0, 亦知  (D i )  0 i-th op. PUSH: MULTIPOP(S, k): 令 k’=min{k,S} POP: 同理 所以一序列 n 個 op 之 total amortized cost 為 O(n)

p9. Eg. 2 [Incrementing a binary counter] 對 counter 而言其 potential function 值為在 i-th op 後 被設定為 1 的 bit 個數 b i = # of 1’s in the counter after the i-th operation Suppose that the i-th Increment op. resets t i bits Actual cost  t i +1 # of 1’s in the counter after the i-th op.: b i  b i-1 – t i + 1

p10. Implement a Queue with two Stacks: Stack A : Dequeue Stack B : Enqueue S B : stack size of B Enqueue(x) { PUSH(B, x) } Dequeue(Q) { if Empty(Q) then return “empty queue”; else if Empty(A) then while not Empty(B) do PUSH(A, POP(B); POP(A); } Stack AStack B frontrear

p11.  (D i )=2[stack size of B after the i-th operation] Enqueue: Dequeue:

p12. i Table T:

p13. Table expansion: Table-Insert(T, x) { if size[T]=0 then allocate table[T] with 1 slot size[T]=1; if num[T]=size[T] then { allocate new-table with 2*size[T] slots;  Expansion insert all items in table[T] into new-table; free table[T]; table[T] = new-table; size[T] = 2*size[T];} insert x into table[T]; num[T]= num[T] + 1;}

p14. Define potential function No expansion after the ith op: With expansion after the ith op:

p15. Table expansion and contraction: I, D, I, I, D, D, I, I, I………. : A sequence of n operations. Preserve two properties:. Load factor is bounded below by a constant.. The amortized cost of a table op is bounded above by a const. Strategy:.Double the table size when an item is inserted into a full table..Halve the table size when a deletion causes the table to become less than ¼ full.

p16. Define potential function: If the i-th operation is Table-Insert: If the load factor >= ½, then the analysis is the same as before.

p17.

p18. If the i-th operation is Table-Delete:

p19. Exercise!