Relevant Mathematics - PowerPoint PPT Presentation

1 / 165
About This Presentation
Title:

Relevant Mathematics

Description:

I claim 'there is a girl whom every boy loves.' Oh yeah! Prove it. I produce MM ... 'x loves some girl.' I give an 'alg' with input x, and output an y. and a ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 166
Provided by: JeffEd3
Category:

less

Transcript and Presenter's Notes

Title: Relevant Mathematics


1
Relevant Mathematics
Thinking about Algorithms Abstractly
Logic Quantifiers The Time Complexity of an
Algorithm Classifying Functions Adding Made
Easy Recurrence Relations
  • Jeff Edmonds
  • York University

COSC 3101
Lecture ?
2
Some Math
Done here
In Iterative Algs (GCD) Repeated here
3
Some Math
You are on your own.
Done here
4
Some Math
In Iterative Algs (Insertion Sort) In
Recursive Algs (Multiplying) Repeated here.
In Recursive Algs (Multiplying, Towers of
Hanoi,Merge Sort) Repeated here.
5
Quantifers
6
Quantifiers, Do you understand them?
? g, " b, Loves(b, g)
A(I)P(I) means algorithm A gives the required
output for problem P on
instance I. Time(A,I) is the running time of
algorithm A on instance
I. T(n) some function like n2.
  • Express
  • Problem P is computable by some algorithm.
  • Problem P is computable in time T(n).
  • Problem P is computable in polynomial time.
  • The computational class Exponential Time
    is strictly bigger than the computational
    class Polynomial Time.

7
Understand Quantifiers!!!
" b, Loves(b, MM)
8
Understand Quantifiers!!!
" b, Loves(b, MM)
Every boy loves Marilin Monro
False
True
9
Understand Quantifiers!!!
" b, Loves(b, MM)
Every boy loves Marilin Monro
b vs MM?
b is a variable.
MM is an object. (cannot appear in ? or ?) The
statement is about MM.
10
Understand Quantifiers!!!
" b, Loves(b, g)
Every boy loves g
b vs g?
b is a free variable. (appears in ? or ?) The
statement is about the set of all boys.
g is a bound variable. (does not appear in ? or
?) The statement is about g.
x5 loop i 1..9 x end loop
11
Understand Quantifiers!!!
" b, Loves(b, g)
g is a bound variable. (does not appear in ? or
?) The statement is about g.
Loved(g) " b, Loves(b, g)
12
Understand Quantifiers!!!
g, " b, Loves(b, g)
There is a girl whom every boy loves
False
True
13
Understand Quantifiers!!!
" b, g, Loves(b, g)
Every boy loves some girl.
False
True
Still True
14
Understand Quantifiers!!!
" b, g, Loves(b, g)
g, " b, Loves(b, g)
vs
  • Could be a separate girl for each boy.
  • One girl

15
Understand Quantifiers!!!
We read this left to right.
I produce the object when it is a .
I produce the object when it is a ".
I can always win if and only if statement is true.
16
Understand Quantifiers!!!
Easy
I produce Sam
And prove Sam does not loves MM.
I can win. Hence, statement is true.
17
Understand Quantifiers!!!
18
Understand Quantifiers!!!
Instead play the game.
Sam does not loves MM.
I cannot win. Hence, statement is false.
19
Understand Quantifiers!!!
I prove Sam does loves MM.
I can always win. Hence, statement is true.
20
Understand Quantifiers!!!
I prove x does loves MM.
This proof needs to work without knowing x
I can always win. Hence, statement is true.
21
Understand Quantifiers!!!
I give an alg with input x, and output a proof
that x loves MM.
I can always win. Hence, statement is true.
22
Understand Quantifiers!!!
I claim there is a girl whom every boy loves.
Oh yeah! Prove it.
I produce MM
I proceed to prove every boy loves MM
23
Understand Quantifiers!!!
I proceed to prove every boy loves MM
No! I produce boy x.
I give an alg with input x, and output a proof
that x loves MM.
I can always win. Hence, statement is true.
24
Understand Quantifiers!!!
I claim Every boy loves some girl.
No! I produce boy x.
I proceed to prove x loves some girl.
I produce girl y
I prove x loves y.
I can always win. Hence, statement is true.
25
Understand Quantifiers!!!
I claim Every boy loves some girl.
No! I produce boy x.
I proceed to prove x loves some girl.
I give an alg with input x, and output an yand
a proof that x loves y.
26
Understand Quantifiers!!!
I give an alg with input y, and output an xand
a proof that x loves y.
You give Sam,I give Beth.
You give Bob, I give MM.

