+ All Categories
Home > Documents > Comp3050 Logarithms and Exponents. A quick revision We know that log b a = c if a = b c We also know...

Comp3050 Logarithms and Exponents. A quick revision We know that log b a = c if a = b c We also know...

Date post: 26-Mar-2015
Category:
Upload: nicole-guthrie
View: 214 times
Download: 1 times
Share this document with a friend
Popular Tags:
26
Comp3050 Logarithms and Exponents
Transcript
Page 1: Comp3050 Logarithms and Exponents. 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.

Comp3050

Logarithms and Exponents

Page 2: Comp3050 Logarithms and Exponents. 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.

A quick revision

We know thatlog b a = c if a = bc

We also know that if b = 2, we may omit writing the base of the algorithm

i.e. log 1024 = 10

Page 3: Comp3050 Logarithms and Exponents. 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.

Some rules for the algorithms

If a, b and c are positive real numbers then:

a.Logb ac = logb a + logb c

b.Logb a/c = logb a – logb c

c.Logb ac = c logb a

d.blogca = alog

cb

e.Logb a = logc a/logc b

f.Log 2 = 1

Page 4: Comp3050 Logarithms and Exponents. 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.

Exponent rules

We also know that(ba)c = bac

Babc = b a+c

Ba/bc = ba-c

Based on these rules:

2log n = nlog2

=n

Page 5: Comp3050 Logarithms and Exponents. 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.

More examples

4n = (22)n = 22n (exponent rule 1) Log 2n = n (rule 3)

What will be: log4n

Page 6: Comp3050 Logarithms and Exponents. 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.

More examples

Algorithm A uses 10nlogn operations. B uses n2 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 n0)

What if Algo B is nn

Page 7: Comp3050 Logarithms and Exponents. 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.

Explanation

We observe that Till n = 10, ALGO A is moreAfter n=10 Algo B is more

So it is not always that nlogn is less then n2

10nlogn n21 0 12 6.0206 43 14.31364 94 24.0824 165 34.9485 256 46.68908 367 59.15686 498 72.2472 649 85.88183 81

10 100 10011 114.5532 12112 129.5017 14413 144.8126 16914 160.4579 19615 176.4137 22516 192.6592 25617 209.1763 289

Page 8: Comp3050 Logarithms and Exponents. 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.

Three types of bounds

There are three bounds:

Big O, big (Omega) and big (theta)

We saw two function 10nlogn and n2

We also saw that for different n’s they differ

So if we plot them:

Page 9: Comp3050 Logarithms and Exponents. 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.

Graphs plotted

Page 10: Comp3050 Logarithms and Exponents. 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.

Big O

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

Page 11: Comp3050 Logarithms and Exponents. 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.

For this example:

F(x) = 10nlogn

The Asymptotic O is O(n)

G(x) = n2

The Asymptotic O is O(n2)

Page 12: Comp3050 Logarithms and Exponents. 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.

Big

We may call Big as BEST CASE We may call Big as BEST CASE

Page 13: Comp3050 Logarithms and Exponents. 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.

Making big Omega

F(x) = 10nlogn G(x) = n2

So the function is

F(x) = (nlogn)

for c=10 and n0 = 10

As now nlogn >=cnlogn. When n>n0 (10)

Page 14: Comp3050 Logarithms and Exponents. 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.

Big

Page 15: Comp3050 Logarithms and Exponents. 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.

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)

Page 16: Comp3050 Logarithms and Exponents. 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.

General rule

Small o is called strict upper bound

F(n) = 12n2 + 6n will have o(n3)

And small omega will be

(n) -> strict lower bound

Page 17: Comp3050 Logarithms and Exponents. 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.

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?

Page 18: Comp3050 Logarithms and Exponents. 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.

solution

Page 19: Comp3050 Logarithms and Exponents. 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.

More example

There are two prefixAverage algo’s 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

Page 20: Comp3050 Logarithms and Exponents. 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 1

Page 21: Comp3050 Logarithms and Exponents. 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 2

Page 22: Comp3050 Logarithms and Exponents. 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.

Result

The running time of algorithm prefixAvarages1 is O(n) for first and second term

For third term onwards it is O(n2)

So the running time would be O(n2)

Page 23: Comp3050 Logarithms and Exponents. 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.

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)

Page 24: Comp3050 Logarithms and Exponents. 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.

Example

Calculate Algo time

Loop1 Loop2 Loop3 Loop4 Loop5 – O(n4)

Page 25: Comp3050 Logarithms and Exponents. 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.

Example

Page 26: Comp3050 Logarithms and Exponents. 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.

Solution


Recommended