Download Chapter 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Eisenstein's criterion wikipedia , lookup

Factorization wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Corecursion wikipedia , lookup

Addition wikipedia , lookup

Transcript
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