27
Understand Quantifiers!!!
g, " b, Loves(b, g)
Ø

" g, Ø " b, Loves(b, g)
" g, b, Ø Loves(b, g)
" g, b, ØLoves(b, g)
Ø moves right
28
Understand Quantifiers!!!
The relation is true. xy x (5-x) 5
I can always win. Hence, the statement is true.
29
Understand Quantifiers!!!
The relation is true. xy x 5/x 5
I can always win. Hence, the statement is true.
What a minute the statement is false!
30
Understand Quantifiers!!!
I can always win. Hence, the negated statement is
true and the original statement is false.
31
Classifying Functions
Giving an idea of how fast a function grows
without going into too much detail.
32
Definition of Theta
f(n) ?(g(n))
33
Definition of Theta
f(n) ?(g(n))
  • f(n) is sandwiched between c1g(n) and c2g(n)

34
Definition of Theta
f(n) ?(g(n))
  • f(n) is sandwiched between c1g(n) and c2g(n)
  • for some sufficiently small c1 ( 0.0001)
  • for some sufficiently large c2 ( 1000)

35
Definition of Theta
f(n) ?(g(n))
  • For all sufficiently large n

36
Definition of Theta
f(n) ?(g(n))
  • For all sufficiently large n
  • For some definition of sufficiently large

37
Definition of Theta
3n2 7n 8 ?(n2)
38
Definition of Theta
3n2 7n 8 ?(n2)
True
7n 8 1n2 7 8/n 1n
39
Definition of Theta
3n2 7n 8 ?(n)
The reverse statement
40
Definition of Theta
3n2 7n 8 n?(1)
Polynomial time
c1, c2, n0, " n ³ n0 nc1 f(n) nc2
41
Definition of Theta
3n2 7n 8 2?(n)
Exponential time
c1, c2, n0, " n ³ n0 2c1n f(n) 2c2n
42
Order of Quantifiers
f(n) ?(g(n))
?
43
Order of Quantifiers
f(n) ?(g(n))
  • No! It cannot be a different c1 and c2
  • for each n.

44
The Time Complexity of a Problem P
Merge, Quick, and Heap Sort can sort N numbers
using O(N log N) comparisons between the values.
Theorem No algorithm can sort faster.
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
45
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
Upper Bound
  • Problem P is computable in time Tupper(n)
  • if there is an algorithm A which
  • outputs the correct answer
  • in this much time
  • given any input instance I.

A, " I, A(I)P(I) and Time(A,I)
Tupper(I)
Eg Sorting computable in Tupper(n) O(n2) time.
46
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
A, " I, A(I)P(I) and Time(A,I)
Tupper(I)
" I, A, A(I)P(I) and Time(A,I)
Tupper(I) What does this say?
One algorithm A, that works for every instance
IvsA different algorithm AI for each instance I.
47
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
A, " I, A(I)P(I) and Time(A,I)
Tupper(I)
" I, A, A(I)P(I) and Time(A,I)
Tupper(I) What does this say?
True for any problem P and time Tupper. Given
fixed I. Its output is P(I).
Let AP(I) be the algorithm that outputs the
string P(I).
48
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
Lower Bound
Time Tlower(n) is a lower bound for problem p if
no algorithm solve the problem faster.
There may be algorithms that give the correct
answer or run quickly on some inputs instance.
49
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
Lower Bound Time Tlower(n) is a lower bound for
problem p if no algorithm solve the problem
faster.
But for every algorithm, there is at least one
instance I for which either the algorithm gives
the wrong answer or it runs in too much time.
Eg No algorithm can sort N values in Tlower
sqrt(N) time.
50
The Time Complexity of a Problem P
The minimum time needed by an algorithm to solve
it.
Upper Bound
A, " I, A(I)P(I) and Time(A,I)
Tupper(I)
Lower Bound
" A, I, A(I) ? P(I) or Time(A,I) ³
Tlower(I)
There is and there isnt a faster
algorithmare almost negations of each other.
51
Prover-Adversary Game
Upper Bound
A, " I, A(I)P(I) and Time(A,I)
Tupper(I)
I have an algorithm A that I claim works and is
fast.
Oh yeah, I have an input I for which it does not.
  • I win if A on input I gives
  • the correct output
  • in the allotted time.

