Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP2230 Tutorial 2. Mathematical Induction A tool for proving the truth of a statement for some integer “n”. “n” is usually a +ve integer from 1 to infinity.

Similar presentations


Presentation on theme: "COMP2230 Tutorial 2. Mathematical Induction A tool for proving the truth of a statement for some integer “n”. “n” is usually a +ve integer from 1 to infinity."— Presentation transcript:

1 COMP2230 Tutorial 2

2 Mathematical Induction A tool for proving the truth of a statement for some integer “n”. “n” is usually a +ve integer from 1 to infinity. Why using M.I.? Usual Procedure Prove the statement is true for n=k 0 (e.g. n=1, n=10,…) Assume it is true for n Prove it is true for (n+1) e.g. Prove 1+2+3+…..+ n =n(n+1)/2……………..eqn.1 n=1, l.h.s of eqn 1 = 1, r.h.s of eqn 1 = 1(1+1)/2=1. (i.e. eqn. 1 is true for n=1)

3 Mathenatical Induction II Assume eqn. 1. is true for n i.e. 1+2+…..+n = n(n+1)/2 For (n+1), l.h.s. = 1+2+….+n +(n+1) = n(n+1)/2 +(n+1) =(n+1)(n+2)/2 r.h.s = (n+1)(n+2)/2=l.h.s.

4 Mathematical Induction III How does M.I. work? We have proved: 1. The statement/equation is true for n=1 2. If it is true for n, then it is true for (n+1) The Equation 1+2+3+…….+n = n(n+1)/2 As The Equation is true for n=1, The Equation is true for n=2 As The Equation is true for n=2, The Equation is true for n=3 ………… The Equation is true for any +ve integer n.

5 Useful assumptions For simplifying analysis Do not affect the asymptotic results E.g (ceiling, flooring) Why ceiling and flooring? ceiling(2.3)=3, flooring(2.3)=2, round(2.3)=2. ceiling(2.7)=3, flooring(2.7)=2, round(2.7)=3. For asymptotic analysis, T(1) can be regarded as the smallest T(n). If there is a recurrence T(n)=2T(n/4)+n, then T(1), T(2), T(3) can be treated as the same constant.

6 Computing Complexity 1.Direct Counting. (for simple algorithms, non-recurrent algorithms) You can refer to Tutorial 1. 2.Subsitution method (for recurrent algorithms). Guess the form of the solution Use M.I. to prove your guess. 3.Recursion tree 4.Master Theorems

7

8 If both algorithms can be used to solve a problem, which one is more efficient, in time?

9 16

10

11 Another Example T(n)=Θ(1) =1for 1 ≤ n ≤ 3 T(n)=3T(  n/4  )+Θ (n 2 ), for n  4 We make a simplifying assumption: n is a power of 4.

12 Without expansion: T(n) First expansion Cn 2 T(n/4) Second expansionC(n/4) 2 …………………………………..T(n/16)………………………………. C(n/4 2 ) 2

13 L0: Cn 2 L1: 3C(n/4) 2 L2: 3 2 C(n/4 2 ) 2 L3: 3 3 C(n/4 3 ) 2 ….. Lk: 3 k C(n/4 k ) 2 If (n/4 k ) = 1, k=log 4 n Total:

14 Ans: O(n 2 ), Can it be Θ(n 2 )? ……. (what should we do to do to get the answer below)

15 Exercise Use substitution method, and Master method to verify the above result.

16 note Big-O concepts can’t be used within M.I. process. A physical function, (e.g. cn 2 ) which is a member of Big-O should be defined before M.I. At the end of M.I. if it comes up with T(n) ≤ guess(n) – (some +ve lower order terms), just ignore the lower order terms. If there is a +ve lower order term left during M.I., add a lower order term to the physical function, guess(n).


Download ppt "COMP2230 Tutorial 2. Mathematical Induction A tool for proving the truth of a statement for some integer “n”. “n” is usually a +ve integer from 1 to infinity."

Similar presentations


Ads by Google