160 likes | 253 Views
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. 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
E N D
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=k0 (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)
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.
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.
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.
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. • Recursion tree • Master Theorems
If both algorithms can be used to solve a problem, which one is more efficient, in time?
Another Example • T(n)=Θ(1) =1for 1≤n ≤ 3 • T(n)=3T(n/4)+Θ (n2), for n4 • We make a simplifying assumption: n is a power of 4.
Without expansion: T(n) • First expansion Cn2 T(n/4) T(n/4) T(n/4) Second expansion C(n/4)2 C(n/4)2 C(n/4)2 …………………………………..T(n/16)………………………………. C(n/42)2
L0: Cn2 L1: 3C(n/4)2 L2: 32C(n/42)2 L3: 33C(n/43)2 ….. Lk: 3kC(n/4k)2 If (n/4k) = 1, k=log4n Total:
……. (what should we do to do to get the answer below) Ans: O(n2) , Can it be Θ(n2)?
Exercise • Use substitution method, and • Master method to verify the above result.
note Big-O concepts can’t be used within M.I. process. A physical function, (e.g. cn2) 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).