What we have been doing all along.
52
Prover-Adversary Game
Lower Bound
I have an algorithm A that I claim works and is
fast.
Oh yeah, I have an input I for which it does not .
  • I win if A on input I gives
  • the wrong output or
  • runs slow.

53
Prover-Adversary Game
Lower Bound
I have an algorithm A that I claim works and is
fast.
Lower bounds are very hard to prove, because I
must consider every algorithm no matter how
strange.
54
Quantifiers, Do you understand them?
? g, " b, Loves(b, g)
A(I)P(I) means algorithm A gives the required
output for problem P on
instance I. Time(A,I) is the running time of
algorithm A on instance
I. T(n) some function like n2.
  • Express
  • Problem P is computable by some algorithm.
  • Problem P is computable in time T(n).
  • Problem P is computable in polynomial time.
  • The computational class Exponential Time
    is strictly bigger than the computational
    class Polynomial Time.

55
  • Problem P is computable by some algorithm.
  • Problem P is computable in time T(n).
  • Problem P is computable in polynomial time.
  • Problem P is not computable in polynomial time.
  • Problem P is computable in exponential time.
  • The computational class Exponential Time
    is strictly bigger than the computational
    class Polynomial Time.

? A, " I, A(I)P(I)
? A, " I, A(I)P(I) Time(A,I) T(I)
? A, c, n0," I, A(I)P(I) (I lt n0 or
Time(A,I) Ic)
? A, c, n0, ? I, A(I)?P(I) or (I n0
Time(A,I) gt Ic)
? A, c, n0," I, A(I)P(I) (I lt n0 or
Time(A,I) 2cI)
56
Some Math
You are on your own.
57
The Time Complexity of an Algorithm
  • Specifies how the running time depends on the
    size of the input.

58
Purpose?
59
Purpose
  • To estimate how long a program will run.
  • To estimate the largest input that can reasonably
    be given to the program.
  • To compare the efficiency of different
    algorithms.
  • To help focus on the parts of code that are
    executed the largest number of times.
  • To choose an algorithm for an application.

60
Time Complexity Is a Function
  • Specifies how the running time depends on the
    size of the input.
  • A function mapping
  • size of input
  • time T(n) executed .

61
Definition of Time?
62
Definition of Time
  • of seconds (machine dependent).
  • lines of code executed.
  • of times a specific operation is performed
    (e.g., addition).
  • Which?

63
Definition of Time
  • of seconds (machine dependent).
  • lines of code executed.
  • of times a specific operation is performed
    (e.g., addition).
  • These are all reasonable definitions of time,
    because they are within a constant factor of each
    other.

64
Size of Input Instance?
83920
65
Size of Input Instance
  • Size of paper
  • of bits
  • of digits
  • Value
  • - n 2 in2
  • - n 17 bits
  • - n 5 digits
  • - n 83920

Which are reasonable?
66
Size of Input Instance
  • Size of paper
  • of bits
  • of digits
  • Value
  • - n 2 in2
  • - n 17 bits
  • - n 5 digits
  • - n 83920
  • Intuitive

67
Size of Input Instance
  • Size of paper
  • of bits
  • of digits
  • Value
  • - n 2 in2
  • - n 17 bits
  • - n 5 digits
  • - n 83920
  • Intuitive
  • Formal

68
Size of Input Instance
  • Size of paper
  • of bits
  • of digits
  • Value
  • - n 2 in2
  • - n 17 bits
  • - n 5 digits
  • - n 83920
  • Intuitive
  • Formal
  • Reasonable

of bits 3.32 of digits
69
Size of Input Instance
  • Size of paper
  • of bits
  • of digits
  • Value
  • - n 2 in2
  • - n 17 bits
  • - n 5 digits
  • - n 83920
  • Intuitive
  • Formal
  • Reasonable
  • Unreasonable

of bits log2(Value) Value 2 of bits
70
Two Example Algorithms
  • Sum N array entries
  • A(1) A(2) A(3)
  • Factor value N
  • Input N5917 Output N9761.
  • Algorithm N/2, N/3, N/4, . ?

