CSC 320: Lecture 3

CSC 320: Proof of the Day
Definition:
for functions f and g which map
the natural numbers to real values, the function
f(n) is in O(g(n)) if there exists constants c  0
and no ≥ 0 such that for all
n ≥ n0,
f(n) ≤ c ۰g(n).
Use this definition to prove that
3 + 4 n + 5 n2 + 2 n3
is in O(n3).
1
You will learn a lot more if you try the problems and get them
wrong than if you do not try. Also, it helps me know where the
class is in terms of understanding.
2
Some office hours:
I will add some more after processing CSC
225 forms.
Please let me know by 11:30am (or on TWF,
tell me after class) that you would like to
see me at one of these times so I don’t
have to wait in my office on days that
nobody wants to see me.
TWF: 12:30-1:30
W: 1:30-2:10
MWR: 3:30-4:30
3
Natural Numbers
= { 0, 1, 2, 3, 4, … }
Inductive Definition:
[Basis] 0 is in the set
[Inductive step]:
If k is in
then k+1 is in
4
Last class, I asked you to prove this
statement
n
S(n): Σ i
i=1
=
n (n+1)/2.
What should you use for the basis?
Since the sum starts at 1, the case n=1 makes
more sense to me than n=0.
If you start at 2 instead, you miss the case n=1.
You only need one base case (we can check this
5
after writing the proof).
n
S(n): Σ i
i=1
=
n (n+1)/2.
Basis [n=1].
When n=1, the lefthand side gives:
1
Σ i
i=1
=
1. The formula on the righthand
side gives 1 (1+1)/2=1. Hence, the formula
6
is correct when n=1.
n
S(n): Σ i
=
i=1
n (n+1)/2.
Some problems I saw on your submissions:
1. Writing sums with nothing to sum over:
n
Σ = n(n+1)/2
i=1
7
n
Σ f(i)
i=1
Meaning of notation (translation to code):
sum= 0
for (i=1; i ≤ n; i++)
sum= sum + f(i)
The value of the expression is sum at the
termination of this loop.
8
2. Instead of writing:
n
S(n)= Σ i
i=1
=
n (n+1)/2
Some students wrote:
n
S(n)= Σ i
i=1
The red part here is a sum and not a
mathematical statement.
9
3. Instead of writing:
n
S(n) = Σ i
i=1
=
n (n+1)/2
Some students wrote:
n
n= Σ i
i=1
=
n (n+1)/2
The value of n does not equal the expression on
10
the righthand side.
Induction step:
To make your proof more elegant, stick to n as
the variable name (don’t use k).
Assume that S(n) is true:
n
S(n): Σ i
=
i=1
n (n+1)/2. We want to prove
n+1
S(n+1): Σ i
= (n+1)((n+1)+1)/2=
(n+1)(n+2)/2.
i=1
11
Separating the sum which is the left hand side of S(n+1)
into two parts gives:
n+1
Σ i =
i=1
n
Σ i + (n+1).
i=1
By the induction hypothesis, the red term above
is equal to n(n+1)/2. Therefore,
12
n+1
Σ i = n (n+1)/2 + (n+1).
i=1
After algebraic simplifications:
n (n+1)/2 + (n+1)
= (n2 + n + 2n +2)/2 = (n+1)(n+2)/2 as required.
13