Download presentation

Presentation is loading. Please wait.

Published bySydney Hagan Modified over 4 years ago

1
BY Lecturer: Aisha Dawood

2
The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = { 0, 1, 2,... }. We will use asymptotic notation primarily to describe the running times of algorithms, as when we wrote that insertion sorts worst-case running time is (n 2 ). 2

3
O notation ( Big-Oh) o notation (Little-oh) -notation (Big – Omega) ω-notation (Little – Omega) -Notation (Theta) 3

4
O notation (Big – Oh) For a given function g(n), we denote by O(g(n)) (pronounced big-oh of g of n or sometimes just oh of g of n) the set of functions: 4 For all values n at and to the right of n0, the value of the function f(n) is on or below cg(n). We write f(n) =O(g(n)), to indicate that a function f(n) is a member of the set O(g(n)). O-notation to give an upper bound on a function, cg(n) is the upper pound of f(n).

5
When we say the running time is O(n 2 ) what does it mean? we mean that there is a function g(n) that grows like O(n 2 ) such that for any value of n, no matter what particular input of size n is chosen, the running time on that input is bounded from above by the value g(n). Equivalently, we mean that the worst-case running time is O(n 2 ). 5

6
The following function are O(n 2 ): f(n) = n 2 + n f(n) = an 2 + b f(n) = bn + c f(n) = an f(n) = n 2 f(n) = log(n) But not: f(n) = n 3 f(n) = n 4 + logn 6

7
Using O notation, we can often describe the running time of an algorithm merely by inspecting the algorithms overall structure. For example, the nested loop structures of the insertion sort algorithm immediately yields an O(n2) upper bound on the worst case running time. Why? 7

8
The asymptotic upper bound provided by O-notation may or may not be asymptotically tight, e.g. The bound 2n 2 = O(n 2 ) is asymptotically tight, but the bound 2n = O(n 2 ) is not. We use o-notation to denote an upper bound that is not asymptotically tight, For example, 2n = o(n 2 ), but 2n 2 o(n 2 ). We formally define o(g(n)) (little-oh of g of n) as the set: The definitions of O-notation and o-notation are similar. The main difference is that in f(n) = O(g(n)), the bound 0 f(n) cg(n) holds for some constant c > 0, But in f(n) = o(g(n)), the bound 0 f(n) 0. 8

9
Intuitively, in o-notation, the function f(n) becomes insignificant relative to g(n) as n approaches infinity; that is: 9

10
The following function are o(n 2 ): f(n) = bn + c f(n) = a f(n) = log(n) But not: f(n) = n 2 f(n) = n 4 + logn 10

11
O-notation provides an asymptotic upper bound on a function, – notation provides an asymptotic lower bound. For a given function g(n), we denote by (g(n)) (pronounced big- omega of g of n or sometimes just omega of g of n) the set of functions: 11 -notation gives a lower bound for a function. We write f(n) = (g(n)) if there are positive constants n 0 and c such that at and to the right of n 0, the value of f(n) always lies on or above cg(n).

12
we say that the running time of an algorithm is (n 2 ), what does it mean? we mean that no matter what particular input of size n is chosen for each value of n, the running time on that input is at least a constant times n 2, for sufficiently large n. 12

13
Using Big-Omega we are giving a lower bound on the best-case running time of an algorithm. For example, the best-case running time of insertion sort is (n), which implies that the running time of insertion sort is (n). The running time of insertion sort belongs to both(n) and O(n2). 13

14
ω-notation is to -notation as o-notation is to O-notation. We use ω-notation to denote a lower bound that is not asymptotically tight. Formally, however, we define ω(g(n)) (little-omega of g of n) as the set: For example, n 2 /2 = ω(n), but 2n/2 ω(n). 14

15
The relation f(n) = ω(g(n)) implies that if the limit exists. That is, f(n) becomes large relative to g(n) as n approaches infinity 15

16
Notation For a given function g(n) we denote by (g(n)) the set of functions: 16 We write f(n)= (g(n)) : if there exist positive constants n 0, c 1, and c 2 such that at and to the right of n0, the value of f(n), always lies between c 1.g(n) and c 2.g(n) inclusive. In other words, for all n n0, the function f (n) is equal to g(n). We say that g(n) is an asymptotically tight bound for f(n).

Similar presentations

Presentation is loading. Please wait....

OK

Asymptotic Notation Faculty Name: Ruhi Fatima

Asymptotic Notation Faculty Name: Ruhi Fatima

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google