Time N
Time N
Is this reasonable?
No! One is considered fast and the other slow!
71
Two Example Algorithms
N hard drive 60G lt 236
  • Sum N array entries
  • A(1) A(2) A(3)
  • Factor value N
  • Input N5917 Output N9761.
  • Algorithm N/2, N/3, N/4, . ?

Time N
N crypto key 2100
Time N
Standard input size?
72
Two Example Algorithms
  • Sum N array entries
  • A(1) A(2) A(3)
  • Factor value N
  • Input N5917 Output N9761.
  • Algorithm N/2, N/3, N/4, . ?

size n N
Time N
size n log N
Time N
Size of Input Instance?
73
Two Example Algorithms
  • Sum N array entries
  • A(1) A(2) A(3)
  • Factor value N
  • Input N5917 Output N9761.
  • Algorithm N/2, N/3, N/4, . ?

size n N
n
Time N
size n log N
Time N
2n
Time for you to solve problem instance as a
function of time for me to give you the problem
instance.
74
Two Example Algorithms
  • Sum N array entries
  • A(1) A(2) A(3)
  • Factor value N
  • Input N5917 Output N9761.
  • Algorithm N/2, N/3, N/4, . ?

size n N
n
Time N
size n log N
Time N
2n
Linear vs Exponential Time!
75
Size of Input Instance?
76
Size of Input Instance
10
  • of elements n 10 elements

77
Size of Input Instance
10
  • of elements n 10 elements

Is this reasonable?
78
Size of Input Instance
10
  • of elements n 10 elements
    Reasonable

If each element has size c of bits c
of elements
79
Size of Input Instance
10
  • of elements n 10 elements
    Reasonable

If each element is in 1..n each element has
size log n of bits n log n n
80
Time Complexity Is a Function
  • Specifies how the running time depends on the
    size of the input.
  • A function mapping
  • of bits n needed to represent the input
  • of operations T(n) executed .

81
Which Input of size n?
  • There are 2n inputs of size n.Which do we
    considerfor the time T(n)?

82
Which Input of size n?
83
Which Input of size n?
84
What is the height of tallest person in the class?
Bigger than this?
Smaller than this?
Need to look at every person
Need to look at only one person
85
Time Complexity of Algorithm
The time complexity of an algorithm isthe
largest time required on any input of size n.
  • O(n2) Prove that for every input of size n, the
    algorithm takes no more than cn2 time.
  • O(n2) Find one input of size n, for which the
    algorithm takes at least this much time.
  • ? (n2) Do both.

86
Time Complexity of Problem
The time complexity of a problem is the time
complexity of the fastest algorithm that solves
the problem.
  • O(n2) Provide an algorithm that solves the
    problem in no more than this time.
  • O(n2) Prove that no algorithm can solve it
    faster.
  • ? (n2) Do both.

87
Classifying Functions
n
Note The universe contains approximately 1050
particles.
88
Classifying Functions
Functions
Exp
Constant
Polynomial
Exponential
Double Exp
Poly Logarithmic
89
Classifying Functions
Polynomial
n?(1)
?
Cubic
Quadratic
Linear
?(n3)
?(n4)
?(n2)
?(n)
log(n) not absorbedbecause not Mult-constant
90
Classifying Functions
We consider two (of many) levels in this
hierarchy
Functions
Ignore Power-constant
Exp.
Poly.
2?(n)
n?(1)
Ignore Mult-constant
?(24n / n100)
?(24n)
?(n3 log(n))
?(n2)
Individuals
824n / n100
824n n3
8n2
7n3log(n)
91
BigOh and Theta?
  • 5n2 8n 2log n ?(n2)
  • 5n2 log n 8n 2log n ?(n2 log n)

Drop low-order terms. Drop multiplicative
constant.
92
Which Functions are Polynomials?
  • nc
  • n0.0001
  • n10000
  • 5n2 8n 2log n
  • 5n2 log n
  • 5n2.5

Drop low-order terms. Drop constant, log, (and
poly) factors. Ignore power constant. Write
n?(1)
93
Which Functions are Exponential?
  • 2n
  • 20.0001 n
  • 210000 n
  • 8n
  • 2n / n100
  • 2n n100

Drop low-order terms. Drop constant, log, and
poly factors. Ignore power constant. Write
2?(n)
94
Notations
95
Definition of Theta
f(n) ?(g(n))
96
Definition of Theta
f(n) ?(g(n))
  • f(n) is sandwiched between c1g(n) and c2g(n)

