Presentation is loading. Please wait.

Presentation is loading. Please wait.

Asymptotic Notation (O, Ω,  ) s Describes the behavior of the time or space complexity for large instance characteristics s Common asymptotic functions.

Similar presentations


Presentation on theme: "Asymptotic Notation (O, Ω,  ) s Describes the behavior of the time or space complexity for large instance characteristics s Common asymptotic functions."— Presentation transcript:

1

2 Asymptotic Notation (O, Ω,  ) s Describes the behavior of the time or space complexity for large instance characteristics s Common asymptotic functions – 1 (constant), log n, n (linear) – n log n, n 2, n 3 – 2 n ( exponential), n! – where n usually refer to the number of instance of data (data 的個數 )

3 Common asymptotic functions

4

5

6 Big-O notation s The big O notation provides an upper bound for the function f s Definition: –f(n) = O(g(n)) iff positive constants c and n 0 exist such that f(n)  c g(n) for all n, n  n 0 –e.g. f(n) = 10 n 2 + 4n + 2 then, f(n) = O( n 2 ), or O( n 3 ), O( n 4 ), …

7 Ω(Omega) notation s The Ω notation provides a lower bound for the function f s Definition: –f(n) = Ω(g(n)) iff positive constants c and n 0 exist such that f(n)  c g(n) for all n, n  n 0 –e.g. f(n) = 10 n 2 + 4n + 2 then, f(n) = Ω( n 2 ), or Ω( n ), Ω( 1 )

8  notation s The  notation is used when the function f can be bounded both from above and below by the same function g s Definition: –f(n) =  (g(n)) iff positive constants c 1 and c 2, and an n 0 exist such that c 1 g(n)  f(n)  c 2 g(n) for all n, n  n 0 –e.g. f(n) = 10 n 2 + 4n + 2 then, f(n) = Ω( n 2 ), and f(n)=O( n 2 ), therefore, f(n)=  ( n 2 )

9 Practical Complexities 10 9 instructions/second

10 Impractical Complexities 10 9 instructions/second

11 Faster Computer Vs Better Algorithm Algorithmic improvement more useful than hardware improvement. E.g. 2 n to n 3

12 Amortized Complexity of Task Sequence s Suppose that a sequence of n tasks is performed. s The worst-case cost of a task is c wc. s Let c i be the (actual) cost of the i th task in this sequence. s So, c i <= c wc, 1 <= i <= n. s n * c wc is an upper bound on the cost of the sequence. s j * c wc is an upper bound on the cost of the first j tasks.

13 Task Sequence s Let c avg be the average cost of a task in this sequence.  So, c avg =  c i /n. s n * c avg is the cost of the sequence. s j * c avg is not an upper bound on the cost of the first j tasks. s Usually, determining c avg is quite hard.

14 Amortized complexity s At times, a better upper bound than j * c wc or n * c wc on sequence cost is obtained using amortized complexity. s The purpose of analyzing amortized complexity is to get tighter upper bound of the actual cost

15 Amortized Complexity s The amortized complexity of a task is the amount you charge the task. s The conventional way to bound the cost of doing a task n times is to use one of the expressions  n*(worst-case cost of task)   worst-case cost  of task i  s The amortized complexity way to bound the cost of doing a task n times is to use one of the expressions  n*(amortized cost of task)   amortized cost of task i 

16 Amortized Complexity s The amortized complexity/cost of individual tasks in any task sequence must satisfy:  actual cost  of task i   amortized cost of task i  s So, we can use  amortized cost of task i  as a bound on the actual complexity of the task sequence.

17 Amortized Complexity s The amortized complexity of a task may bear no direct relationship to the actual complexity of the task.

18 Amortized Complexity s In conventional complexity analysis, each task is charged an amount that is >= its cost.  actual cost  of task i   worst-case cost of task i) s In amortized analysis, some tasks may be charged an amount that is < their cost.  actual cost  of task i   amortized cost of task i)

19 Amortized complexity example: –suppose that a sequence of insert/delete operations: i1, i2, d1, i3, i4, i5, i6, i7, i8, d2, i9 actual cost of each insert is 1 and d1 is 8, d2 is 12. So, the total cost is 29. –In convention, for the upper bound of the cost of the sequence of tasks, we will consider the worst case of each operations; i.e., the cost of insert is 1 and the cost of delete is 12. Therefore, the upper bound of the cost of the sequence of tasks is 9*1+12*2 = 33

20 Amortized complexity –In amortization scheme we charge the actual cost of some operations to others. –The amortized cost of each insert could be 2, d1 and d2 become 6. total is 9*2+6*2=30, which is less than worst case upper bound 33.

21 Amortized Complexity s more examples –the amortized complexity of a sequence of Union and Find operations (will be discuss in chapter 8) –the amortized complexity of a sequence of inserts and deletes of binomial heaps


Download ppt "Asymptotic Notation (O, Ω,  ) s Describes the behavior of the time or space complexity for large instance characteristics s Common asymptotic functions."

Similar presentations


Ads by Google