Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Petra University Faculty of Information Technology Design and Analysis of Algorithms Chapter 2 Mathematical Background Dr. Ahmad M. Awwad Page 1 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Summations ο· When an algorithm contains an iterative control construct such as a while or for loop, its running time can be expressed as the sum of the times spent on each execution of the body of the loop. By adding up the time spent on each iteration, we obtain the summation formula (or series) ο· Given a sequence a1, a2, ... , an of numbers, the finite sum a1 + a2 + ··· + an, where n is an nonnegative integer, can be written If n = 0, the value of the summation is defined to be 0. Example: βππ π=π ππ = π + π + π + ππ = ππ ο· For any real number c and any finite sequences a1, a2, ..., an and b1, b2, ..., bn, Example: π π β10 π=7(πππ+ ππ ) = π βπ=1 ππ + βπ=1 ππ = 2(7 + 8 + 9 + 10) + (7 + 8 + 9 + 10) = 2(34) + 34 = 102 The summation is an arithmetic series and has the value Example: Sum of numbers 1 to 5; =βππ=π π + π + π + π + π = ππ = Page 2 π(π+π) π = ππ February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Sums of squares and cubes We have the following summations of squares and cubes: Example:n =5 02 + 12 + 22 + 32 + 42 + 52 = 55 = 5(5+1)(2β5+1) 6 = 30 β 11 6 = 330 6 = 55 Example:n =3 03 + 13 + 23 + 33 = 36 = 32 (3+1)2 4 =36 Geometric series For real x β 1, the summation is a geometric or exponential series and has the value Example:Type equation here. 20 + 21 + 22 + 23 = 15 π = 3; π₯ = 2 = 23+1 β1 2β1 = 24 β1 1 = 15 Harmonic series: For positive integerβs n, the nth harmonic number is Page 3 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Example:π π = 5; π π π π π +π+π+π+π= ππ+ππ+ππ+ππ+ππ ππ = πππ ππ Splitting summations One way to obtain bounds on a difficult summation is to express the series as the sum of two or more series by partitioning the range of the index and then to bound each of the resulting series. Example:=1+2+3 + 4 + 5 + 6 = 21 Summary Important Summation Formulas 1. u n i ο½l i ο½1 ο₯ 1 ο½ 1 ο« 1 ο« ... ο« 1 ο½ u ο l ο« 1(l , u are integer limits, l ο£ u ); ο₯ n Example:- β8π=π=5 1 = 8 β 5 + 1 = 4 n 2. ο₯ i ο½ 1 ο« 2 ο« ... ο« n ο½ i ο½1 Example:n 3. ο₯i 2 5(5+1) 2 = 15 ο½ 12 ο« 2 2 ο« ... ο« n 2 ο½ i ο½1 Example:n 4. ο₯i k n(n ο« 1) 2 5(5+1)(2β5+1) 6 n(n ο« 1)( 2n ο« 1) 6 = 30 β 11 6 = 330 6 = 55 ο½ 1k ο« 2 k ο« ... ο« n k i ο½1 Example:- 13 + 23 + 33 = 36 Page 4 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad n 5. ο₯ ai ο½ 1 ο« a ο« ... ο« a n ο½ i ο½0 n a nο«1 ο 1 (a οΉ 1); ο₯ 2i ο½ (2nο«1 ο 1) /( 2 ο 1) ο½ 2nο«1 ο 1 a ο1 i ο½0 Example:- a = 3; n = 4 30 + 31 + 32 + 33 + 34 = 1 + 3 + 9 + 27 + 81 = 121 = 34+1 β1 3β1 n 6. ο₯ i2 i = 243β1 2 = 121 ο½ 1 οͺ 2 ο« 2 οͺ 2 2 ο« ... ο« n 2 n ο½ (n ο 1)2 n ο«1 ο« 2 i ο½1 Example:n=3; 1 β 21 + 2 β 22 + 3 β 23 = 2 + 8 + 24 = 34 = (3 β 1) β 23+1 + 2=34 n 7. 1 1 1 ο₯ i ο½ 1 ο« 2 ο« ... ο« n ο» ln n ο« y, where y ο» 0.5772... (Euler's constant) i ο½1 n 8. ο₯ lg i ο» n lg n i ο½1 Example: n= 10; log1+ log2+β¦.. log10 ο» 10 n =10; 10*log10 = 10*1=10 ο· Examples on sum Manipulation Rules 1. u u i ο½1 i ο½l ο½1 ο₯ cai ο½ c ο₯ ai Example:- a =5; u =3; c =4 3 3 β 4 β 5π = 4 β 5 + 4 β 5 + 4 β 5 = 60 = 4 β 5π = 4(5 + 5 + 5) = 60 π=1 2. π=1 u u u i ο½l i ο½l i ο½l ο₯ (ai ο± bi ) ο½ ο₯ ai ο± ο₯ bi Page 5 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Example: β3π=1(4 + 5)π = 9 + 9 + 9 = 27 u =3; a =4; b =5 = β3π=1 4π + β3π=1 5π = 12 + 15=27 3. u m i ο½l i ο½l ο₯ ai ο½ ο₯ ai ο« u ο₯ a , where l ο£ m < u i ο½ m ο«1 i Example:- i =2; m =4; u =6; a =3 β6π=2 3π = β4π=2 3π + β6π=5 3π = 3 + 3 + 3 + 3 + 3=15 Properties of logarithms ο· All logarithms bases are assumed to be greater than 1 in the formulas below; lg x denotes the logarithm base 2, lnx denotes the logarithm base e=2.71828β¦; x and y are arbitrary positive numbers. ο· In the examples below it is assumed that the base = a =10 1- log a 1 ο½ 0 βLogarithm 1 to the base 10β 2- log a a ο½ 1 βLogarithm 10 to the base 10 is 1β 3- log a x ο½ y log a x y base = a = 10; x = 5; y = 3 4- log1053= log10125=2.09691 a. 3*log105 =3*0.69897 = 2.09691 5- log a xy ο½ log a x ο« log a y a = 10; x = 5; y = 8 log10 5 β 8 = log10 5 + log10 8 = 0.69897 + 0.903089 = 1.60206 Page 6 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad log10 8 β 5 = log10 40 = 1.60206 6- log a x ο½ log a x ο log a y y X=10; y=2; log10 log b ο½ x log b x 7- a 10 = 0.69897ο log10 10 β log10 2 = 1 β 0.30103 = 0.69897 2 a Example: a = 5; b =10; x = 3 5log10 3 = 50.47712 = 2.15522 β‘ 3log10 5 = 30.69890 = 2.155 8. log a x = log b x log b a Example: x = 5; a = integer No. log a x= 0.69897 log b x ο½ 0.698 log b a Page 7 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Combinatory 1- Number of permutation of an n-element set: P(n) = n! n=3 3! =6 123; 132; 213; 231; 312; 321 Number of k-combinations of an n-element set: C(n, k) ο½ 2- n! k!(n ο k )! n = 4 = (1234); k = 2 C(4,2)=4!/2!×2! = 6 12; 13; 14; 23; 24; 34 3- Number of subsets of an n-element set: 2 n n = 3 = (123); 23 =8 {1, 2, 3, 12, 13, 23, 123, ο¦} Floor and Ceiling Formulas ο· The floor of a real number x, denoted ο«xο», is defined the greatest integer not larger than x (e.g., ο«3.8ο»= 3, ο«-3.8ο»= -4, ο«3ο». = 3). The ceiling of area number ο©-3.8οΉ = -3, ο©3οΉ = 3. "Modify all floors and ceilings below" 1. x ο 1 < ο«xο» ο£ x ο£ ο©xοΉ οΌ x ο« 1 2.8 < 3 β€3.8β€ 4 < 4.8 2. ο«x ο« nο» ο½ ο«xο» ο« n and ο©x ο« nοΉ ο½ ο©xοΉ ο« n for real x and integer n ο«3.8 ο« 5ο» ο½ ο«3.8ο» ο« 5 8=3+5 3. οͺnοΊ ο©nοΉ οͺ2οΊ ο« οͺ2οΊ ο½ n ο« ο» οͺ οΊ n=5 Page 8 2+3=5 February 2012 Design and Analysis of Algorithms 4. ο©lg( n ο« 1)οΉ ο½ ο«lg nο» ο« 1 By Dr. Ahmad M. Awwad ; n=5 ο©lg( 5 ο« 1)οΉ ο½ ο«lg 5ο» ο« 1 ο©0.7781οΉ ο½ ο«0.7781ο» ο« 1 1 = 0 +1 βModularβ β (mod) ο· Modular arithmetic (n, m are integers, p is a positive integer) (n + m) mod p = (n mod p + m mod p) mod p Example: m=10; n=10; p=4 20 mod 4 = 0 (10 mod 4 +10 mod 4 ) mod 4 = (2 +2 ) mod 4 =0 (n * m ) mod p = ((n mod p) * ( m mod p )) mod p Example: (10*10) mod 4 = 0 ((10 mod 4)*(10 mod 4)) mod 4 = 2*2 mod 4 = 0 Sets ο· A set is a collection of distinguishable objects, called its members or elements. If an object x is a member of a set S, we write x ο S (read "x is a member of S" or, more briefly, "x is in S"). ο· If x is not a member of S, we write x β S. We can describe a set by explicitly listing its members as a list inside braces. β’ Ø denotes the empty set, that is, the set containing no members. β’ Z denotes the set of integers, that is, the set {..., -2, -1, 0, 1, 2 ...} Page 9 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad β’ R denotes the set of real numbers. β’ N denotes the set of natural numbers, that is, the set {0, 1, 2 ...}. ο· Given two sets A and B, we can also define new sets by applying set operations: The intersection of sets A and B is the set A β© B = {x : x ο A and x οB}. Example:A= {1, 2, 3, 4, 6, 7}; B= {3, 5, 7} Aβ©B = {3, 7} ο· The union of sets A and B is the set A ο B = {x : x ο A or x ο B}. A ο B = {1, 2, 3, 4, 5, 6, 7} The difference between two sets A and B is the set A - B = {x: x ο A and x β B}. A - B = {1, 2, 4, 6} Set operations obey the following laws. ο· Empty set laws: A β© Ø = Ø, A - Ø = A. ο· Idempotency laws: A β© A = A, A ο A = A. ο· Commutative laws: A β© B = B β© A, A οB = B ο A. A Venn diagram illustrating the first of DeMorgan's laws. Each of the sets A, B, and C is represented as a circle. Page 10 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad A= {1, 2, 3, 4, 6, 7}; B= {3, 5, 7}; C= {3, 6, 9} ο· Associative laws: A β© (B β© C) = (A β© B) β© C, {1, 2, 3, 4, 6, 7}β©({3, 5, 7}β©{3, 6, 9}) =({1, 2, 3, 4, 6, 7}β©{3, 5, 7})β© {3, 6, 9} {1, 2, 3, 4, 6, 7}β©{3} = {3,7}β© {3, 6, 9} {3} = {3} A= {1, 2, 3, 4, 6, 7}; B= {3, 5, 7}; C= {3, 6, 9} A ο (B οC) = (A οB) οC. {1, 2, 3, 4, 6, 7}ο({3, 5, 7}ο{3, 6, 9}) = ({1, 2, 3, 4, 6, 7}ο{3, 5, 7})ο{3, 6, 9} ο· {1, 2, 3, 4, 6, 7}ο{3,5,6,7,9} = {1,2,3,4,5,6,7}ο{3, 6, 9} {1, 2, 3, 4, 5, 6, 7, 9} = {1, 2, 3, 4, 5, 6, 7, 9} Distributive laws: {1, 2, 3, 4, 6, 7}β©({3, 5, 7}ο{3, 6, 9}) =({1, 2, 3, 4, 6, 7}β©{3, 5, 7})ο({1, 2, 3, 4, 6, 7}β©{3, 6, 9}) {1, 2, 3, 4, 6, 7}β© {3, 5, 6, 7, 9} ={3, 7} ο{3, 6} {3, 6, 7} = {3, 6, 7} {1, 2, 3, 4, 6, 7}ο({3, 5, 7} β© {3, 6, 9}) = ({1, 2, 3, 4, 6, 7} ο {3, 5, 7})β©({1, 2, 3, 4, 6, 7}ο{3, 6, 9}) {1, 2, 3, 4, 6, 7}ο {3} {1, 2, 3, 4, 6, 7} ο· = {1, 2, 3, 4, 5, 6, 7} β© {1, 2, 3, 4, 6, 7, 9} = {1, 2, 3, 4, 6, 7} Absorption βinclusionβ laws: A β© (A οB) = A, {1, 2, 3, 4, 6, 7} β©({1, 2, 3, 4, 6, 7}ο{3, 5, 7}) = {1, 2, 3, 4, 6, 7} Page 11 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad {1, 2, 3, 4, 6, 7}β© {3, 7} = {1, 2, 3, 4, 6, 7} {1, 2, 3, 4, 6, 7} = {1, 2, 3, 4, 6, 7} A ο (A β© B) = A. {1, 2, 3, 4, 6, 7}ο({1, 2, 3, 4, 6, 7}β©{3, 5, 7}) = {1, 2, 3, 4, 6, 7} {1, 2, 3, 4, 6, 7}ο {3, 7} = {1, 2, 3, 4, 6, 7} {1, 2, 3, 4, 6, 7} ο· = {1, 2, 3, 4, 6, 7} De-Morgan's laws: {1, 2, 3, 4, 6, 7} β ({3, 5, 7} β© {3, 6, 9}) = ({1, 2, 3, 4, 6, 7}- {3, 5, 7})ο({1, 2, 3, 4, 6, 7}-{3, 6, 9}) {1, 2, 3, 4, 6, 7} β {3} = {1, 2, 4, 6}ο {1, 2, 4, 7} {1, 2, 4, 6, 7} = {1, 2, 4, 6, 7} {1, 2, 3, 4, 6, 7} β ({3, 5, 7} ο {3, 6, 9}) = ({1, 2, 3, 4, 6, 7}- {3, 5, 7})β© ({1, 2, 3, 4, 6, 7}-{3, 6, 9}) {1, 2, 3, 4, 6, 7} β {3, 5, 6, 7, 9} = {1, 2, 4, 6}β© {1, 2, 4, 7} {1, 2, 4} = {1, 2, 4} ο· Given a universe U, we define the complement of a set A as Δ = U - A. For any set A ο U, we have the following laws: U = {1, 2, 3, 4, 6, 7, 8, 9} A= {1, 2, 3, 4, 6, 7} B = {3, 7} Page 12 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad π΄Μ = {8,9} ππππ΄ΜΏ = {1, 2, 3, 4, 6, 7} π΄ β© π΄Μ = {1, 2, 3, 4, 6, 7} β© {8,9} = β π΄ βͺ π΄Μ = {1, 2, 3, 4, 6, 7, 8, 9} ο· DeMorgan's laws can be rewritten with complements. For any two sets B, C ο U, we have : Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ {3, 7} β© {3, 6, 9} = 3Μ = {1, 2, 4, 6, 7, 8, 9} π΅ β© πΆ = Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ {3, 7}π Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΅Μ ππΆΜ = Μ Μ Μ Μ Μ Μ Μ {3, 6, 9} = {1, 2, 4, 6,8,9}π{1, 2, 4, 7,8} = {1,2,4,6,7,8,9} Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ = {1, 2, 4, 8} Μ Μ Μ Μ Μ Μ Μ Μ Μ {3, 7}U{3, 6, 9} = {3,6,7,9} π΅ππΆ = Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΅Μ β© πΆΜ = {3, 7}πΌ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ {3, 6, 9} = {1, 2, 4, 6, 8, 9} β© {1, 2, 4, 7, 8} = {1, 2, 4, 8} ο· Two sets A and B are disjoint if they have no elements in common, that is, if A β© B = Ø. ο· The number of elements in a set is called the cardinality (or size) of the set, denoted |S|. Two sets have the same cardinality if their elements can be put into a one-to-one correspondence. ο· The cardinality of the empty set is |Ø| = 0. If the cardinality of a set is a natural number {0, 1, 2 ...}, we say the set is finite; otherwise, it is infinite. An infinite set that can be put into a one-to-one correspondence with the natural numbers N is countably infinite; otherwise, it is uncountable. The integers Z are countable, but the reals R are uncountable. A={1, 2, 3, 4, 6, 7} and B={3, 7} ο· For any two finite sets A and B, we have the identity: From which we can conclude that Page 13 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad |A ο B| β€ |A| + |B|. βNo. of elements or size of |A U B|; |A|=6; |B|=2 6 β€ 6 +2 ο· If A and B are disjoint, then |A β© B| = Ø and thus |A οB| = |A|+|B|. If A ο B, then |A| β€ |B|. ο· A finite set of n elements is sometimes called an n-set. A 1-set is called a singleton. A subset of k elements of a set is sometimes called a k-subset. ο· The set of all subsets of a set S, including the empty set and S itself is denoted 2S and is called the power set of S. For example, 2{a,b} = {Ø,{a}, {b}, {a, b}}. The power set of a finite set S has cardinality 2|S|. ο· We sometimes care about set; like structures in which the elements are ordered. An ordered pair of two elements a and b is denoted (a, b). Thus, the ordered pair (a, b) is not the same as the ordered pair (b, a). Example on the ordered set {x, y, z} ο· The Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs such that the first element of the pair is an element of A and the second is an element of B. More formally, A × B = {(a, b): a οA and b οB}. ο· For example, {a, b} × {a, b, c} = {(a, a), (a, b), (a, c), (b, a), (b, b), (b, c)}. When A and B are finite sets, the cardinality of their Cartesian product is : 2*3=6 ο· The Cartesian product of n sets A1, A2,..., An is the set of n-tuples A1 × A2 × ··· × An = {(a1, a2,..., an) : ai ο Ai, i = 1, 2,..., n}, whose cardinality is Page 14 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad |A1 × A2 × ··· × An| = |A1| · |A2| · · · |An| "Num. of nodes in the product graph" ο· If all sets are finite. We denote an n-fold Cartesian product over a single set A by the set An = A × A × ··· × A, Whose cardinality is |An| = |A|n if A is finite. An n-tuple can also be viewed as a finite sequence of length n. Mathematical induction βProof by Inductionβ Suppose that you have just learned the product rule for derivatives [i.e. (fg)' = f 'g + fg'] you wanted to prove to someone that for every integer n >= 1, the derivative of π(π₯) = π₯ π is π β² = ππ₯ πβ1 . How might you go about doing this? Maybe you would argue like this: "Well, see that when n =1, f(x) = x and you know that the formula works in this case. Now for n = 2, Now for n = 3, Now for n = 4, Now for n = 5, And you see we can keep on going this way - do you see the pattern? We just keep using the product rule in conjunction βcombinationβ with the result from the previous line and we get the theorem for the next integer." Consider another example. Suppose that you wanted to show that for every integer n >= 1, . You might argue this way: It's true for n =1, that's pretty clear. You can also check it directly for n =2, 3, 4 and 5. Now that you know it's true for n =5, we can show you that it is true for n =6 like this: Page 15 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad And so the formula works for n=6, too. Now you can continue this way and use this last result to show that the formula is true for n=7. Then, using the fact that it is true for 7, show that is also true for 8 etc. you could say something like, "so, see, we can continue just like this and prove the result for one integer after another." But that's not very satisfying. So the mathematical induction is a way of formalizing above kind of proof so that we don't have to say "and so on" or "we keep on going this way" or some such statement. The idea is to show that the result is true for n=1 and then show how once we've shown it to be true for some integer, we can see that it must be true for the next one as well. It follows that the mathematical induction is a powerful, yet straight-forward method of proving statements whose "domain" is a subset of the set of integers. Usually, a statement that is proven by induction is based on the set of natural numbers. This statement can often be thought of as a function of a number n, where n = 1, 2, 3... Proof by induction involves three main steps: 1- Proving the base of induction (usually 0, 1, or 2). 2- Forming the induction hypothesis 3- Finally proving that the induction hypothesis holds true for all numbers in the domain Proving the base of induction involves showing that the claim holds true for some base value (usually 0, 1, or 2). There are sometimes many ways to do this, and it can require some ingenuity. The Principle of Mathematical Induction Suppose we have a claim P(n) about the positive integers. Then if we show both of (i) and (ii) below, then P(n) is true for all n>= 1. ο· P(1) is true or P(m) if the base is β 0 ο· For each k >= 1: If P(k) is true, Page 16 February 2012 Design and Analysis of Algorithms ο· By Dr. Ahmad M. Awwad Prove then P(k+1) is true. There is one very important thing to remember about using proof by induction. This technique can only be used to prove statements that have real valued inputs. If you think of the statement as a relation of functions (for example, prove f(x) β€ g(x) for all x), the domain of these functions must be a subset of the integers. It cannot be used to prove statements true for non-integer values. For example, the proof that we did in the above example does not prove that (2.5)² β₯ 2(2.5). It only proves the statement true for integer values of k greater than 2 (k = 2, 3, ...) However, for many proofs involving statements based on subsets of the integers (usually natural numbers), proof by induction is the easiest method to use. I. The Fibonacci Numbers The Fibonacci numbers are defined by the recurrence relation, π1 = 1, π2 = 2 πππ πππ π > 2, ππ = ππβ1 + ππβ2 So the first few Fibonacci Numbers are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,... There are numerous interested properties of the Fibonacci Numbers. Once guessed, most such properties can be verified by induction. Here are a few examples. 1. For every n >= 1, π3π ππ ππ£ππ. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,... 2. For every n >= 1, π4π ππ πππ£ππ ππππ ππ¦ 3. 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... 3. For every n >= 1 and m >= 1, ππβπ = ππβ1 + ππ ππβ1 β ππ ππ . Recall that the Fibonacci numbers are defined by the recurrence relation, fn = fn-1 + fn-2 n>2, f1=1, f2=1. So, f1=1, f2=1, f3=2, f4=3, f5=5, f6=8, f7=13, f8=21, f9=34, ... Page 17 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Examples: 1. To prove that we could argue like this: For n = 1, the result is clearly true since . Now suppose that for integer k > = 1, . We will be finished if we can show that But we have, and so the result follows by induction. Note: Induction arguments don't always start with the case n = 1. Sometimes we want to prove that an assertion βclaimβ is true for all integers n >= m for some other integer m. In that case we can use the slightly more general version of induction below. Or the above problem could be written as: Prove that the arithmetic series βππ=1 π equivalent to n(n + 1)/2. We can easily verify this for n = 1, so we make the inductive assumption that it holds for n and prove that it holds for n+1. we have 2. Prove the proposition for all n β₯ 0, βππ=1 π(π+1) 2 = π(π+1)(π+2) 6 βBaseβ 1. The proof is by induction on n, the upper limit of the sum Page 18 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad 2. The base case is n =0. 3. In this case both sides of the equation are 0. (Math.) 4. For n greater than 0, assume that βππ=0 = π(π+1)(π+2) 6 π(π+1) 2 = 6. βππ=0 π(π+1) 2 = βπβ1 π=1 7. βππ=1 π(π+1) 2 = 5. βπβ1 π=0 8. (πβ1)(π)(π+1) 6 9. βππ=1 3. π(π+1) 2 π(π+1) 2 = holds for all k β₯ 0 such that kοΌ n π(π+1)(π+2) 6 π+1 π(π+1) + 2 2 (πβ1)(π)(π+1) 6 + π(π+1) 2 = + βMathβ π(π+1) 2 π(π+1)(π+2) 6 π(π+1)(π+2) 6 β5+6β βMathβ β7+8β Prove that for every n >= 1, 133|11π+1 + 122πβ1 We argue by induction for n=1, the expression has the value . So the assertion is true for n=1. Now assume that for some integer k, 133|11π+1 + 122πβ1 . Then there must exist an integer t such that 133|11π+1 + 122πβ1 = 133π‘. Now we must show that the claim must be true for k+1, i.e. that 133|11π+2 + 122π+1. However, 122π+1 + 11π+2 = 122 (122πβ1 + 11π+1 ) β 122 . 11π+1 + 11π+2 122 (122πβ1 + 11π+1 ) β 11π+1 (122 β 11) 144(133π‘) β 133. 11π+1 = 133((144π‘ β 11π+1 ) So we have133|11π+2 + 122π+1, and the result follows by induction. Page 19 February 2012 Design and Analysis of Algorithms 4. By Dr. Ahmad M. Awwad Prove by induction that the sum 1 + 3 + 5 + 7 + ... + 2n-1 is a perfect square. It is almost impossible to prove this assertion without proving much more. For convenience, let Sn = 1 + 3 + 5 + 7 + ... + 2n-1. Then Sn+1 = Sn + (2n+1). Now the result is easily seen to be true in the case k=1, since 1 is a perfect square. Now assume that Sk is a perfect square, say Sk = t2 for some t. Then we must show that Sk+1 is also a perfect square. Well, Sk+1 = Sk + (2k+1) = t2 + 2k +1. Now what?? Well, we seem to be stuck. The proof isn't going anywhere. But look what happens if we try to prove the stronger result that Sn= n2. Our argument would be almost the same as before except that at the very end we would have: Sk+1 = Sk + (2k+1) = k2 + 2k +1 = (k+1)2. The induction proof works! 5. Let fn be the nth Fibonacci number, Prove by induction: For every n >= 1, 2 | f3n ( i.e. f3n is even) Proof: We argue by induction. For n=1 this says that f3 = 2 is even - which it is. Now suppose that for some k, f3k is even. So f3k = 2m for some integer m. Now we must show that f3(k+1) is even. Then, f3(k+1) = f3k+3 = f3k+2 +f3k+1 = f3k+1 + f3k + f3k+1 = 2f3k+1 + f3k = 2(f3k+1 + m). 6. Prove by Induction: For all integers n >= 1, 4|32πβ1 + 1 Proof: For n=1 this asserts that 4|4 which is certainly true. Now suppose that for some integer k >= 1, 4|32πΎβ1 + 1 . Thus, there is some integer m such that 32πΎβ1 + 1 = 4π. We claim that. 4|32(πΎ+1)β1 + 1. But this is equivalent to showing that 4|32πΎ+1 + 1. However, 32πΎ+1 + 1 = 32 (32πβ1 + 1) β 8 = 9(4π) β 8 = 4(9π β 1) , and so 32πΎ+1 + 1 is a multiple of 4 and the result follows by induction. Page 20 February 2012 Design and Analysis of Algorithms By Dr. Ahmad M. Awwad Prove by induction: For any n>=1, 7 | 8n - 1. 7. We argue by induction. For n=1 this just says that 7 | 7 which is true. Now suppose that for some k >=1, 7 | 8k - 1. So that 8k - 1 = 7t for some integer t. We must show that 7 | 8k+1 - 1. But, 8k+1 - 1 = 8 ( 8k - 1 ) + 7 = 8(7t) + 7 = 7( 8t +1 ). And so we have 8k+1 - 1 is a multiple of 7 and so, 7 | 8k+1 - 1. Prove by induction: For all n >= 1, 9n -1 is divisible by 8. 8. We will argue by induction (1). We first note that for n = 1, this just says that 8 | 8 which is clearly true. Now, assume that the result holds for some(2) integer k. So, 8 | 9k -1, and hence 9k -1 = 8t for some integer t. We claim that the result is true for the next larger integer, k+1. That is, we claim that 8 | 9k+1 -1. Once we show this we will be finished. But, 9k+1 -1 = 9( 9k -1 ) + 8 = 9( 8t ) + 8 = 8( 9t +1 ) and so 9k+1 -1 is a multiple of 8, and so 8 | 9k+1 -1. Thus our result follows by induction.(3) Page 21 February 2012 Design and Analysis of Algorithms X (n) By Dr. Ahmad M. Awwad = X ο«2K/2ο» + 1 =X ο«2K-1 ο» + 1 = X ο«2K-2 ο» + 1+1 = X ο«2K-3 ο» + 1+1+1 . = X ο«2K-i ο» + 1+1+β¦+1 // I times = let i = k = X ο«2K-k ο» + 1 + 1 ... + 1 / / k times = X ο«20 ο» + 1 + 1 ... + 1 = X ο«1 ο» + 1 + 1 ... + 1 = 1 + 1 + 1 ... + 1 =k+1 //2n = k = log2 n +1 Page 22 February 2012