97
Definition of Theta
f(n) ?(g(n))
  • f(n) is sandwiched between c1g(n) and c2g(n)
  • for some sufficiently small c1 ( 0.0001)
  • for some sufficiently large c2 ( 1000)

98
Definition of Theta
f(n) ?(g(n))
  • For all sufficiently large n

99
Definition of Theta
f(n) ?(g(n))
  • For all sufficiently large n
  • For some definition of sufficiently large

100
Definition of Theta
3n2 7n 8 ?(n2)
101
Order of Quantifiers
f(n) ?(g(n))
  • No! It cannot be a different c1 and c2
  • for each n.

102
Understand Quantifiers!!!
  • Could be a separate girl for each boy.
  • One girl

103
End of first part of math review
  • Recursive Algorithms

104
Adding The Classic Techniques
  • Evaluating ?i1 f(i).

n
105
Arithmetic Sum
?i1..n i 1 2 3 . . . n
?
Gauss
106
Adding Made Easy
number of white dots
1

2

3

. . .

n-1

n

S
1 2 . . . . . . . . n
107
Adding Made Easy
number of white dots
1

2

3

. . .

n-1

n

S
number of yellow dots
n

n-1

n-2

. . .

2

1

S
1 2 . . . . . . . . n
n . . . . . . . 2 1
108
Adding Made Easy
number of yellow dots
109
Arithmetic Sum
?i1..n i 1 2 3 . . . n Q( of
terms last term)
Gauss
True when ever terms increase slowly
110
Geometric Sum
?i0..n 2i 1 2 4 8 . . . 2n
?
111
Geometric Sum
112
Geometric Sum
?i0..n 2i 1 2 4 8 . . . 2n
2 last term - 1
113
Geometric Sum
?i0..n ri r0 r1 r2 . . . rn
?
114
Geometric Sum

S







2
3
n
n
1
Sr
r
r
r
.
.
.
r
r

-

-
n
1
S
Sr
1
r

-
n
1
r
1

S
-
r
1
115
Geometric Sum
When rgt1?

-
n
1
r
1
?i0..n ri

-
r
1
116
Geometric Sum
When rgt1

-
n
1
r
1
Biggest Term
?i0..n ri

?(rn)
-
r
1
117
Geometric Increasing
?i0..n ri r0 r1 r2 . . . rn
Q(biggest term)
True when ever terms increase quickly
118
Geometric Sum
When rlt1?
1 r
-
?i0..n ri

-
1 r
119
Geometric Sum
When rlt1
1 r
-
?i0..n ri

Biggest Term
?(1)
-
1 r
120
Bounded Tail
?i0..n ri r0 r1 r2 . . . rn
Q(1)
True when ever terms decrease quickly
121
Harmonic Sum
?i1..n 1/i 1/1 1/2 1/3 1/4 1/5
1/n ?
122
Sum of Shrinking Function
n
f(i) 1
?i1..n f(i) n
123
Sum of Shrinking Function
n
f(i) ?
?i1..n f(i) n1/2
124
Sum of Shrinking Function

f(i) 1/2i
?i1..n f(i) 2
125
Sum of Shrinking Function
n
f(i) 1/i
?i1..n f(i) ?
126
Harmonic Sum
127
Harmonic Sum
?i1..n 1/i 1/1 1/2 1/3 1/4 1/5
1/n Q(log(n))
128
Approximating Sum by Integrating
?i1..n f(i) ?x1..n f(x) dx
The area under the curve approximates the sum
129
Adding Made Easy
(For , -, , ? , exp, log functions f(n))
130
Adding Made Easy
131
Adding Made Easy
  • Geometric Like If f(n) ³ 2O(n), then
    ?i1..n f(i) ?(f(n)).
  • Arithmetic Like If f(n) n?(1)-1, then
    ?i1..n f(i) ?(n f(n)).
  • Harmonic If f(n) 1/n , then
    ?i1..n f(i) logen ?(1).
  • Bounded Tail If f(n) n-1-O(1), then
    ?i1..n f(i) ?(1).
  • (For , -, , ? , exp, log functions f(n))

This may seem confusing, but it is really not. It
should help you compute most sums easily.
132
Recurrence Relations
  • T(1) 1
  • T(n) a T(n/b) f(n)

