Download presentation

Presentation is loading. Please wait.

Published byNicole Guthrie Modified over 2 years ago

1
Comp3050 Logarithms and Exponents

2
A quick revision We know that log b a = c if a = b c We also know that if b = 2, we may omit writing the base of the algorithm i.e. log 1024 = 10

3
Some rules for the algorithms If a, b and c are positive real numbers then: a. Log b ac = log b a + log b c b. Log b a/c = log b a – log b c c. Log b a c = c log b a d. b log c a = a log c b e. Log b a = log c a/log c b f. Log 2 = 1

4
Exponent rules We also know that (b a ) c = b ac B a b c = b a+c B a /b c = b a-c Based on these rules: 2 log n = n log2 =n

5
More examples 4 n = (2 2 ) n = 2 2n (exponent rule 1) Log 2 n = n (rule 3) What will be: log 4 n

6
More examples Algorithm A uses 10nlogn operations. B uses n 2 operations? Do you think that Algo A will always be better than Algo B? What value the situations may change (i.e. what will be the value for n 0 ) What if Algo B is n n

7
Explanation We observe that Till n = 10, ALGO A is more After n=10 Algo B is more So it is not always that nlogn is less then n 2 10nlognn

8
Three types of bounds There are three bounds: Big O, big (Omega) and big (theta) We saw two function 10nlogn and n 2 We also saw that for different ns they differ So if we plot them:

9
Graphs plotted

10
Big O We may also call Big O as WORST CASE

11
For this example: F(x) = 10nlogn The Asymptotic O is O(n) G(x) = n 2 The Asymptotic O is O(n 2 )

12
Big We may call Big as BEST CASE

13
Making big Omega F(x) = 10nlogn G(x) = n 2 So the function is F(x) = (nlogn) for c=10 and n0 = 10 As now nlogn >=cnlogn. When n>n0 (10)

14
Big

15
Analysis of Algorithms 15 Intuition for Asymptotic Notation Big-Oh f(n) is O(g(n)) if f(n) is asymptotically less than or equal to g(n) big-Omega f(n) is (g(n)) if f(n) is asymptotically greater than or equal to g(n) big-Theta f(n) is (g(n)) if f(n) is asymptotically equal to g(n) little-oh f(n) is o(g(n)) if f(n) is asymptotically strictly less than g(n) little-omega f(n) is (g(n)) if is asymptotically strictly greater than g(n)

16
General rule Small o is called strict upper bound F(n) = 12n 2 + 6n will have o(n 3 ) And small omega will be (n) -> strict lower bound

17
Question Bill has an algorithm, find2D, to find an element x in an n * n array A. The algorithm find2D iterates over the rows of A, and calls the algorithm arrayFind, on each row, until x is found or it has searched all rows of A. What is the worst case running time of find2D in terms of n? What is the worst case running time of find2D in terms of N, where N is the total size of A? Would it be correct to say that find2D is a linear-time algorithm? Why or why not?

18
solution

19
More example There are two prefixAverage algos PrefixAlgo is creating array B as each element of Array B must be the average of the elements of Array A till ith location of array B

20
Algorithm 1

21
Algorithm 2

22
Result The running time of algorithm prefixAvarages1 is O(n) for first and second term For third term onwards it is O(n 2 ) So the running time would be O(n 2 )

23
Result The running time of algorithm prefixAvarages2 is O(1) for first and second term For third term onwards it is O(n) So the running time would be O(n)

24
Example Calculate Algo time Loop1 Loop2 Loop3 Loop4 Loop5 – O(n 4 )

25
Example

26
Solution

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google