relevant mathematics jeff edmonds york university cosc 3101 lecture skipped. lecture skipped. (done...
TRANSCRIPT
![Page 1: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/1.jpg)
Relevant Mathematics
Jeff Edmonds
York University COSC 3101
Lecture skipped.(Done when needed)
Logic QuantifiersThe Time Complexity of an AlgorithmClassifying FunctionsAdding Made EasyRecurrence RelationsIn More Details
![Page 2: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/2.jpg)
Some Math
Time Complexityt(n) = Q(n2)
Logic Quantifiers g "b Loves(b,g)"b g Loves(b,g)
In Iterative Algs (GCD)
See logic slides
![Page 3: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/3.jpg)
Some Math
Logs and Exps
2a × 2b = 2a+b
2log n = nYou are on your own.
Input Size
Tim
e
Classifying Functionsf(i) = nQ(n)
See logic slides
![Page 4: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/4.jpg)
Some Math
Recurrence RelationsT(n) = a T(n/b) + f(n)
Adding Made Easy∑i=1 f(i).
In Iterative Algs (Insertion Sort)
In Recursive Algs (Multiplying)
In Recursive Algs(Multiplying,
Towers of Hanoi,Merge Sort)
![Page 5: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/5.jpg)
The Time Complexity of an Algorithm
Specifies how the running time depends on the size of the input.
![Page 6: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/6.jpg)
Purpose?
![Page 7: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/7.jpg)
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.
![Page 8: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/8.jpg)
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 .
![Page 9: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/9.jpg)
Definition of Time?
![Page 10: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/10.jpg)
Definition of Time
• # of seconds (machine dependent). • # lines of code executed. • # of times a specific operation is performed
(e.g., addition).
Which?
![Page 11: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/11.jpg)
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.
![Page 12: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/12.jpg)
Size of Input Instance?
83920
![Page 13: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/13.jpg)
Size of Input Instance
• Size of paper
• # of bits• # of digits• Value
- n = 2 in2
- n = 17 bits
- n = 5 digits
- n = 83920
2’’
83920
5
1’’
Which are reasonable?
![Page 14: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/14.jpg)
Size of Input Instance
• Size of paper
• # of bits• # of digits• Value
- n = 2 in2
- n = 17 bits
- n = 5 digits
- n = 83920
• Intuitive
2’’
83920
5
1’’
![Page 15: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/15.jpg)
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
2’’
83920
5
1’’
![Page 16: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/16.jpg)
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
2’’
83920
5
1’’
![Page 17: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/17.jpg)
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
2’’
83920
5
1’’
![Page 18: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/18.jpg)
Two Example Algorithms
• Sum N array entries: A(1) + A(2) + A(3) + …
• Factor value N: Input N=5917 & Output N=97*61.
Algorithm N/2, N/3, N/4, …. ?
Time?
Time = N
Time = N
Is this reasonable?
No! One is considered fast and the other slow!
![Page 19: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/19.jpg)
Two Example Algorithms
• Sum N array entries: A(1) + A(2) + A(3) + …
• Factor value N: Input N=5917 & Output N=97*61.
Algorithm N/2, N/3, N/4, …. ?
Standard input size?
Time = N
Time = N
N = hard drive = 60G < 236
N = crypto key = 2100
![Page 20: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/20.jpg)
Two Example Algorithms
• Sum N array entries: A(1) + A(2) + A(3) + …
• Factor value N: Input N=5917 & Output N=97*61.
Algorithm N/2, N/3, N/4, …. ?
Size of Input Instance?
Time = N
Time = N
size n = N
size n = log N
![Page 21: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/21.jpg)
Two Example Algorithms
• Sum N array entries: A(1) + A(2) + A(3) + …
• Factor value N: Input N=5917 & Output N=97*61.
Algorithm N/2, N/3, N/4, …. ?
size n = N
size n = log N
Time as function of input size?
Time for you to solve problem instance as a function of
time for me to give you the problem instance.
= n
= 2n
Time = N
Time = N
![Page 22: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/22.jpg)
Two Example Algorithms
• Sum N array entries: A(1) + A(2) + A(3) + …
• Factor value N: Input N=5917 & Output N=97*61.
Algorithm N/2, N/3, N/4, …. ?
Linear vs Exponential Time!
size n = N
size n = log N
= n
= 2n
Time = N
Time = N
![Page 23: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/23.jpg)
Size of Input Instance?
14,23,25,30,31,52,62,79,88,98
![Page 24: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/24.jpg)
Size of Input Instance
• # of elements = n = 10 elements
14,23,25,30,31,52,62,79,88,98
10
![Page 25: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/25.jpg)
Size of Input Instance
• # of elements = n = 10 elements
14,23,25,30,31,52,62,79,88,98
10
Is this reasonable?
![Page 26: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/26.jpg)
Size of Input Instance
• # of elements = n = 10 elements Reasonable
14,23,25,30,31,52,62,79,88,98
10
If each element has size c
# of bits = c * # of elements
![Page 27: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/27.jpg)
Size of Input Instance
• # of elements = n = 10 elements Reasonable
14,23,25,30,31,52,62,79,88,98
10
If each element is in [1..n]
each element has size log n
# of bits = n log n ≈ n
~
![Page 28: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/28.jpg)
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 .
![Page 29: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/29.jpg)
Which Input of size n?
There are 2n inputs of size n.Which do we consider
for the time T(n)?
![Page 30: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/30.jpg)
Which Input of size n?
Typical Input
Average Case
Worst Case
![Page 31: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/31.jpg)
Which Input of size n?
Typical Input But what is typical?
Average Case For what distribution?
Worst Case •Time for all inputs is bound.•Easiest to compute
![Page 32: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/32.jpg)
What is the height of tallest person in the class?
Bigger than this?
Need to look at only one person
Need to look at every person
Smaller than this?
![Page 33: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/33.jpg)
Time Complexity of Algorithm
O(n2): Prove that for every input of size n, the algorithm takes no more than cn2 time.
Ω(n2): Find one input of size n, for which the algorithm takes at least this much time.
θ (n2): Do both.
The time complexity of an algorithm isthe largest time required on any input of size n.
![Page 34: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/34.jpg)
Time Complexity of Problem
O(n2): Provide an algorithm that solves the problem in no more than this time.
Ω(n2): Prove that no algorithm can solve it faster.θ (n2): Do both.
The time complexity of a problem is the time complexity of the fastest algorithm that solves the problem.
![Page 35: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/35.jpg)
Classifying Functions
T(n) 10 100 1,000 10,000
log n 3 6 9 13 amoeba
n1/2 3 10 31 100 bird
10 100 1,000 10,000 human
n log n 30 600 9,000 130,000 my father
n2 100 10,000 106 108 elephantn3 1,000 106 109 1012 dinosaur2n 1,024 1030 10300 103000 the universe
Note: The universe contains approximately 1050 particles.
n
![Page 36: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/36.jpg)
Classifying FunctionsFunctions
Poly L
ogarithmic
Polynom
ial
Exponential
Exp
Double E
xp
Constant
(log n)5 n5 25n5 2n5 25n
2<< << << << <<
(log n)θ(1) nθ(1) 2θ(n)θ(1) 2nθ(1) 2θ(n)
2
![Page 37: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/37.jpg)
Classifying Functions
Linear
Quadratic
Cubic
?
θ(n2)θ(n) θ(n3)
Polynomial = nθ(1)
θ(n4)
Others
θ(n3 log7(n))log(n) not absorbed
because not Mult-constant
![Page 38: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/38.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n3log(n)
We consider two (of many) levels in this hierarchy
Individuals
Ignore Mult-constant
Ignore Power-constant
![Page 39: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/39.jpg)
BigOh and Theta?
• 5n2 + 8n + 2log n = (n2)
Drop low-order terms.Drop multiplicative constant.
• 5n2 log n + 8n + 2log n = (n2 log n)
![Page 40: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/40.jpg)
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)
![Page 41: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/41.jpg)
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)
![Page 42: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/42.jpg)
Notations
Theta f(n) = θ(g(n)) f(n) ≈ c g(n)
BigOh f(n) = O(g(n)) f(n) ≤ c g(n)
Omega f(n) = Ω(g(n)) f(n) ≥ c g(n)
Little Oh f(n) = o(g(n)) f(n) << c g(n)
Little Omega f(n) = ω(g(n)) f(n) >> c g(n)
![Page 43: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/43.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 44: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/44.jpg)
Definition of Theta
f(n) is sandwiched between c1g(n) and c2g(n)
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 45: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/45.jpg)
Definition of Theta
f(n) is sandwiched between c1g(n) and c2g(n)
for some sufficiently small c1 (= 0.0001)
for some sufficiently large c2 (= 1000)
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 46: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/46.jpg)
Definition of Theta
For all sufficiently large n
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 47: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/47.jpg)
Definition of Theta
For all sufficiently large n
For some definition of “sufficiently large”
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 48: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/48.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
![Page 49: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/49.jpg)
Order of Quantifiers
No! It cannot be a different c1 and c2
for each n.
n n n c c c g n f n c g n0 0 1 2 1 2, , ( ) ( ) ( ), ,
f(n) = θ(g(n))
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
![Page 50: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/50.jpg)
Gauss ∑i=1..n i = 1 + 2 + 3 + . . . + n
= ?
Arithmetic Sum
![Page 51: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/51.jpg)
1 2 . . . . . . . . n
= number of white dots1 + 2 + 3 + . . . + n-1 + n = S
Adding Made Easy
![Page 52: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/52.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
1 2 . . . . . . . . n
= number of yellow dots
n . . . . . . . 2 1
= number of white dots
Adding Made Easy
![Page 53: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/53.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
= number of white dots
= number of yellow dots
n+1 n+1 n+1 n+1 n+1
n
n
n
n
n
n
= n(n+1) dots in the grid
2S dots
S = n (n+1)
2
Adding Made Easy
![Page 54: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/54.jpg)
Gauss ∑i=1..n i = 1 + 2 + 3 + . . . + n
= Q(# of terms · last term)
Arithmetic Sum
True when ever terms increase slowly
![Page 55: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/55.jpg)
∑i=0..n 2i = 1 + 2 + 4 + 8 +. . . + 2n
= ?
Geometric Sum
![Page 56: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/56.jpg)
Geometric Sum
![Page 57: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/57.jpg)
∑i=0..n 2i = 1 + 2 + 4 + 8 +. . . + 2n
= 2 · last term - 1
Geometric Sum
![Page 58: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/58.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= ?
Geometric Sum
![Page 59: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/59.jpg)
S
Sr r r r ... r r
S Sr 1 r
Sr 1
r 1
2 3 n n 1
n 1
n 1
=1 r r r ...2 3 rn+ + + + +
= + + + + +
- = -
=-
-
+
+
+
Geometric Sum
![Page 60: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/60.jpg)
∑i=0..n rir 1
r 1
n 1
=-
-
+
Geometric SumWhen r>1?
![Page 61: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/61.jpg)
∑i=0..n rir 1
r 1
n 1
=-
-
+
Geometric Sum
= θ(rn) Biggest TermWhen r>1
![Page 62: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/62.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= Q(biggest term)
Geometric Increasing
True when ever terms increase quickly
![Page 63: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/63.jpg)
∑i=0..n ri =
Geometric SumWhen r<1?
1 r
1 r
n 1+--
![Page 64: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/64.jpg)
∑i=0..n ri =
Geometric Sum
1 r
1 r
n 1+--
= θ(1)
When r<1
Biggest Term
![Page 65: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/65.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= Q(1)
Bounded Tail
True when ever terms decrease quickly
![Page 66: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/66.jpg)
∑i=1..n 1/i
= 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + …+ 1/n
= ?
Harmonic Sum
![Page 67: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/67.jpg)
f(i) = 1∑i=1..n f(i) = n
n
Sum of Shrinking Function
![Page 68: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/68.jpg)
f(i) = ?∑i=1..n f(i) = n1/2
n
Sum of Shrinking Function
![Page 69: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/69.jpg)
f(i) = 1/2i
∑i=1..n f(i) = 2
¥
Sum of Shrinking Function
![Page 70: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/70.jpg)
f(i) = 1/i∑i=1..n f(i) = ?
n
Sum of Shrinking Function
![Page 71: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/71.jpg)
Harmonic Sum
![Page 72: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/72.jpg)
∑i=1..n 1/i
= 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + …+ 1/n
= Q(log(n))
Harmonic Sum
![Page 73: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/73.jpg)
Approximating Sum by Integrating
The area under the curveapproximates the sum
∑i=1..n f(i) ≈ ∫x=1..n f(x) dx
![Page 74: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/74.jpg)
Adding Made Easy
(For +, -, ×, , exp, log functions f(n))
![Page 75: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/75.jpg)
Adding Made Easy
![Page 76: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/76.jpg)
• Geometric Like: If f(n) ³ 2Ω(n), then ∑i=1..n f(i) = θ(f(n)).
• Arithmetic Like: If f(n) = nθ(1)-1, then ∑i=1..n f(i) = θ(n · f(n)).
• Harmonic: If f(n) = 1/n , then ∑i=1..n f(i) = logen + θ(1).
• Bounded Tail: If f(n) £ n-1-Ω(1), then ∑i=1..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.
Adding Made Easy
![Page 77: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/77.jpg)
Recurrence Relations
T(1) = 1
T(n) = a T(n/b) + f(n)
![Page 78: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/78.jpg)
Recurrence Relations» Time of Recursive Program
With all this recursing and looping, how do we
determine the running time of this recursive
program?
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
Recurrence relations.
![Page 79: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/79.jpg)
Recurrence Relations» Time of Recursive Program
Let n be the “size” of our input.
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 80: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/80.jpg)
Recurrence Relations» Time of Recursive Program
Let T(n) be the # of “Hi”s printed by me
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 81: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/81.jpg)
Recurrence Relations» Time of Recursive Program
Let T(n) be the # of “Hi”s printed by me
And by all of my friends.
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 82: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/82.jpg)
If my input is sufficiently small
(according to my measure of size)
then I print (1) “Hi”s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 83: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/83.jpg)
I personally output f(n) “Hi”s,
i.e. top level stack frame.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 84: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/84.jpg)
I have a friendsi.e. recurse a times.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 85: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/85.jpg)
Let b be the factor by which I shrink the input
before giving it to a friend.
i.e. if my input has size n then my friends are of
size n/b.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 86: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/86.jpg)
By definition of T,the number of “Hi”s printed by one of my
friends and all of his friends is
T(n/b).
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 87: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/87.jpg)
Hence, the total number printed by me
and my a friends isT(n) = a T(n/b) + f(n)
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
T(1) = 1T(n) = a T(n/b) + f(n)
![Page 88: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/88.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
Work in Level
0 n f(n) 1 1 · f(n)
1 n/b f(n/b) a a · f(n/b)
2 n/b2 f(n/b2) a2 a2 · f(n/b2)
i n/bi f(n/bi) ai ai · f(n/bi)
h = log n/log b n/bh T(1) nlog a/log b n · T(1)
log a/log b
Dominated by Top Level or Base Cases
![Page 89: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/89.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
![Page 90: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/90.jpg)
Merge Sort SortTime: T(n) =
= Q(n log(n))2T(n/2) + Q(n)
Total work at any level
= Q(n)
# levels = Q(log(n))
![Page 91: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/91.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
Work in Level
0 n f(n) 1 1 · f(n)
1 n/b f(n/b) a a · f(n/b)
2 n/b2 f(n/b2) a2 a2 · f(n/b2)
i n/bi f(n/bi) ai ai · f(n/bi)
h = log n/log b n/bh T(1) nlog a/log b n · T(1)
log a/log b
Total Work T(n) = ∑i=0..h ai×f(n/bi)
2T(n/2) + Q(n)
2i·Q(n/2i) = Q(n)
= Q(n) · log(n)
All levels basically the same.
![Page 92: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/92.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
![Page 93: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/93.jpg)
Logs
log 27log 9
=
![Page 94: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/94.jpg)
Logs
log? 27log? 9
=
Which base?
![Page 95: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/95.jpg)
Logs
log2 27log2 9
=
It does not matter.
log2 clog2 c
· logc 27· logc 9
=logc 27logc 9
Which is easiest?
![Page 96: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/96.jpg)
Logs
log3 27log3 9
=log3 33
log3 32 =32
Please no calculators in exams.And I wont ask log 25
log 9
![Page 97: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/97.jpg)
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 98: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/98.jpg)
Time for top level?:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 99: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/99.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases?:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 100: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/100.jpg)
Time for top level: f(n) = n3 /log5n
Time for base cases:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n )
log ?/log ?
![Page 101: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/101.jpg)
Time for top level: f(n) = n3 /log5n
Time for base cases:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = ?
log 4/log 2
![Page 102: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/102.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = ?
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
log a/log b = ?
![Page 103: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/103.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = 3 > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
![Page 104: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/104.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = 3 > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = θ(top) = θ(f(n)) = θ(n3/log5n).
![Page 105: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/105.jpg)
Time for top level: f(n) = 2n
Time for base cases:
Dominated?: c = ? > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ 2n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = θ(top) = θ(f(n)) = θ(2n).
bigger
>big
The time is even more dominated by the top level of recursion
![Page 106: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/106.jpg)
Time for top level: f(n) = n log5n
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
1<
= θ(base cases) = θ(n ) = θ(n2).log a/log b
![Page 107: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/107.jpg)
Time for top level: f(n) = log5n
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
0<
= θ(base cases) = θ(n ) = θ(n2).log a/log b
![Page 108: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/108.jpg)
Time for top level: f(n) = n2
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
2=
= θ(f(n) log(n) ) = θ(n2 log(n)).
![Page 109: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/109.jpg)
Time for top level: f(n) = n2 log5n
Time for base cases:
Dominated?: c = 2 = 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2 log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
d = ?5 ?
Hence, T(n) = ?
> -1
= θ(f(n) log(n) ) = θ(n2 log6(n)).
![Page 110: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/110.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
![Page 111: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/111.jpg)
Evaluating: T(n) = aT(n-b)+f(n)
h = ? n-hb
n-ib
n-2b
n-b
T(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)n
Work in Level
# stack frames
Work
in stack
frame
Instance
size
a
ai
a2
a
1
n/b a · T(0)
ai · f(n-ib)
a2 · f(n-2b)
a · f(n-b)
1 · f(n)
n/b
|base case| = 0 = n-hb
h = n/b
h = n/b
i
2
1
0
Level
Likely dominated by base cases Exponential
![Page 112: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/112.jpg)
Evaluating: T(n) = 1T(n-b)+f(n)
h = ?
Work in Level
# stack frames
Work
in stack
frame
Instance
size
1
1
1
1
1
f(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)
n-b
n
n-hb
n-ib
n-2b
T(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)
h = n/b
i
2
1
0
Level
Total Work T(n) = ∑i=0..h f(b·i) = θ(f(n)) or θ(n·f(n))
![Page 113: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/113.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
![Page 114: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/114.jpg)
Relevant MathematicsIn more detail.
Jeff Edmonds
York University
COSC 3101Lecture skipped
Classifying FunctionsThe Time Complexity of an AlgorithmAdding Made EasyRecurrence Relations
![Page 115: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/115.jpg)
Assumed Knowledge
Read the section on • Existential and Universal Quantifiers,
• Logarithms and Exponentials
g "b Loves(b,g)"b g Loves(b,g)
![Page 116: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/116.jpg)
Start With Some Math
Input Size
Tim
eClassifying Functions
f(i) = nQ(n)
Recurrence Relations
T(n) = a T(n/b) + f(n)
Adding Made Easy∑i=1 f(i).
Time Complexityt(n) = Q(n2)
![Page 117: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/117.jpg)
Classifying Functions
Giving an idea of how fast a function grows without going into too much detail.
![Page 118: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/118.jpg)
Which are more alike?
![Page 119: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/119.jpg)
Which are more alike?
Mammals
![Page 120: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/120.jpg)
Which are more alike?
![Page 121: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/121.jpg)
Which are more alike?
Dogs
![Page 122: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/122.jpg)
Classifying Animals
Vertebrates
Birds
Mam
mals
Reptiles
Fish
Dogs
Giraffe
We consider two (of many) levels in this hierarchy
Class
Genus
Individuals
![Page 123: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/123.jpg)
Classifying Functions
T(n) 10 100 1,000 10,000
log n 3 6 9 13 amoeba
n1/2 3 10 31 100 bird
10 100 1,000 10,000 human
n log n 30 600 9,000 130,000 my father
n2 100 10,000 106 108 elephantn3 1,000 106 109 1012 dinosaur2n 1,024 1030 10300 103000 the universe
Note: The universe contains approximately 1050 particles.
n
![Page 124: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/124.jpg)
Which are more alike?
n1000 n2 2n
![Page 125: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/125.jpg)
Which are more alike?
Polynomials
n1000 n2 2n
![Page 126: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/126.jpg)
Which are more alike?
1000n2 3n2 2n3
Polynomials
![Page 127: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/127.jpg)
Which are more alike?
Quadratic
1000n2 3n2 2n3
Polynomials
![Page 128: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/128.jpg)
Classifying Functions?
Functions
![Page 129: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/129.jpg)
Classifying Functions
Functions
Poly L
ogarithmic
Polynom
ial
Exponential
Exp
Double E
xp
Constant
(log n)5 n5 25n5 2n5 25n
2
Others
2n log(n)
![Page 130: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/130.jpg)
Classifying Functions?
Polynomial
![Page 131: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/131.jpg)
Classifying Functions
Polynomial
Linear
Quadratic
Cubic
?
5n25n 5n3 5n4
Others
5n3 log7(n)
![Page 132: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/132.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n2 + n
We consider two (of many) levels in this hierarchy
Ignore Power-constant
Ignore Mult-constant
Individuals
![Page 133: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/133.jpg)
Logarithmic
• log10n = # digits to write n
• log2n = # bits to write n = 3.32 log10n
• log(n1000) = 1000 log(n)
Differ only by a multiplicative constant.
![Page 134: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/134.jpg)
Poly Logarithmic
(log n)5 = log5 n
![Page 135: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/135.jpg)
Logarithmic << Polynomial
For sufficiently large n
log1000 n << n0.001
![Page 136: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/136.jpg)
Linear << Quadratic
For sufficiently large n
10000 n << 0.0001 n2
![Page 137: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/137.jpg)
Polynomial << Exponential
For sufficiently large n
n1000 << 20.001 n
![Page 138: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/138.jpg)
Classifying Functions
Functions
Poly L
ogarithmic
Polynom
ial
Exponential
Exp
Double E
xp
Constant
(log n)5 n5 25n5 2n5 25n
2<< << << << <<
![Page 139: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/139.jpg)
Which Functions are Constant?
• 5• 1,000,000,000,000• 0.0000000000001• -5• 0• 8 + sin(n)
YesYesYes
No
YesYes
![Page 140: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/140.jpg)
Which Functions are “Constant”?
• 5• 1,000,000,000,000• 0.0000000000001• -5• 0• 8 + sin(n)
YesYesYesNo
NoYes
Lie in between
7
9
The running time of the algorithm is a “Constant” It does not depend significantly
on the size of the input.
Write θ(1).
![Page 141: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/141.jpg)
Which Functions are Quadratic?
• n2
• … ?
![Page 142: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/142.jpg)
Which Functions are Quadratic?
• n2
• 0.001 n2
• 1000 n2
Some constant times n2.
![Page 143: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/143.jpg)
Which Functions are Quadratic?
• n2
• 0.001 n2
• 1000 n2
• 5n2 + 3000n + 2log n
![Page 144: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/144.jpg)
Which Functions are Quadratic?
• n2
• 0.001 n2
• 1000 n2
• 5n2 + 3000n + 2log n
Lie in between
![Page 145: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/145.jpg)
Which Functions are Quadratic?
• n2
• 0.001 n2
• 1000 n2
• 5n2 + 3000n + 2log n
Ignore multiplicative constant.Low-order terms absorbed into constant.
Ignore "small" values of n. Write θ(n2).
![Page 146: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/146.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n2 + n
We consider two (of many) levels in this hierarchy
Ignore Mult-constant
Individuals
Ignore Power-constant
![Page 147: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/147.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n2 + n
We consider two (of many) levels in this hierarchy
Ignore Mult-constant
Individuals
Ignore Power-constant
log(n) not absorbedbecause not
Mult-constant
![Page 148: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/148.jpg)
Which Functions are Polynomial?
• n5
• … ?
![Page 149: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/149.jpg)
Which Functions are Polynomial?
• nc
• n0.0001
• n10000
n to some constant power.
![Page 150: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/150.jpg)
Which Functions are Polynomial?
• nc
• n0.0001
• n10000
• 5n2 + 8n + 2log n • 5n2 log n • 5n2.5
![Page 151: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/151.jpg)
Which Functions are Polynomial?
• nc
• n0.0001
• n10000
• 5n2 + 8n + 2log n • 5n2 log n • 5n2.5
Lie in between
![Page 152: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/152.jpg)
Which Functions are Polynomials?• nc
• n0.0001
• n10000
• 5n2 + 8n + 2log n • 5n2 log n • 5n2.5
Ignore power constant. Low-order terms and log factors
absorbed into constant.Write nθ(1)
![Page 153: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/153.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n2 + n
We consider two (of many) levels in this hierarchy
Ignore Mult-constant
Individuals
Ignore Power-constant
![Page 154: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/154.jpg)
If f(n) = c ban nd loge (n)c Î ?a Î ?b Î ?d Î ?e Î ?
> 0= 0
or b = 1> 0
(-¥,¥)
Which Functions are Polynomials?
then f(n) Î nθ(1)
![Page 155: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/155.jpg)
Which Functions are Exponential?
• 2n
• … ?
![Page 156: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/156.jpg)
Which Functions are Exponential?
• 2n
• 20.0001 n
• 210000 n
2 raised to the power ofn times some constant power
![Page 157: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/157.jpg)
Which Functions are Exponential?
• 2n
• 20.0001 n
• 210000 n
• 8n
• 2n / n100 • 2n · n100
too small?too big?
![Page 158: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/158.jpg)
Which Functions are Exponential?
• 2n
• 20.0001 n
• 210000 n
• 8n
• 2n / n100 • 2n · n100
= 23n
> 20.5n
< 22n
Lie in between
![Page 159: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/159.jpg)
Which Functions are Exponential?
• 2n
• 20.0001 n
• 210000 n
• 8n
• 2n / n100 • 2n · n100
= 23n
> 20.5n
< 22n
20.5n > n100
2n = 20.5n · 20.5n > n100 · 20.5n
2n / n100 > n0.5n
![Page 160: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/160.jpg)
Which Functions are Exponential?
Ignore power constant. Low-order terms, change in base,
and polynomial factors absorbed into constant.
Write 2θ(n)
• 2n
• 20.0001 n
• 210000 n
• 8n
• 2n / n100 • 2n · n100
![Page 161: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/161.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
8·n2
θ(n2) θ(n3 log(n))
7·n2 + n
We consider two (of many) levels in this hierarchy
Ignore Mult-constant
Individuals
Ignore Power-constant
![Page 162: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/162.jpg)
If f(n) = c ban nd loge (n)c Î ?a Î ?b Î ?d Î ?e Î ?
then f(n) Î 2θ(n)
> 0> 0> 1
(-¥,¥)(-¥,¥)
Which Functions are Exponential?
![Page 163: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/163.jpg)
Classifying Functions
Functions
Poly L
ogarithmic
Polynom
ial
Exponential
Exp
Double E
xp
Constant
(log n)θ(1) nθ(1) 2θ(n)θ(1) 2nθ(1) 2θ(n)
2
Ignore Power-constant
![Page 164: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/164.jpg)
Classifying Functions
Linear
Quadratic
Cubic
?
θ(n2)θ(n) θ(n3)
Polynomial = nθ(1)
θ(n4)
Others
θ(n3 log7(n))
Ignore Mult-constant
![Page 165: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/165.jpg)
Exponential
2n vs 8n
Should these be classified together?
8n = 4n · 2n >> 1,000,000 · 2n
8n = 2log(8) · n = 23n
No: 8n ¹ Q(2n)
Yes: 8n = 2Q(n)
Ignore Power-constant
Ignore Mult-constant
![Page 166: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/166.jpg)
Classifying Functions
Rank constants in significance.
f(n) = 8·24n / n100 + 5·n3
Tell me the most significant thing
about your function
![Page 167: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/167.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
f(n) = 9·24n / n100 + 5·n3
vs
additive: multiplicative: 9/8
24n / n100
Rank constants in significance.
![Page 168: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/168.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
f(n) = 8·24n / n100 + 6·n3
vs
≈ 1n3
Rank constants in significance.
additive: multiplicative:
![Page 169: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/169.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
f(n) = 8·24n / n100 + 5·n4
vs
≈ 1≈ 5· n4
Rank constants in significance.
additive: multiplicative:
![Page 170: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/170.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
f(n) = 8·25n / n100 + 5·n3
vs
multiplicative: 2n
Rank constants in significance.
![Page 171: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/171.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
f(n) = 8·24n / n101 + 5·n3
vs
multiplicative: n
Rank constants in significance.
![Page 172: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/172.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
Rank constants in significance.
1 231’ 45
![Page 173: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/173.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
Rank constants in significance.
Significant Less significant
Irrelevant
![Page 174: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/174.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
Tell me the most significant thing
about your function
2θ(n)
23n < < 24nf(n)because
![Page 175: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/175.jpg)
Classifying Functions
f(n) = 8·24n / n100 + 5·n3
Tell me the most significant thing
about your function
2θ(n)
24n/nθ(1)
θ(24n/n100)
8·24n / n100 + θ(n3)8·24n / n100 + nθ(1)
8·24n / n100 + 5·n3
![Page 176: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/176.jpg)
Classifying Functions
Functions
Poly.
Exp.
8·24n / n100 + n3,
θ(24n / n100)
8·24n + n3
nθ(1) 2θ(n)
θ(24n)
Ignore Mult-constant
Individuals
Ignore Power-constant
![Page 177: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/177.jpg)
Notations
Theta f(n) = θ(g(n)) f(n) ≈ c g(n)
BigOh f(n) = O(g(n)) f(n) ≤ c g(n)
Omega f(n) = Ω(g(n)) f(n) ≥ c g(n)
Little Oh f(n) = o(g(n)) f(n) << c g(n)
Little Omega f(n) = ω(g(n)) f(n) >> c g(n)
![Page 178: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/178.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 179: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/179.jpg)
Definition of Theta
f(n) is sandwiched between c1g(n) and c2g(n)
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 180: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/180.jpg)
Definition of Theta
f(n) is sandwiched between c1g(n) and c2g(n)
for some sufficiently small c1 (= 0.0001)
for some sufficiently large c2 (= 1000)
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 181: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/181.jpg)
Definition of Theta
For all sufficiently large n
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 182: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/182.jpg)
Definition of Theta
For all sufficiently large n
For some definition of “sufficiently large”
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
f(n) = θ(g(n))
![Page 183: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/183.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
![Page 184: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/184.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
c1·n2 £ 3n2 + 7n + 8 £ c2·n2? ?
![Page 185: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/185.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n23 4
![Page 186: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/186.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·12 £ 3·12 + 7·1 + 8 £ 4·121False
![Page 187: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/187.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·72 £ 3·72 + 7·7 + 8 £ 4·727False
![Page 188: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/188.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·82 £ 3·82 + 7·8 + 8 £ 4·828True
![Page 189: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/189.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·92 £ 3·92 + 7·9 + 8 £ 4·929True
![Page 190: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/190.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·102 £ 3·102 + 7·10 + 8 £ 4·10210True
![Page 191: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/191.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n2?
![Page 192: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/192.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n2n ³ 88
![Page 193: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/193.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n2
Truen ³ 8
![Page 194: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/194.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n2
7n + 8 £ 1·n2
7 + 8/n £ 1·n
n ³ 8
True
![Page 195: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/195.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n2)
3·n2 £ 3n2 + 7n + 8 £ 4·n23 4 8 n ³ 8
True
![Page 196: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/196.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
n2 = θ(n3)
![Page 197: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/197.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
n2 = θ(n3)
c1 · n3 £ n2 £ c2 · n3? ?
![Page 198: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/198.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
n2 = θ(n3)
0 · n3 £ n2 £ c2 · n30True, but ?
![Page 199: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/199.jpg)
Definition of Theta
c c n n n1 0 2 0 0 0, , , , . . .
n2 = θ(n3)
0 Constants c1 and c2 must be positive!
False
![Page 200: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/200.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
![Page 201: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/201.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
c1·n £ 3n2 + 7n + 8 £ c2·n? ?
![Page 202: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/202.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·n £ 3n2 + 7n + 8 £ 100·n3 100
![Page 203: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/203.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·n £ 3n2 + 7n + 8 £ 100·n?
![Page 204: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/204.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·100 £ 3·1002 + 7·100 + 8 £ 100·100100
False
![Page 205: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/205.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·n £ 3n2 + 7n + 8 £ 10,000·n3 10,000
![Page 206: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/206.jpg)
Definition of Theta
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·10,000 £ 3·10,000 2 + 7·10,000 + 8 £ 10,000·10,00010,000
False
![Page 207: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/207.jpg)
Definition of Theta
3n2 + 7n + 8 = θ(n)
What is the reverse statement?
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
![Page 208: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/208.jpg)
Understand Quantifiers!!!
Sam Mary
Bob Beth
John Marilyn Monroe
Fred Ann
Sam Mary
Bob Beth
John Marilyn Monroe
Fred Ann
$ b, ØLoves(b, MM)
" b, Loves(b, MM)
[Ø $ b, ØLoves(b, MM)]
["Ø b, Loves(b, MM)]
![Page 209: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/209.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
The reverse statement
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
![Page 210: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/210.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3n2 + 7n + 8 > 100·n3 100 ?
![Page 211: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/211.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·1002 + 7·100 + 8 > 100·1003 100
True100
![Page 212: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/212.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3n2 + 7n + 8 > 10,000·n3 10,000 ?
![Page 213: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/213.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·10,0002 + 7·10,000 + 8 > 10,000·10,0003 10,000
True10,000
![Page 214: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/214.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3n2 + 7n + 8 > c2·nc1 c2 ?
![Page 215: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/215.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·c22 + 7 · c2 + 8 > c2·c2c1 c2
Truec2
![Page 216: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/216.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3n2 + 7n + 8 > c2·nc1 c2 ?n0
![Page 217: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/217.jpg)
Definition of Theta
c c n n n c g n f n o r f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( ) ( )
3n2 + 7n + 8 = θ(n)
3·c22 + 7 · c2 + 8 > c2·c2c1 max(c2,n0 )
Truec2 n0
True
![Page 218: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/218.jpg)
Definition of Theta
3n2 + 7n + 8 = g(n)θ(1)
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
3n2 + 7n + 8 = nθ(1)
![Page 219: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/219.jpg)
Definition of Theta
3n2 + 7n + 8 = nθ(1)
nc1 £ 3n2 + 7n + 8 £ nc2
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
? ?
![Page 220: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/220.jpg)
Definition of Theta
3n2 + 7n + 8 = nθ(1)
n2 £ 3n2 + 7n + 8 £ n3
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
2 3
![Page 221: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/221.jpg)
Definition of Theta
3n2 + 7n + 8 = nθ(1)
n2 £ 3n2 + 7n + 8 £ n3
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
2 3 ? n ³ ?
![Page 222: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/222.jpg)
Definition of Theta
3n2 + 7n + 8 = nθ(1)
n2 £ 3n2 + 7n + 8 £ n3
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
2 3 5 n ³ 5
![Page 223: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/223.jpg)
Definition of Theta
3n2 + 7n + 8 = nθ(1)
n2 £ 3n2 + 7n + 8 £ n3
True
True
$ c1, c2, n0, " n ³ n0 g(n)c1 £ f(n) £ g(n)c2
2 3 5 n ³ 5
![Page 224: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/224.jpg)
Order of Quantifiers
n n n c c c g n f n c g n0 0 1 2 1 2, , ( ) ( ) ( ), ,
f(n) = θ(g(n))
?
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
![Page 225: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/225.jpg)
g b lo ves b g, , ( , ) b g lo ves b g, , ( , )
Understand Quantifiers!!!
One girl Could be a separate girl for each boy.
Sam Mary
Bob Beth
John Marilyn Monroe
Fred Ann
Sam Mary
Bob Beth
John Marilyn Monroe
Fred Ann
![Page 226: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/226.jpg)
Order of Quantifiers
No! It cannot be a different c1 and c2
for each n.
n n n c c c g n f n c g n0 0 1 2 1 2, , ( ) ( ) ( ), ,
f(n) = θ(g(n))
c c n n n c g n f n c g n1 2 0 0 1 2, , , , ( ) ( ) ( )
![Page 227: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/227.jpg)
Other Notations
Theta f(n) = θ(g(n)) f(n) ≈ c g(n)
BigOh f(n) = O(g(n)) f(n) ≤ c g(n)
Omega f(n) = Ω(g(n)) f(n) ≥ c g(n)
Little Oh f(n) = o(g(n)) f(n) << c g(n)
Little Omega f(n) = ω(g(n)) f(n) >> c g(n)
![Page 228: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/228.jpg)
BigOh Notation
• n2 = O(n3)• n3 = O(n2)
![Page 229: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/229.jpg)
BigOh Notation
• O(n2) = O(n3)• O(n3) = O(n2)
Odd Notation
f(n) = O(g(n)) Standard f(n) ≤ O(g(n)) Stresses one function dominating another.
f(n)ÎO(g(n)) Stress function is member of class.
![Page 230: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/230.jpg)
Adding The Classic Techniques
Evaluating ∑i=1 f(i).n
![Page 231: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/231.jpg)
Gauss ∑i=1..n i = 1 + 2 + 3 + . . . + n
= ?
Arithmetic Sum
![Page 232: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/232.jpg)
1 + 2 + 3 + . . . + n-1
+ n = S
n + n-1 + n-2 + . . . + 2
+ 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) +
(n+1) = 2S
n (n+1) = 2S
![Page 233: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/233.jpg)
1 + 2 + 3 + . . . + n-1
+ n = S
n + n-1 + n-2 + . . . + 2
+ 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) +
(n+1) = 2S
n (n+1) = 2S
![Page 234: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/234.jpg)
1 + 2 + 3 + . . . + n-1
+ n = S
n + n-1 + n-2 + . . . + 2
+ 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) +
(n+1) = 2S
n (n+1) = 2S
![Page 235: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/235.jpg)
1 + 2 + 3 + . . . + n-1
+ n = S
n + n-1 + n-2 + . . . + 2
+ 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) +
(n+1) = 2S
n (n+1) = 2S 2
1)(n n S
![Page 236: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/236.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) + (n+1) = 2S
n (n+1) = 2S
Let’s restate this argument using a
geometric representation
Algebraic argument
![Page 237: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/237.jpg)
1 2 . . . . . . . . n
= number of white dots.1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) + (n+1) = 2S
n (n+1) = 2S
![Page 238: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/238.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) + (n+1) = 2S
n (n+1) = 2S
1 2 . . . . . . . . n
= number of white dots
= number of yellow dots
n . . . . . . . 2 1
![Page 239: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/239.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) + (n+1) = 2S
n (n+1) = 2S
n+1 n+1 n+1 n+1 n+1
= number of white dots
= number of yellow dots
n
n
n
n
n
n
There are n(n+1) dots in the grid
![Page 240: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/240.jpg)
1 + 2 + 3 + . . . + n-1 + n = S
n + n-1 + n-2 + . . . + 2 + 1 = S
(n+1) + (n+1) + (n+1) + . . . + (n+1) + (n+1) = 2S
n (n+1) = 2S
n+1 n+1 n+1 n+1 n+1
= number of white dots
= number of yellow dots
n
n
n
n
n
n
2
1)(n n S
Note = Q(# of terms · last term))
![Page 241: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/241.jpg)
Gauss ∑i=1..n i = 1 + 2 + 3 + . . . + n
= Q(# of terms · last term)
Arithmetic Sum
True when ever terms increase slowly
![Page 242: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/242.jpg)
∑i=0..n 2i = 1 + 2 + 4 + 8 +. . . + 2n
= ?
Geometric Sum
![Page 243: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/243.jpg)
Geometric Sum
![Page 244: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/244.jpg)
∑i=0..n 2i = 1 + 2 + 4 + 8 +. . . + 2n
= 2 · last term - 1
Geometric Sum
![Page 245: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/245.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= ?
Geometric Sum
![Page 246: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/246.jpg)
S
Sr r r r ... r r
S Sr 1 r
Sr 1
r 1
2 3 n n 1
n 1
n 1
=1 r r r ...2 3 rn+ + + + +
= + + + + +
- = -
=-
-
+
+
+
Geometric Sum
![Page 247: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/247.jpg)
∑i=0..n rir 1
r 1
n 1
=-
-
+
Geometric SumWhen r>1?
![Page 248: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/248.jpg)
∑i=0..n rir 1
r 1
n 1
=-
-
+
Geometric Sum
= θ(rn) Biggest TermWhen r>1
![Page 249: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/249.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= Q(biggest term)
Geometric Increasing
True when ever terms increase quickly
![Page 250: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/250.jpg)
∑i=0..n ri =
Geometric SumWhen r<1?
1 r
1 r
n 1+--
![Page 251: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/251.jpg)
∑i=0..n ri =
Geometric Sum
1 r
1 r
n 1+--
= θ(1)
When r<1
Biggest Term
![Page 252: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/252.jpg)
∑i=0..n ri = r0 + r1 + r2 +. . . + rn
= Q(1)
Bounded Tail
True when ever terms decrease quickly
![Page 253: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/253.jpg)
∑i=1..n 1/i
= 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + …+ 1/n
= ?
Harmonic Sum
![Page 254: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/254.jpg)
f(i) = 1∑i=1..n f(i) = n
n
Sum of Shrinking Function
![Page 255: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/255.jpg)
f(i) = ?∑i=1..n f(i) = n1/2
n
Sum of Shrinking Function
![Page 256: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/256.jpg)
f(i) = 1/2i
∑i=1..n f(i) = 2
¥
Sum of Shrinking Function
![Page 257: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/257.jpg)
f(i) = 1/i∑i=1..n f(i) = ?
n
Sum of Shrinking Function
![Page 258: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/258.jpg)
Harmonic Sum
![Page 259: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/259.jpg)
∑i=1..n 1/i
= 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + …+ 1/n
= Q(log(n))
Harmonic Sum
![Page 260: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/260.jpg)
Approximating Sum by Integrating
The area under the curveapproximates the sum
∑i=1..n f(i) ≈ ∫x=1..n f(x) dx
![Page 261: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/261.jpg)
Approximating Sum by Integrating
1/c+1 xc+1dd x = xc
∫x=1..n xc dx = 1/c+1 nc+1∑i=1..n ic ≈
Arithmetic Sums
= θ(# of terms · last term)True when ever terms increase slowly
= θ(n·nc)
![Page 262: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/262.jpg)
Approximating Sum by Integrating1/ln(b) eln(b)xdd x = eln(b)x = bx
∫x=1..n bx dx = 1/ln(b) bx∑i=1..n bi ≈
Geometric Sums
= θ(last term)True when ever terms increase quickly
= θ(bn)
![Page 263: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/263.jpg)
Harmonic Sum
Approximating Sum by Integrating
![Page 264: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/264.jpg)
Approximating Sum by Integrating
Problem: Integrating may be hard too.
![Page 265: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/265.jpg)
Outline
II) Math proofs of sums
V) Ability to know the answer fast
I) What is the sumEg. ∑i=1..n f(i) = ∑i=1..n 1/i
0.9999 =θ(n0.0001)
III) Pattern of sums ∑i=1..n f(i) = θ(n · f(n))
IV) Intuition why this is the sum
I flash it upIf you follow great.If not don’t panic.
![Page 266: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/266.jpg)
Adding Made Easy
We will now classify (most) functions f(i)
into four classes:
–Geometric Like–Arithmetic Like–Harmonic–Bounded Tail
![Page 267: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/267.jpg)
Adding Made Easy
We will now classify (most) functions f(i)
into four classes
For each class, we will give
an easy rule for approximating
it’s sum
θ( ∑i=1..n f(i) )
![Page 268: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/268.jpg)
Classifying Animals
Vertebrates
Birds
Mam
mals
Reptiles
Fish
Dogs
Giraffe
Mammal Þ Complex social networks Dog Þ Man’s best friend
![Page 269: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/269.jpg)
Classifying Functions
Functions
Poly.
Exp.
2θ(n) Þ ∑i=1..n f(i) = θ(f(n))
8·2n / n100 + n3,
θ(2n / n100)
8·2n + n3
nθ(1) 2θ(n)
θ(2n)
f(n) = 8·2n / n100 + n3
θ(2n / n100) Þ ∑i=1..n f(i) = θ(2n / n100)
20.5n < < 2n8· 2n / n100 + n3
Significant Less significant
Irrelevant
![Page 270: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/270.jpg)
Adding Made Easy
11
1
2
34
Four Classes of Functions
![Page 271: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/271.jpg)
Adding Made Easy
![Page 272: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/272.jpg)
If the terms f(i) grow sufficiently quickly, then the sum will be
dominated by the largest term.
Silly example:1+2+3+4+5+ 1,000,000,000 ≈ 1,000,000,000
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 273: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/273.jpg)
If the terms f(i) grow sufficiently quickly, then the sum will be
dominated by the largest term.
Classic example:
?
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 274: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/274.jpg)
If the terms f(i) grow sufficiently quickly, then the sum will be
dominated by the largest term.
Classic example:∑i=1..n 2i = 2n+1-1 ≈ 2 f(n)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 275: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/275.jpg)
If the terms f(i) grow sufficiently quickly, then the sum will be
dominated by the largest term.
For which functions f(i) is this true?
How fast and how slow can it grow?
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 276: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/276.jpg)
r 1r 1
n 1
= -
-
+
= θ( )r n Last Term
when r>1.
∑i=1..n ri 1 r r r . . .2 3 r n+ + + + +=
= θ(f(n))
∑i=1..n (1.0001)i ≈ 10,000 (1.0001)n
= 10,000 f(n)Lower Extreme:
Upper Extreme: ∑i=1..n (1000)i ≈ 1.001(1000)n
= 1.001 f(n)
Recall, when f(n) = ri = 2θ(n)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 277: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/277.jpg)
Because the constant is sooo big, the statement is just barely true.
∑i=1..n (1.0001)i ≈ 10,000 (1.0001)n
= 10,000 f(n)Lower Extreme:
Upper Extreme: ∑i=1..n (1000)i ≈ 1.001(1000)n
= 1.001 f(n)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 278: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/278.jpg)
∑i=1..n (1.0001)i ≈ 10,000 (1.0001)n
= 10,000 f(n)Lower Extreme:
Upper Extreme: ∑i=1..n (1000)i ≈ 1.001(1000)n
= 1.001 f(n)
Even bigger?
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 279: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/279.jpg)
2n2i
∑i=1..n 22 ≈ 22 = 1f(n)
No Upper Extreme:
Even bigger?
∑i=1..n (1.0001)i ≈ 10,000 (1.0001)n
= 10,000 f(n)Lower Extreme:
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 280: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/280.jpg)
2n2i
∑i=1..n 22 ≈ 22 = 1f(n)
No Upper Extreme:
Functions in between?
∑i=1..n (1.0001)i ≈ 10,000 (1.0001)n
= 10,000 f(n)Lower Extreme:
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 281: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/281.jpg)
∑i=1..n 2i
= 2·2n –2
= 21 + 22 + 23 + 24 +…+ 2n
8·[ ]
8· 8· 8· 8· 8·
8·
= θ( 2n )
1100 2100 3100 4100 n100
i100
n100
+ i3
+ 13 + 23 + 33 + 43 + n3
+ n4
Dominated by the largest term.
= θ(f(n))
f(n) = 2n8·n100
+ n3 = θ( 2n )n100
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
n100≈
![Page 282: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/282.jpg)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
f(n) = 2n8·n100
∑i=1..n f(i)f(n) £ £ c·f(n)f(i) £ ?·f(n) f(i) £ ?·f(i+1)
Easy Hard
³(1+1/i)100
12 1.9
=8·2(i+1)
(i+1)100f(i+1)f(i) 8·2i
i100
=
³ 1/.51
£ .51·f(i+1) f(i)
(i+1)100
i1002
=
![Page 283: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/283.jpg)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
f(n) = 2n8·n100
∑i=1..n f(i)f(n) £ £ c·f(n)f(i) £ ?·f(n)
£ .512·f(i+2)
£ .51·f(i+1) f(i)
£ .51·f(i+1) f(i) £ .513·f(i+3) ... £ .51(n-i)·f(i+(n-i)) = .51(n-i)·f(n)
f(i) £ .51(n-i)·f(n)
Eg. i = n, f(n) £ .51(n-n)·f(n) = 1·f(n)
i = 0, f(0) £ .51n·f(n)
![Page 284: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/284.jpg)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
f(n) = 2n8·n100
∑i=1..n f(i)f(n) £ £ c·f(n)
∑i=1..n f(i) £ ∑i=1..n .51(n-i)·f(n)
= θ(1) · f(n)
f(i) £ ?·f(n) £ .51·f(i+1) f(i)
f(i) £ .51(n-i)·f(n)
= [∑i=1..n .51(n-i)] · f(n)
![Page 285: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/285.jpg)
Functions
Poly.
Exp.
2θ(n) Þ ∑i=1..n f(i) = θ(f(n))
8·2n / n100 + n3
θ(2n / n100)
8·2n + n3
nθ(1) 2θ(n)
θ(2n)
f(n) = 8·2n / n100 + n3
θ(2n / n100) Þ ∑i=1..n f(i) = θ(2n / n100)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 286: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/286.jpg)
If f(n) = c ban nd loge (n)c Î ?a Î ?b Î ?d Î ?e Î ?
f(n) = Ω, θ ?
then ∑i=1..n f(i) = θ(f(n)).
³ 2Ω(n)
> 0> 0> 1
(-¥,¥)(-¥,¥)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 287: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/287.jpg)
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 288: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/288.jpg)
All functions in 2Ω(n)? Maybe not.
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 289: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/289.jpg)
Functions that oscillate continually do not have the property.
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 290: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/290.jpg)
Functions expressed with +, -, ×, , exp, log
do not oscillate continually.
They are well behaved for sufficiently large n.
These do have the property.
f(i) ³ 2Ω(n) Þ ∑i=1..n f(i) = θ(f(n))Geometric Like:
![Page 291: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/291.jpg)
Adding Made Easy
Done
![Page 292: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/292.jpg)
Adding Made Easy
![Page 293: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/293.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
Silly example:1,001 + 1,002 + 1,003 + 1,004 + 1,005
≈ 5 · 1,000
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 294: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/294.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
Another silly example:∑i=1..n 1 = n · 1
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 295: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/295.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
Is the statement true for this function?
∑i=1..n i = 1 + 2 + 3 + . . . + n
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 296: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/296.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
Is the statement true for this function?
∑i=1..n i = 1 + 2 + 3 + . . . + n
The terms are not roughly the same.
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 297: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/297.jpg)
But half the terms are roughly the same.
∑i=1..n i =
1 + . . . + n/2 + . . . + n
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 298: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/298.jpg)
But half the terms are roughly the same
and the sum is roughly the number
terms, n, times this value
∑i=1..n i =
1 + . . . + n/2 + . . . + n
∑i=1..n i = θ(n · n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 299: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/299.jpg)
Is the statement true for this function?
∑i=1..n i2 = 12 + 22 + 32 + . . . + n2
Even though, the terms are not roughly the same.
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 300: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/300.jpg)
Again half the terms are roughly the same.
∑i=1..n i =
12 + . . . + (n/2)2 + . . . + n2
1/4 n2
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 301: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/301.jpg)
Again half the terms are roughly the same.
∑i=1..n i =
12 + . . . + (n/2)2 + . . . + n2
1/4 n2
∑i=1..n i2 = θ(n · n2)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 302: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/302.jpg)
∑i=1..n f(i) ≈ area under curve
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 303: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/303.jpg)
area of small square£ ∑i=1..n f(i)
≈ area under curve£ area of big square
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 304: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/304.jpg)
n/2 · f(n/2)
= area of small square£ ∑i=1..n f(i)
≈ area under curve£ area of big square
= n · f(n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 305: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/305.jpg)
θ(n · f(n)) = n/2 · f(n/2)
= area of small square£ ∑i=1..n f(i)
≈ area under curve£ area of big square
= n · f(n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 306: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/306.jpg)
θ(n · f(n)) = n/2 · f(n/2)
= area of small square£ ∑i=1..n f(i)
≈ area under curve£ area of big square
= n · f(n)
?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 307: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/307.jpg)
∑i=1..n i2 = 12 + 22 + 32 + . . . + n2
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = n2
f(n/2) = θ(f(n))
The key property is
= ?
![Page 308: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/308.jpg)
The key property is
f(n/2) = (n/2)2 = 1/4 n2 = θ(n2) = θ(f(n))
∑i=1..n i2 = 12 + 22 + 32 + . . . + n2
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = n2
Þ = θ(n·f(n)) = θ(n · n2)
![Page 309: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/309.jpg)
∑i=1..n f(i) = ?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = nθ(1)
![Page 310: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/310.jpg)
∑i=1..n ir = 1r + 2r + 3r + . . . + nr
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = nθ(1)
f(n/2) = θ(f(n))
The key property is
![Page 311: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/311.jpg)
The key property is
f(n/2) = (n/2)r = 1/2r nr = θ(nr) = θ(f(n))
∑i=1..n ir = 1r + 2r + 3r + . . . + nr
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
Þ = θ(n·f(n)) = θ(n · nr)
f(i) = nθ(1)
![Page 312: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/312.jpg)
∑i=1..n 2i = 21 + 22 + 23 + . . . + 2n
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = nθ(1)
f(n/2) = θ(f(n))
The key property is
![Page 313: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/313.jpg)
The key property is
∑i=1..n 2i = 21 + 22 + 23 + . . . + 2n
f(n/2) = 2(n/2) = θ(2n) = θ(f(n))
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
f(i) = nθ(1)
Þ = θ(n·f(n)) = θ(n · 2n)
![Page 314: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/314.jpg)
∑i=1..n 1 = n · 1 = n · f(n)
Middle Extreme:
Upper Extreme: ∑i=1..n i1000 = 1/1001 n1001
= 1/1001 n · f(n)
All functions in between.
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 315: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/315.jpg)
Adding Made Easy
Half done
![Page 316: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/316.jpg)
f(i) = 1∑i=1..n f(i) = n
n
Sum of Shrinking Function
![Page 317: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/317.jpg)
f(i) = ?∑i=1..n f(i) = n1/2
n
Sum of Shrinking Function
1/i1/2
![Page 318: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/318.jpg)
f(i) = 1/i∑i=1..n f(i) = log n
n
Sum of Shrinking Function
![Page 319: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/319.jpg)
f(i) = 1/2i
∑i=1..n f(i) = 2
Sum of Shrinking Function
¥
![Page 320: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/320.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
Does the statement hold for functions f(i) that shrink?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 321: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/321.jpg)
If most of the terms f(i) have roughly the same value, then the sum is roughly the
number of terms, n, times this value.
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
Does the statement hold for the Harmonic Sum?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 322: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/322.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i) = ?
θ(n · f(n))
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 323: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/323.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i)
θ(n · f(n))
= ∑i=1..n 1/i = ?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 324: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/324.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i)
θ(n · f(n))
= ∑i=1..n 1/i = θ(log n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 325: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/325.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i = θ(log n)
?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 326: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/326.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i = θ(log n)
θ(1) = θ(n · 1/n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 327: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/327.jpg)
Does the statement hold for the Harmonic Sum?
∑i=1..n 1/i = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i = θ(log n)
θ(1) = θ(n · 1/n)≠
No the statement does not hold!
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 328: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/328.jpg)
Adding Made Easy
not included
![Page 329: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/329.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
Shrinks slightly slower than harmonic.
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 330: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/330.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i0.9999
= ?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 331: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/331.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i0.9999
= θ(n0.0001)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 332: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/332.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i0.9999
= θ(n0.0001)
?
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 333: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/333.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i0.9999
= θ(n0.0001)
θ(n0.0001) = θ(n · 1/n0.9999)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 334: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/334.jpg)
Does the statement hold for the almost Harmonic Sum?
∑i=1..n 1/i0.9999
∑i=1..n f(i)
= θ(n · f(n))
= ∑i=1..n 1/i0.9999
= θ(n0.0001)
θ(n0.0001) = θ(n · 1/n0.9999)
=
The statement does hold!
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 335: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/335.jpg)
∑i=1..n 1 = n · 1 = n · f(n)
Middle Extreme:
Lower Extreme: ∑i=1..n 1/i0.9999
= θ(n0.0001) = θ(n · f(n))
All functions in between.
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 336: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/336.jpg)
∑i=1..n 1 = n · 1 = n · f(n)
Middle Extreme:
Lower Extreme: ∑i=1..n 1/i0.9999
= θ(n0.0001) = θ(n · f(n))
Upper Extreme: ∑i=1..n i1000 = 1/1001 n1001
= 1/1001 n · f(n)
f(i) = nθ(1)-1 Þ ∑i=1..n f(i) = θ(n·f(n))Arithmetic Like:
![Page 337: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/337.jpg)
Arithmetic Like
If f(n) = c ban nd loge (n)c Î ?a Î ?b Î ?d Î ?e Î ?
f(n) = Ω, θ ?
then ∑i=1..n f(i) = θ(n · f(n)).
n-1+θ(1)
> 0= 0
or b = 1> -1
(-¥,¥)
(For +, -, ×, , exp, log functions f(n))
Conclusion
![Page 338: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/338.jpg)
Adding Made Easy
Done
![Page 339: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/339.jpg)
Adding Made Easy
Harmonic
![Page 340: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/340.jpg)
Harmonic Sum
∑i=1..n 1/i
= 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + …+ 1/n
= Q(log(n))
![Page 341: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/341.jpg)
Adding Made Easy
![Page 342: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/342.jpg)
If the terms f(i) decrease towards zerosufficiently quickly,
then the sum will be a constant.
The classic example ∑i=0..n 1/2i = 1 + 1/2 + 1/4 + 1/8 + … = 2.
f(n) £ n-1-Ω(1) Þ ∑i=1..n f(i) = θ(1)Bounded Tail:
![Page 343: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/343.jpg)
If f(i) decays even faster, then the tail of the sum is more bounded.
2i
∑i=1..n 22 = θ(1).
1
f(n) £ n-1-Ω(1) Þ ∑i=1..n f(i) = θ(1)Bounded Tail:
![Page 344: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/344.jpg)
Upper Extreme: ∑i=1..n 1/i1.0001
= θ(1)
f(n) £ n-1-Ω(1) Þ ∑i=1..n f(i) = θ(1)Bounded Tail:
![Page 345: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/345.jpg)
Upper Extreme: ∑i=1..n 1/i1.0001
= θ(1)
No Lower Extreme:2i
∑i=1..n 22 = θ(1).
1
All functions in between.
f(n) £ n-1-Ω(1) Þ ∑i=1..n f(i) = θ(1)Bounded Tail:
![Page 346: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/346.jpg)
Bounded Tail
If f(n) = c ban nd loge (n)c Î ?a Î ?b Î ?d Î ?e Î ?
f(n) = Ω, θ ?
then ∑i=1..n f(i) = θ(1).
> 0< 0
(-¥,¥)
(-¥,¥)
Conclusion
or b < 1
c nd loge (n)
c > 0a > 0 b > 1
ban
![Page 347: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/347.jpg)
Bounded Tail
If f(n) = c nd loge (n)c Î ?
a = 0b = 1d Î ?e Î ?
f(n) = Ω, θ ?
then ∑i=1..n f(i) = θ(1).
= n-1-Ω(1)
> 0
< -1(-¥,¥)
Conclusion
![Page 348: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/348.jpg)
Adding Made Easy
Done
![Page 349: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/349.jpg)
Adding Made EasyMissing Functions
n n
n nlo g
1/nlogn
logn/n
![Page 350: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/350.jpg)
Adding Made Easy • Geometric Like: If f(n) ³ 2Ω(n), then ∑i=1..n f(i) = θ(f(n)).
• Arithmetic Like: If f(n) = nθ(1)-1, then ∑i=1..n f(i) = θ(n · f(n)).
• Harmonic: If f(n) = 1/n , then ∑i=1..n f(i) = logen + θ(1).
• Bounded Tail: If f(n) £ n-1-Ω(1), then ∑i=1..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.
![Page 351: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/351.jpg)
Recurrence Relations
T(1) = 1
T(n) = a T(n/b) + f(n)
![Page 352: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/352.jpg)
Recurrence Relations» Time of Recursive Program
Recurrence relationsarise from the timing of recursive programs.
Let T(n) be the # of “Hi”s on an input of “size” n.
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
?
![Page 353: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/353.jpg)
Given size 1,the program outputs
T(1)=1 Hi’s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
![Page 354: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/354.jpg)
Given size n,the stackframe outputs
f(n) Hi’s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
![Page 355: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/355.jpg)
Recursing on an instances of size n/b
generates T(n/b) “Hi”s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
![Page 356: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/356.jpg)
Recursing a times
generates a·T(n/b) “Hi”s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
![Page 357: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/357.jpg)
For a total of T(1) = 1 T(n) = a·T(n/b) + f(n)
“Hi”s.
Recurrence Relations» Time of Recursive Program
procedure Eg(In) n = |In| if(n£1) then put “Hi” else loop i=1..f(n) put “Hi” loop i=1..a In/b = In cut in b pieces
Eg(In/b)
![Page 358: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/358.jpg)
Solving Technique 1Guess and Verify
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = 2n2 – n•Verify: Left Hand Side Right Hand Side
T(1) = 2(1)2 – 1
T(n)= 2n2 – n
1
4T(n/2) + n= 4 [2(n/2)2 – (n/2)] + n
= 2n2 – n
![Page 359: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/359.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = an2 + bn + c•Verify: Left Hand Side Right Hand Side
T(1) = a+b+c
T(n)= an2 +bn+c
1
4T(n/2) + n= 4 [a (n/2)2 + b (n/2) +c] + n
= an2 +(2b+1)n + 4c
Solving Technique 2Guess Form and Calculate Coefficients
![Page 360: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/360.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = an2 + bn + 0•Verify: Left Hand Side Right Hand Side
T(1) = a+b+c
T(n)= an2 +bn+c
1
4T(n/2) + n= 4 [a (n/2)2 + b (n/2) +c] + n
= an2 +(2b+1)n + 4c
Solving Technique 2Guess Form and Calculate Coefficients
c=4cc=0
![Page 361: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/361.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = an2 - 1n + 0•Verify: Left Hand Side Right Hand Side
T(1) = a+b+c
T(n)= an2 +bn+c
1
4T(n/2) + n= 4 [a (n/2)2 + b (n/2) +c] + n
= an2 +(2b+1)n + 4c
Solving Technique 2Guess Form and Calculate Coefficients
b=2b+1b=-1
![Page 362: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/362.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = an2 - 1n + 0•Verify: Left Hand Side Right Hand Side
T(1) = a+b+c
T(n)= an2 +bn+c
1
4T(n/2) + n= 4 [a (n/2)2 + b (n/2) +c] + n
= an2 +(2b+1)n + 4c
Solving Technique 2Guess Form and Calculate Coefficients
a=a
![Page 363: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/363.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2) + n•Guess: G(n) = 2n2 - 1n + 0•Verify: Left Hand Side Right Hand Side
T(1) = a+b+c
T(n)= an2 +bn+c
1
4T(n/2) + n= 4 [a (n/2)2 + b (n/2) +c] + n
= an2 +(2b+1)n + 4c
Solving Technique 2Guess Form and Calculate Coefficients
a+b+c=1a-1+0=1a=2
![Page 364: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/364.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = aT(n/b) + f(n)
Solving Technique 3Approximate Form and
Calculate Exponent
which is bigger?
Guess
![Page 365: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/365.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = aT(n/b) + f(n)•Guess: aT(n/b) << f(n)•Simplify: T(n) » f(n)
Solving Technique 3Calculate Exponent
In this case, the answer is easy. T(n) = Q(f(n))
![Page 366: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/366.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = aT(n/b) + f(n)•Guess: aT(n/b) >> f(n)•Simplify: T(n) » aT(n/b)
Solving Technique 3Calculate Exponent
In this case, the answer is harder.
![Page 367: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/367.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = aT(n/b)•Guess: G(n) = cna
•Verify: Left Hand Side Right Hand Side
T(n)= cna
aT(n/b) = a [c (n/b) a ]
= c a b-a na
Solving Technique 3Calculate Exponent
(log a/log b)= cn
1 = a b-a
ba = a a log b = log a
a = log a/log b
![Page 368: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/368.jpg)
•Recurrence Relation:
T(1) = 1 & T(n) = 4T(n/2)•Guess: G(n) = cna
•Verify: Left Hand Side Right Hand Side
T(n)= cna
aT(n/b) + f(n)= c [a (n/b) a ]
= c a b-a na
Solving Technique 3Calculate Exponent
1 = a b-a
ba = a a log b = log a
a = log a/log b
(log a/log b)= cn(log 4/log 2)= cn
2= cn
![Page 369: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/369.jpg)
Logs
log 27log 9
=
![Page 370: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/370.jpg)
Logs
log? 27log? 9
=
Which base?
![Page 371: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/371.jpg)
Logs
log2 27log2 9
=
It does not matter.
log2 clog2 c
· logc 27· logc 9
=logc 27logc 9
Which is easiest?
![Page 372: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/372.jpg)
Logs
log3 27log3 9
=log3 33
log3 32 =32
Please no calculators in exams.And I wont ask log 25
log 9
![Page 373: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/373.jpg)
•Recurrence Relation:
Solving Technique 3Calculate Exponent
If bigger then
T(n) = Q(f(n))
If bigger then(log a/log b)T(n) = Q(n )
And if aT(n/b) » f(n) what is T(n) then?
T(1) = 1 & T(n) = aT(n/b) + f(n)
![Page 374: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/374.jpg)
4: Decorate The Tree
• T(n) = a T(n/b) + f(n)
T(1) = 1 & T(n) = aT(n/b) + f(n)f(n)
T(n/b) T(n/b) T(n/b) T(n/b)
T(n) =
T(1)
•T(1) = 1
1=
a
![Page 375: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/375.jpg)
f(n)
T(n/b) T(n/b) T(n/b) T(n/b)
T(n) =a
![Page 376: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/376.jpg)
f(n)
T(n/b) T(n/b) T(n/b)
T(n) =a
f(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
a
![Page 377: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/377.jpg)
f(n)T(n) =a
f(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
a
![Page 378: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/378.jpg)
11111111111111111111111111111111 . . . . . . 111111111111111111111111111111111
f(n)T(n) =a
f(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
af(n/b)
T(n/b2)T(n/b2)T(n/ b2)T(n/ b2)
a
![Page 379: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/379.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
Level
0
1
2
i
h
![Page 380: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/380.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0
1
2
i
h
![Page 381: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/381.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1
2
i
h
![Page 382: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/382.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2
i
h
![Page 383: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/383.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i
h
![Page 384: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/384.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i n/bi
h n/bh
![Page 385: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/385.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i n/bi
h n/bh
![Page 386: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/386.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i n/bi
h n/bh = 1
base case
![Page 387: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/387.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i n/bi
h n/bh = 1
![Page 388: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/388.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
0 n
1 n/b
2 n/b2
i n/bi
h = log n/log b n/bh = 1
bh = nh log b = log nh = log n/log b
![Page 389: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/389.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
0 n
1 n/b
2 n/b2
i n/bi
h = log n/log b 1
![Page 390: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/390.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
0 n f(n)
1 n/b f(n/b)
2 n/b2 f(n/b2)
i n/bi f(n/bi)
h = log n/log b 1 T(1)
![Page 391: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/391.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
0 n f(n)
1 n/b f(n/b)
2 n/b2 f(n/b2)
i n/bi f(n/bi)
h = log n/log b n/bh T(1)
![Page 392: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/392.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
0 n f(n) 1
1 n/b f(n/b) a
2 n/b2 f(n/b2) a2
i n/bi f(n/bi) ai
h = log n/log b n/bh T(1) ah
![Page 393: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/393.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
0 n f(n) 1
1 n/b f(n/b) a
2 n/b2 f(n/b2) a2
i n/bi f(n/bi) ai
h = log n/log b n/bh T(1) ah
![Page 394: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/394.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
0 n f(n) 1
1 n/b f(n/b) a
2 n/b2 f(n/b2) a2
i n/bi f(n/bi) ai
h = log n/log b n/bh T(1) ah
ah = a
= n
log n/log b
log a/log b
![Page 395: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/395.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
Work in Level
0 n f(n) 1
1 n/b f(n/b) a
2 n/b2 f(n/b2) a2
i n/bi f(n/bi) ai
h = log n/log b n/bh T(1) nlog a/log b
![Page 396: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/396.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
Work in Level
0 n f(n) 1 1 · f(n)
1 n/b f(n/b) a a · f(n/b)
2 n/b2 f(n/b2) a2 a2 · f(n/b2)
i n/bi f(n/bi) ai ai · f(n/bi)
h = log n/log b n/bh T(1) nlog a/log b n · T(1)
log a/log b
Total Work T(n) = ∑i=0..h ai×f(n/bi)
![Page 397: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/397.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
= ∑i=0..h ai×f(n/bi)
If a Geometric Sum∑i=0..n xi = θ(max(first term, last term))
![Page 398: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/398.jpg)
Evaluating: T(n) = aT(n/b)+f(n)
LevelInstance
size
Workin stackframe
# stack frames
Work in Level
0 n f(n) 1 1 · f(n)
1 n/b f(n/b) a a · f(n/b)
2 n/b2 f(n/b2) a2 a2 · f(n/b2)
i n/bi f(n/bi) ai ai · f(n/bi)
h = log n/log b n/bh T(1) nlog a/log b n · T(1)
log a/log b
Dominated by Top Level or Base Cases
![Page 399: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/399.jpg)
Evaluating: T(n) = aT(n/b)+f(n)Is the sum Geometric?
Simplify by letting f(n) = nc logkn
T(n) = ∑i=0..h ai×f(n/bi)
= ∑i=0..h ai×(n/bi)c ×logk(n/bi)
= nc ∑i=0..h 2[log a - c log b] · i ×logk(n/bi)
Geometrically IncreasingArithmetic SumGeometrically Decreasing
Sum = θ(last term)
= θ( )Sum = θ(any term ×# terms)
= θ(f(n) × log n) Sum = θ(first term)
= θ(f(n)).
log a - c log b > 0log a - c log b = 0log a - c log b < 0
c < log a/log b
c = log a/log b & k<-1c = log a/log b & k>-1c > log a/log b
nlog a/log b
(n/..)c = ncai = 2[log a]·i(../bi)c = 2[-c log b]·i
= nc ∑i=0..h 2-d i ×logk(n/bi)
![Page 400: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/400.jpg)
Evaluating: T(n) = aT(n/b)+f(n)Is the sum Geometric?
Simplify by letting f(n) = nc logkn
T(n) = ∑i=0..h ai×f(n/bi)
= ∑i=0..h ai×(n/bi)c ×logk(n/bi)
= nc ∑i=0..h 2[log a - c log b] · i ×logk(n/bi)
Geometrically IncreasingArithmetic SumGeometrically Decreasing
Sum = θ(last term)
= θ( )Sum = θ(any term ×# terms)
= θ(f(n) × log n) Sum = θ(first term)
= θ(f(n)).
log a - c log b > 0log a - c log b = 0log a - c log b < 0
c < log a/log b
c = log a/log b & k<-1c = log a/log b & k>-1c > log a/log b
nlog a/log b
k=-1 Þ logk(n/bi) = 1/(logn - i × logb)
» 1/i (backwards)= nc ∑i=0..h 20 i ×logk(n/bi)
(back wards)
de
![Page 401: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/401.jpg)
Evaluating: T(n) = aT(n/b)+f(n)Is the sum Geometric?
Simplify by letting f(n) = nc logkn
T(n) = ∑i=0..h ai×f(n/bi)
= ∑i=0..h ai×(n/bi)c ×logk(n/bi)
= nc ∑i=0..h 2[log a - c log b] · i ×logk(n/bi)
Geometrically IncreasingArithmetic SumGeometrically Decreasing
Sum = θ(last term)
= θ( )Sum = θ(any term ×# terms)
= θ(f(n) × log n) Sum = θ(first term)
= θ(f(n)).
log a - c log b > 0log a - c log b = 0log a - c log b < 0
c < log a/log b
c = log a/log b & k<-1c = log a/log b & k>-1c > log a/log b
nlog a/log b
= nc ∑i=0..h 2+d i ×logk(n/bi)
![Page 402: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/402.jpg)
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 403: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/403.jpg)
Time for top level?:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 404: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/404.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases?:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
![Page 405: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/405.jpg)
Time for top level: f(n) = n3 /log5n
Time for base cases:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n )
log ?/log ?
![Page 406: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/406.jpg)
Time for top level: f(n) = n3 /log5n
Time for base cases:
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = ?
log 4/log 2
![Page 407: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/407.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = ?
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
log a/log b = ?
![Page 408: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/408.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = 3 > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
![Page 409: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/409.jpg)
Time for top level: f(n) = n3/log5n
Time for base cases:
Dominated?: c = 3 > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n3/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = θ(top) = θ(f(n)) = θ(n3/log5n).
![Page 410: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/410.jpg)
Time for top level: f(n) = 2n
Time for base cases:
Dominated?: c = ? > 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ 2n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = θ(top) = θ(f(n)) = θ(2n).
bigger
>big
The time is even more dominated by the top level of recursion
![Page 411: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/411.jpg)
Time for top level: f(n) = n log5n
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
1<
= θ(base cases) = θ(n ) = θ(n2).log a/log b
![Page 412: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/412.jpg)
Time for top level: f(n) = log5n
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
0<
= θ(base cases) = θ(n ) = θ(n2).log a/log b
![Page 413: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/413.jpg)
Time for top level: f(n) = n2
Time for base cases:
Dominated?: c = ? 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
Hence, T(n) = ?
2=
= θ(f(n) log(n) ) = θ(n2 log(n)).
![Page 414: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/414.jpg)
Time for top level: f(n) = n2 log5n
Time for base cases:
Dominated?: c = 2 = 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2 log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
d = ?5 ?
Hence, T(n) = ?
> -1
= θ(f(n) log(n) ) = θ(n2 log6(n)).
![Page 415: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/415.jpg)
Time for top level: f(n) = n2/log5n
Time for base cases:
Dominated?: c = 2 = 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2/log5n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
d = ?
Hence, T(n) = ?
-5 ?< -1
= θ(base cases) = θ(n ) = θ(n2).log a/log b
![Page 416: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/416.jpg)
Time for top level: f(n) = n2/log n
Time for base cases:
Dominated?: c = 2 = 2 = log a/log b
Evaluating: T(n) = 4T(n/2)+ n2/log n
θ(n ) =log a/log b θ(n ) = θ(n2)
log 4/log 2
d = ?
Hence, T(n) = ?
-1 ?= -1
= θ(nc loglog n) = θ(n2 loglog n).Did not do before.
![Page 417: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/417.jpg)
Sufficiently close to: T(n) = 4T(n/2)+ n3 = θ(n3). T2(n) = ?
Evaluating: T2(n) = 4 T2(n/2+n1/2)+ n3
θ(n3).
![Page 418: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/418.jpg)
Evaluating: T(n) = aT(n-b)+f(n)
h = ? n-hb
n-ib
n-2b
n-b
T(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)n
Work in Level
# stack frames
Work
in stack
frame
Instance
size
a
ai
a2
a
1
n/b a · T(0)
ai · f(n-ib)
a2 · f(n-2b)
a · f(n-b)
1 · f(n)
n/b
|base case| = 0 = n-hb
h = n/b
h = n/b
i
2
1
0
Level
Likely dominated by base cases Exponential
![Page 419: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/419.jpg)
Evaluating: T(n) = 1T(n-b)+f(n)
h = ?
Work in Level
# stack frames
Work
in stack
frame
Instance
size
1
1
1
1
1
f(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)
n-b
n
n-hb
n-ib
n-2b
T(0)
f(n-ib)
f(n-2b)
f(n-b)
f(n)
h = n/b
i
2
1
0
Level
Total Work T(n) = ∑i=0..h f(b·i) = θ(f(n)) or θ(n·f(n))
![Page 420: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/420.jpg)
End
Restart Relevant Mathematics
Iterative Algorithms
![Page 421: Relevant Mathematics Jeff Edmonds York University COSC 3101 Lecture skipped. Lecture skipped. (Done when needed) Logic Quantifiers The Time Complexity](https://reader038.vdocuments.us/reader038/viewer/2022110100/56649e045503460f94af0994/html5/thumbnails/421.jpg)
End of math review
More Math