133
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • Recurrence relations
  • arise from the timing
  • of recursive programs.
  • Let T(n) be the of His
  • on an input of size n.

134
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • Given size 1,
  • the program outputs
  • T(1)1 His.

135
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • Given size n,
  • the stackframe outputs
  • f(n) His.

136
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • Recursing
  • on an instances of size n/b
  • generates T(n/b) His.

137
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • Recursing
  • a times
  • generates aT(n/b) His.

138
Recurrence Relations Time of Recursive Program
procedure Eg(In) n In if(n1)
then put Hi else
loop i1..f(n) put Hi
loop i1..a In/b
In cut in b pieces Eg(In/b)
  • For a total of
  • T(1) 1
  • T(n) aT(n/b) f(n)
  • His.

139
Evaluating T(n) aT(n/b)f(n)
Dominated by Top Level or Base Cases
140
Evaluating T(n) aT(n/b)f(n)
141
Merge Sort Sort
Time T(n)
2T(n/2) Q(n)
Q(n log(n))
Total work at any level Q(n)
levels Q(log(n))
142
Evaluating T(n) aT(n/b)f(n)
2T(n/2) Q(n)
2iQ(n/2i) Q(n)
All levels basically the same.
Total Work T(n) ?i0..h aif(n/bi)
Q(n) log(n)
143
Evaluating T(n) aT(n/b)f(n)
144
Logs
log 27

log 9
145
Logs
log? 27

log? 9
Which base?
146
Logs
log2 27
log2 c
logc 27
logc 27


log2 9
log2 c
logc 9
logc 9
It does not matter.
Which is easiest?
147
Logs
3
log3 27
log3 33


2
log3 9
log3 32
Please no calculators in exams.
148
Evaluating T(n) 4T(n/2) n3/log5n
149
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level?

150
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3/log5n
  • Time for base cases?

151
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3 /log5n
  • Time for base cases

log ?/log ?
log a/log b
?(n )
?(n )
152
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3 /log5n
  • Time for base cases

log 4/log 2
log a/log b
?(n ) ?
?(n )
153
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3/log5n
  • Time for base cases
  • Dominated? c ?

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
log a/log b ?
154
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3/log5n
  • Time for base cases
  • Dominated? c 3 gt 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
Hence, T(n) ?
155
Evaluating T(n) 4T(n/2) n3/log5n
  • Time for top level f(n) n3/log5n
  • Time for base cases
  • Dominated? c 3 gt 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
Hence, T(n) ?(top) ?(f(n)) ?(n3/log5n).
156
Evaluating T(n) 4T(n/2) 2n
bigger
  • Time for top level f(n) 2n
  • Time for base cases
  • Dominated? c ? gt 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
Hence, T(n) ?(top) ?(f(n)) ?(2n).
157
Evaluating T(n) 4T(n/2) n log5n
  • Time for top level f(n) n log5n
  • Time for base cases
  • Dominated? c ? 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
158
Evaluating T(n) 4T(n/2) log5n
  • Time for top level f(n) log5n
  • Time for base cases
  • Dominated? c ? 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
159
Evaluating T(n) 4T(n/2) n2
  • Time for top level f(n) n2
  • Time for base cases
  • Dominated? c ? 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
?(f(n) log(n) ) ?(n2 log(n)).
160
Evaluating T(n) 4T(n/2) n2 log5n
  • Time for top level f(n) n2 log5n
  • Time for base cases
  • Dominated? c 2 2 log a/log b

log 4/log 2
log a/log b
?(n ) ?(n2)
?(n )
?(f(n) log(n) ) ?(n2 log6(n)).
161
Evaluating T(n) aT(n/b)f(n)
162
Evaluating T(n) aT(n-b)f(n)
Work in Level
stack frames
Work in stack frame
Instance size
n
n-b
h ?
h n/b
base case 0 n-hb h n/b
163
Evaluating T(n) 1T(n-b)f(n)
Work in Level
stack frames
Work in stack frame
Instance size
h ?
?(f(n)) or ?(nf(n))
Total Work T(n) ?i0..h f(bi)
164
Evaluating T(n) aT(n/b)f(n)
165
End of second part of math review
More Math
  • Graphs Searching Algorithms
Write a Comment
User Comments (0)
About PowerShow.com