0% found this document useful (0 votes)
40 views72 pages

Counting (Part-2) : Sequence Series Recursion

Uploaded by

aya16235
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views72 pages

Counting (Part-2) : Sequence Series Recursion

Uploaded by

aya16235
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

Counting (Part-2)

 Sequence
 Series
 Recursion

Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
SEQUENCE

2
Agenda
What is Sequence?
Explicit Formula of the Sequence
Types of the Sequence
Arithmetic
Geometric

3
SEQUENCE
 A sequence can be thought of as a list of
elements with a particular order
 Elements in a sequence are known as Terms
(Length of Sequence) A sequence may be
finite or infinite
 EXAMPLES
 1, 2, 3, 4, 5, …
 4, 8, 12, 16, 20,…
 2, 4, 8, 16, 32, …
 1, 1/2, 1/3, 1/4, 1/5, …
 1, 4, 9, 16, 25, …
 1, -1, 1, -1, 1, -1, …
 NOTE: The symbol “…” is called ellipsis, and
reads as “so forth”
4
SEQUENCE
 FORMAL DEFINITION
 A sequence is a function whose domain is the
set of integers greater than or equal to a
particular integer.
 Usually this set is the set of Natural numbers
{1, 2, 3, …} or the set of whole numbers {0, 1,
2, 3, …}.
 NOTATION
 We use the notation an to denote the image of
the integer n, and call it a term of the sequence.
Thus
 a1, a2, a3, a4 …, an, …
represent the terms of a sequence defined on the set of
natural
5
numbers N.
FINDING TERMS OF A SEQUENCE GIVEN BY AN EXPLICIT FORMULA

 An explicit formula or general formula for a


sequence is a rule that shows how the values of
ak depends on k.
 EXAMPLE
 Defineka sequence a1, a2, a3, … by the explicit
a  k for all integers k 1
k 1
formula

1 four
 The first 1 terms2of the
2 sequence
3 are:
3
a 
1  ,a  2  ,a  
3
1 1 2 2 1 3 1
3 4
4 4
and fourth term is a4  
4 1 5
6
EXAMPLE (Infinite Sequence)
 Write the first four terms of the sequence
defined by the formula bj = 1 + 2j, for all
integers j  0
 SOLUTION:
 b0 = 1 + 20 = 1 + 1 = 2
 b1 = 1 + 21 = 1 + 2 = 3
 b2 = 1 + 22 = 1 + 4 = 5
 b3 = 1 + 23 = 1 + 8 = 9
 REMARK
 The formula bj = 1 + 2j , for all integers j  0
defines an infinite sequence having infinite
number of values.
7
EXERCISE (Infinite Sequence)
 Compute the first six terms of the sequence
defined by the formula Cn = 1+ (-1)n for all
integers n  0
 SOLUTION
 C0 = 1 + (-1) 0= 1 + 1 = 2 , C1 = 1 + (-1)1 = 1 +
(-1) = 0
 C2 = 1 + (-1)2 = 1 + 1 = 2 , C3 = 1 + (-1)3 = 1 +
(-1) = 0
 C4 = 1 + (-1)4 = 1 + 1 = 2 , C5 = 1 + (-1)5 = 1 +
(-1) = 0
 REMARK
 If n is even, then Cn = 2 and if n is odd, then Cn
=0 8
EXERCISE (Alternating Sequence)
 EXAMPLE
 Write the first four terms of the sequence
defined by
n
( 1) n
Cn  for all integers n 1
n 1
 Solution
( 1)1 (1)  1 ( 1) 2 (2) 2 (  1)3 (3)  3
C1   , C2   , C3  
1 1 2 2 1 3 3 1 4
( 1) 4 (4) 4
And fourth term isC4  
4 1 5

 REMARK:A sequence whose terms


alternate in sign is called an alternating 9
EXERCISE
 Find explicit formulas for sequences with the
initial terms given:
 0, 1, -2, 3, -4, 5, …
 SOLUTION
 an = (-1)n+1n for all integers n  0

1 1
bk   for all integers n 1
k k 1
10
EXERCISE
 2, 6, 12, 20, 30, 42, 56, …
 SOLUTION
 Cn = n (n + 1) for all integers n  1

 1/4, 2/9, 3/16, 4/25, 5/36, 6/49, …


 SOLUTION

i
di  for all integers i 1
(i  1) 2
OR
j 1
dj  2
for all integers j 0
( j  2)
11
Types of Sequence
Arithmetic Sequence
Next term is calculated by adding in the
preceding term
Geometric Sequence
Next term is calculated by multiplying by the
preceding term

12
ARITHMETIC SEQUENCE
 A sequence in which every term after the first is
obtained from the preceding term by adding a
constant number is called an arithmetic
sequence or arithmetic progression (A.P.)
 The constant number, being the difference of
any two consecutive terms is called the
common difference of A.P., commonly denoted
by “d”.
 EXAMPLES:
 5, 9, 13, 17, … (common difference = 4)
 0, -5, -10, -15, … (common difference = -5)
 x + a, x + 3a, x + 5a, …(common difference =
2a)
13
GENERAL TERM OF AN ARITHMETIC SEQUENCE

 Let a be the first term and d be the common


difference of an arithmetic sequence. Then the
sequence is
a, a+d, a+2d, a+3d, …
 If ai, for i  1, represents the terms of the
sequence then
 a1 = first term = a = a + (1-1) d
 a2 = second term = a + d = a + (2-1) d
 a3 = third term = a + 2d = a + (3 -1) d
 By symmetry
 an = nth term = a + (n - 1)d for all integers n
1.
14
EXAMPLE
 Find the 20th term of the arithmetic sequence
 3, 9, 15, 21, …
 SOLUTION:
 Here a = first term = 3
 d = common difference = 9 - 3 = 6
 n = term number = 20
 a20 = value of 20th term = ?
 Since an = a + (n - 1) d; n 1
  a20 = 3 + (20 - 1) 6
 = 3 + 114
 = 117

15
EXERCISE
 Find the 36th term of the arithmetic sequence
whose 3rd term is 7 and 8th term is 17.
 SOLUTION
 Let a be the first term and d be the common
difference of the arithmetic sequence.
 Then
 an = a + (n - 1)d n1
  a3 = a + (3 - 1) d
 and a8 = a + (8 - 1) d
 Given that a3 = 7 and a8 = 17. Therefore
 7 = a + 2d……………………(1)
 and 17 = a + 7d………….………..(2)

16
EXERCISE
 Subtracting (1) from (2), we get,
 10 = 5d
  d=2
 Substituting d = 2 in (1) we have
 7 = a + 2(2)
 which gives a = 3
 Thus, an = a + (n - 1) d
 an = 3 + (n - 1) 2 (using values of a and d)
 Hence the value of 36th term is
 a36 = 3 + (36 - 1) 2
 = 3 + 70
 = 73
17
GEOMETRIC SEQUENCE
 A sequence in which every term after the first is
obtained from the preceding term by
multiplying it with a constant number is called a
geometric sequence or geometric progression
(G.P.)
 The constant number, being the ratio of any two
consecutive terms is called the common ratio
of the G.P. commonly denoted by “r”.
 EXAMPLES
 1, 2, 4, 8, 16, … (common ratio = 2)
 3, - 3/2, 3/4, - 3/8, … (common ratio = - 1/2)
 0.1, 0.01, 0.001, 0.0001, …(common ratio = 0.1
= 1/10)
18
GENERAL TERM OF A GEOMETRIC SEQUENCE

 Let a be the first term and r be the common ratio


of a geometric sequence. Then the sequence is a,
ar, ar2, ar3, …
 If ai, for i  1 represent the terms of the
sequence, then
 a1 = first term = a = ar1-1
 a2 = second term = ar = ar2-1
 a3 = third term = ar2 = ar3-1
 ………………
 ………………
 an = nth term = arn-1; for all integers n
1
19
EXAMPLE
 Find the 8th term of the following geometric
sequence
 4, 12, 36, 108, …
 SOLUTION
 12
Here a = first term = 4
 r = common ratio = 4 =3
 n = term number = 8
 a8 = value of 8th term = ?
 Since an = arn-1; n1
  a8 = (4)(3)8-1
 = 4 (2187)
 = 8748
20
Class Task
 Which term of the geometric
sequence is 1/8 if the first term
is 4 and common ratio ½
 Write the geometric sequence
with positive terms whose
second term is 9 and fourth
term is 1.

21
SERIES

22
SERIES
 The sum of the terms of a sequence
forms a series. If a1, a2, a3, … represent a
sequence of numbers, then the
corresponding series
 is

 a1 + a2 + a3 + … =
a
k 1
k

23
SUMMATION NOTATION
 The capital Greek letter sigma  is used to write
a sum in a short hand notation; where k varies
from 1 to n represents the sum given in
expanded form by
 = a1 + a 2 + a 3 + … + a n
 More generally if m and n are integers and m 
n, then the summation from k equal m to n of ak
is
 Here k is called the index of the summation; m
the lower limit of the summation and n the
upper limit of the summation.

24
COMPUTING SUMMATIONS
 a0 = 2, a1 = 3, a2 = -2, a3 = 1 and a4 =
0.Compute each of the summations:
4 2 1
1. a
i 0
i 2. a
j 0
2j a
k 1
k

 SOLUTION
4
 1.  ai = a0 + a1 + a2 + a3 + a4
i 0
 = 2 + 3 + (-2) + 1 + 0 = 4
2

 2. 
a2 j
j 0 = a0 + a2 + a4
 = 2 + (-2) + 0 = 0
1

 3. 
ak
k 1 =a1
 =3 25
EXERCISE

26
EXERCISE
3
1.  (2i  1)
i 1
 [2(1)  1]  [2(2)  1]  [2(3)  1]

 1  3 5
 9
1
2.   2)
( k 3

k  1
 [( 1)3  2]  [(0)3  2]  [(1)3  2]

 [ 1  2]  [0  2]  [1  2]
 1 2 3
 6

27
SUMMATION NOTATION TO EXPANDED FORM
i
 Write the summation (  1)
n
to expanded
form:
i 0 i  1
 Solution

28
TRANSFORMING A SUM BY A CHANGE OF VARIABLE
3
 Consider k 2 12  22  32
 k 1
3
 And  i 2
12
 2 2
 32

i 1
3 3
 Hence  k
k 1
 2
i 2

i 1

 The index of a summation can be


replaced by any other symbol. The index
of a summation is therefore called a
dummy variable.

29
EXERCISE
n 1
k
 Consider 
k 1 ( n  1)  k

 Substituting k = j + 1 so that j = k – 1
 When k = 1, j = k - 1 = 1 - 1 = 0
 When k = n + 1, j = k - 1 = (n + 1) - 1 = n
 Hence
n 1
k n
j 1

k 1 ( n  1)  k

j 0 ( n  1)  ( j  1)

n
j  1 n k 1
  (changing variable)
j 0 n  j k 0 n  k

30
EXERCISE
 Transform by making the change of variable j =
i - 1, in the summation

n 1
i

i 1 ( n  i ) 2

31
PROPERTIES OF SUMMATIONS
n n n
1.  (a
k m
k  bk )  ak   bk ;
k m k m
ak , bk  R

n n
2.  ca
k m
k  c  ak
k m
c R

b i b
3.  (k  i)   k
k a  i k a
iN

b i b
4.  (k  i )   k
k a i k a
iN

32
EXERCISE
 Express the following summation more simply
n n
3 (2k  3)   (4  5k )
k 1 k 1

 Solution

33
EXERCISE
 Express the following summation more simply
n n
3 (2k  3)   (4  5k )
k 1 k 1

 Solution n n
 3 (2k  3)   (4  5k )
k 1 k 1
n n
3 (2k  3)   (4  5k )
k 1 k 1
n
 [3(2k  3)  (4  5k )]
k 1
n
 ( k  5)
k 1
n n
 k  5
k 1 k 1
34
ARITHMETIC SERIES
 The sum of the terms of an arithmetic
sequence forms an arithmetic series
(A.S). For example
 1 + 3 + 5 + 7 + … is an
arithmetic series of positive odd
integers.
 In general, if a is the first term and d the
common difference of an arithmetic
series, then the series is given as: a +
(a+d) + (a+2d) +…

35
SUM OF n TERMS OF AN ARITHMETIC SERIES
 Let a be the first term and d be the common
difference of an arithmetic series. Then its nth
term is:
 an = a + (n - 1)d; n  1
 If Sn denotes the sum of first n terms of the
A.S, then
 Sn = a + (a + d) + (a + 2d) + … + [a +
(n-1) d]
 = a + (a+d) + (a + 2d) + … + an
 = a + (a+d) + (a + 2d) + … + (an - d)
+ an ………(1)
 where an = a + (n - 1) d
 Rewriting the terms in the series in reverse 36
SUM OF n TERMS OF AN ARITHMETIC SERIES
 Adding (1) and (2) term by term, gives
 2 Sn = (a + an) + (a + an) + (a + an) + … + (a +
an) (n terms)
 2 Sn= n (a + an)
 Sn = n(a + an)/2
 Sn = n(a + l)/2…………………..(3)
 Where l = an = a + (n - 1)d
 Therefore
 Sn= n/2 [a + a + (n - 1) d]
 Sn = n/2 [2 a + (n - 1) d]……….(4)

37
EXERCISE
 Find the sum of first n natural numbers.
 SOLUTION
 Let Sn = 1 + 2 + 3 + … + n
 Clearly the right hand side forms an arithmetic
series with
 a = 1, d = 2 - 1 = 1 and n=n
n
 Sn   2a  (n  1)d 
2
n
  2(1)  (n  1)(1)
2
n
  2  n  1
2
n(n  1)

2 38
GEOMETRIC SERIES
 The sum of the terms of a geometric sequence
forms a geometric series (G.S.). For example
 1 + 2 + 4 + 8 + 16 + …
 is geometric series.
 In general, if a is the first term and r the
common ratio of a geometric series, then the
series is given as: a + ar + ar2 + ar3 + …

39
SUM OF n TERMS OF A GEOMETRIC SERIES
 Let a be the first term and r be the common
ratio of a geometric series. Then its nth term is:
 an = arn-1; n  1
 If Sn denotes the sum of first n terms of the G.S.
then
 Sn = a + ar + ar2 + ar3 + … + arn-2 + arn-1
……………(1)
 Multiplying both sides by r we get.
 r Sn = ar + ar2 + ar3 + … + arn-1 +
arn………………(2)
 Subtracting (2) from (1) we get
 Sn - rSn = a – aar
(1 n r n )
 Sn  (r 1)
   nr = a (1 - rn)
(1 - r)1S 40
EXERCISE
 Find the sum of the geometric series

 Solution
 In the given geometric series
2 1
a 6, r   and n 10
6 3
a (1  r n )
 Sn 
1 r
  1 10 
6 1     6 1 1 
  3   
   310 
S10  
 1  4
1     
 3  3
 1 
9  1  10 
3 
 
2 41
INFINITE GEOMETRIC SERIES
 Find the sum of the infinite geometric series:
 …………….

 SOLUTION
 Here we have
9 3/ 2 2
a , r 
4 9/4 3
 we can use the above formula.
a
 S 
1 r
9/4

1 2 / 3
9 / 4 9 3 27
   
1/ 3 4 1 4 42
RECURSION
USE OF RECURSION
At first recursion may seem hard or
impossible, may be magical at best.
However, recursion often provides
elegant, short algorithmic solutions to
many problems in computer science and
mathematics.
Examples where recursion is often used
math functions
number sequences
data structure definitions
data structure manipulations
language definitions

44
RECURSION
We know the Set of Odd numbers. We give the
new definition of the same set that is the set of
Odd numbers.
Definition for odd positive integers may be given
as:
BASE
 1 is an odd positive integer.
RECURSION
 If k is an odd positive integer, then k + 2 is an odd
positive integer.
Now, 1 is an odd positive integer by the definition
base. With k = 1, 1 + 2 = 3, so 3 is an odd
positive integer. With k = 3, 3 + 2 = 5, so 5 is an
odd positive integer and so, 7, 9, 11, … are odd
positive integers.

45
RECURSION
 RECURSION
 The process of defining an object in terms of smaller
versions of itself is called recursion.
 A recursive definition has two parts:
 1.BASE
 An initial simple definition which cannot be expressed in
terms of smaller versions of itself.
 2. RECURSION
 The part of definition which can be expressed in terms of
smaller versions of itself.
 RECURSIVELY DEFINED FUNCTIONS
 A function is said to be recursively defined if the function
refers to itself such that
 There are certain arguments, called base values, for which the
function does not refer to itself.
 Each time the function does refer to itself, the argument of the
function must be closer to a base value.

46
EXAMPLE
 Suppose that f is defined recursively by
 f(0) = 3
 f(n + 1) = 2 f (n) + 3
 Find f(1), f(2), f(3) and f(4)
 SOLUTION
 From the recursive definition it follows that
 f(1) = 2 f(0) + 3 = 2(3) + 3 = 6 + 3 = 9
 In evaluating of f(1) we use the formula given in the
example and we note that it involves f(0) and we are also
given the value of that which we use to find out the
functional value at 1. Similarly we will use the preceding
value
 In evaluating the next values of the functions as we did
below.
 f(2) = 2 f(1) + 3 = 2(9) + 3 = 18 + 3 = 21
 f(3) = 2 f(2) + 3 = 2(21) + 3 = 42 + 3 = 45
 f(4) = 2 f(3) + 3 = 2(45) + 3 = 90 + 3 = 93

47
EXAMPLE
Find f(2), f(3), and f(4) if f is defined
recursively by
 f(0) = -1, f(1)=2 and for n = 1, 2,
3, …
 f(n+1) = f(n) + 3 f(n - 1)

48
EXAMPLE
 Find f(2), f(3), and f(4) if f is defined recursively by
 f(0) = -1, f(1)=2 and for n = 1, 2, 3, …
 f(n+1) = f(n) + 3 f(n - 1)
 SOLUTION
 From the recursive definition it follows that
 f(2) = f(1) + 3 f (1-1)
 = f(1) + 3 f (0)
 = 2 + 3 (-1)
 = -1
 Now in order to find out the other values we will need the values of the preceding .So
we write these values here again
 f(0) = -1, f(1)=2 f(n+1) = f(n) + 3 f(n - 1)
 f(2) = -1
 By recursive formula we have
 f(3) = f(2) + 3 f (2-1)
 = f(2) + 3 f (1)
 = (-1) + 3 (2)
 =5
 f(4) = f(3) + 3 f (3-1)
 = f(2) + 3 f (2)
 = 5 + 3 (-1)
 =2

49
THE FACTORIAL OF A POSITIVE INTEGER
For each positive integer n, the factorial of n
denoted n! is defined to be the product of all the
integers from 1 to n:
 n! = n·(n - 1)·(n - 2) · · · 3 · 2 · 1
Zero factorial is defined to be 1
 0! = 1
EXAMPLE
 0! = 1 1! = 1
 2! = 2·1 = 2 3! = 3·2·1 = 6
 4! = 4·3·2·1 = 24 5! = 5·4·3·2·1 = 120
 6! = 6·5·4·3·2·1= 720

 7! = 7·6·5·4·3·2·1= 5040

50
THE FACTORIAL OF A POSITIVE INTEGER
REMARK
5! = 5 · 4 · 3 · 2 · 1
 = 5 ·(4 · 3 · 2 · 1)
 = 5 · 4!
In general, n! = n(n-1)! for each positive
integer n.

51
THE FACTORIAL FUNCTION DEFINED RECURSIVELY

We can define the factorial function F(n)


= n! recursively by specifying the initial value
of this function, namely, F(0) = 1, and
giving a rule for finding F(n) from F(n-1).
{(n! = n(n-1)!}
Thus, the recursive definition of factorial
function F(n) is:
1. F(0) = 1
2. F(n) = n F(n-1)

52
EXAMPLE
Let S be the function such that S(n) is the sum of
the first n positive integers. Give a recursive
definition of S(n).
SOLUTION
The initial value of this function may be specified
as S(0) = 0
Since
S(n) = n + (n - 1) + (n - 2) + … + 3 + 2 + 1
 = n + [(n - 1) + (n - 2) + … + 3 + 2 + 1]
 = n + S(n-1) which defines the recursive
step.
Accordingly S may be defined as:
1. S(0)= 0
2. S(n) = n + S(n - 1) for n  1
53
Rabbits and the Fibonacci Numbers
Example: A young pair of rabbits (one of each

does not breed until they are 2 months old. After


gender) is placed on an island. A pair of rabbits

they are 2 months old, each pair of rabbits


produces another pair each month. Find a
recurrence relation for the number of pairs of
rabbits on the island after n months, assuming
that rabbits never die.

This is the original problem considered by


Leonardo Pisano (Fibonacci) in the thirteenth
century.
Rabbits and the Fiobonacci Numbers
(cont.)

Modeling the Population Growth of Rabbits on an


Island
Rabbits and the Fibonacci Numbers (cont.)
Solution: Let fn be the the number of pairs of rabbits after n months.
 There are is f1 = 1 pairs of rabbits on the island at the end of the
first month.
 We also have f2 = 1 because the pair does not breed during the first
month.
 To find the number of pairs on the island after n months, add the
number on the island after the previous month, fn-1, and the
number of newborn pairs, which equals fn-2, because each newborn
pair comes from a pair at least two months old.

fn = fn-1 + fn-2 for n ≥ 3 with the initial conditions f1 = 1 and f2


Consequently the sequence {fn } satisfies the recurrence relation

= 1.
The number of pairs of rabbits on the island after n months is given by
the nth Fibonacci number.
Fibonacci Sequence
Definition: Define the Fibonacci sequence, f0 ,f1 ,f2,…, by:
 Initial Conditions: f0 = 0, f1 = 1
 Recurrence Relation: fn = fn-1 + fn-2

Example: Find f2 ,f3 ,f4 , f5 and f6 .

f2 = f1 + f0 = 1 + 0 = 1,
Answer:

f3 = f2 + f1 = 1 + 1 = 2,
f4 = f3 + f2 = 2 + 1 = 3,
f5 = f4 + f3 = 3 + 2 = 5,
f6 = f5 + f4 = 5 + 3 = 8.
Recurrence Relations
Definition: A recurrence relation for the sequence
{an} is an equation that expresses an in terms of
one or more of the previous terms of the
sequence, namely, a0, a1, …, an-1, for all integers n
with n ≥ n0, where n0 is a nonnegative integer.
A sequence is called a solution of a recurrence
relation if its terms satisfy the recurrence
relation.
The initial conditions for a sequence specify the
terms that precede the first term where the
recurrence relation takes effect.
Solving Recurrence Relations
Finding a formula for the nth term of the
sequence generated by a recurrence relation
is called solving the recurrence relation.
Such a formula is called a closed formula.
Here we illustrate by example the method of
iteration in which we need to guess the
formula. The guess can be proved correct by
the method of induction (Chapter 5).
Iterative Solution Example
Method 1: Working upward, forward substitution
Let {an} be a sequence that satisfies the recurrence
relation an = an-1 + 3 for n = 2,3,4,…. and suppose
that a1 = 2.
a2 = 2 + 3∙1
a3 = 2 + 3 + 3 = 2 + 3 ∙ 2
a4 = 2 +3 + 3 + 3 = 2 + 3 ∙ 3
a5 = 2 +3 + 3 + 3+ 3 = 2 + 3 ∙ 4
a6 = 2 +3 + 3 + 3+ 3+3 = 2 + 3 ∙ 5
...
an = 2 +3+…+ 3=2+3(n – 1)
an=2+3(n –
1)
Iterative Solution Example
Method 2: Working downward, backward substitution
Let {an} be a sequence that satisfies the recurrence relation
an = an-1 + 3 for n = 2,3,4,…. and suppose that a1 = 2.
an = an-1 + 3
an-1 = (an-2 + 3) + 3 = an-2 + 3 ∙ 2
an-2 = (an-3 + 3 )+ 3 ∙ 2 = an-3 + 3 ∙ 3
an-3 = (an-4 + 3 )+ 3 ∙ 3 = an-4 + 3 ∙ 4
an-4 = (an-5 + 3 )+ 3 ∙ 4 = an-5 + 3 ∙ 5
.
.
= a1 + 3 ∙(n – 1)

an=2+3(n –
= 2 + 3(n – 1)

1)
Financial Application
Example: Suppose that a person deposits

yielding 11% per year with interest compounded


$10,000.00 in a savings account at a bank

30 years?
annually. How much will be in the account after

Let Pn denote the amount in the account after 30


years. Pn satisfies the following recurrence

Pn = Pn-1 + 0.11Pn-1 = (1.11) Pn-1


relation:

10,000
with the initial condition P0 =
Continued on next slide 
Financial Application
Pn = Pn-1 + 0.11Pn-1 = (1.11) Pn-1
with the initial condition P0 = 10,000
Solution: Forward Substitution
P1 = (1.11)P0
P2 = (1.11)P1 = (1.11)2P0
P3 = (1.11)P2 = (1.11)3P0

(1.11)n 10,000
:
Pn = (1.11)Pn-1 = (1.11)nP0 =

Pn = (1.11)n 10,000 (Can prove by induction, covered in


Chapter 5)

P30 = (1.11)30 10,000 = $228,992.97


Some Useful Summation Formulae.
EXERCISE
Find the first four terms of the following
recursively defined sequence.
 b1 = 2
 bk = bk-1 + 2 · k, for all
integers k  2
SOLUTION

65
EXERCISE
Find the first four terms of the following
recursively defined sequence.
 b1 = 2
 bk = bk-1 + 2 · k, for all
integers k  2
SOLUTION
 b1 = 2 (given in base step)
 b2 = b1 + 2·2=2+4=6
 b3 = b2 + 2 · 3 = 6 + 6 = 12
 b4 = b3 + 2 · 4 = 12 + 8 = 20
66
EXERCISE
Find the first five terms of the following
recursively defined sequence.
 t0 = – 1, t1 = 1
 tk = tk-1 + 2 · tk-2, for all
integers k  2
SOLUTION

67
EXERCISE
Find the first five terms of the following
recursively defined sequence.
 t0 = – 1, t1 = 1
 tk = tk-1 + 2 · tk-2, for all
integers k  2
SOLUTION
 t0 = – 1, (given in base step)
 t1 = 1 (given in base
step)
 t2 = t1 + 2 · t0 = 1 + 2 · (–1) = 1 – 2
= –1
 t3 = t2 + 2 · t1 = –1 + 2 · 1 = –1 + 2 =68
EXERCISE
Define a sequence b , b , b , . . . by the formula b
0 1 2 n
= 5n , for all integers n  0.
Show that this sequence satisfies the recurrence
relation bk = 5bk – 1, for all integers k 
1.
SOLUTION
The sequence is given by the formula
 bn = 5n
Substituting k for n we get
 bk = 5k . . . . . (1)
Substituting k – 1 for k we get
 bk-1 = 5 k-1 . . . . . (2)
Multiplying both sides of (2) by 5 we obtain
 5 · bk-1 = 5 · 5 k – 1
 = 5k = b k using (1)
Hence bk = 5bk-1 as required 69
THE TOWER OF HANOI
The puzzle was invented by a French
Mathematician Adouard Lucas in 1883. It
is well known to students of Computer
Science since it appears in virtually any
introductory text on data structures or
algorithms.
There are three poles on first of which are
stacked a number of disks that decrease in
size as they rise from the base. The goal is
to transfer all the disks one by one from
the first pole to one of the others, but they
must never place a larger disk on top of a
smaller one. 70
THE TOWER OF HANOI

71
THE TOWER OF HANOI
Let m be the minimum number of moves needed
n
to move a tower of n disks from one pole to
another. Then mn can be obtained recursively as
follows.
m = 1
1
m = 2 m +1
k k-1
m = 2 · m + 1 = 2 · 1 + 1 = 3
2 1
m = 2 · m + 1 = 2 · 3 + 1 = 7
3 2
m = 2 · m + 1 = 2 · 7 + 1 = 15
4 3
m = 2 · m + 1 = 2 · 15 + 1 = 31
5 4
m = 2 · m + 1 = 2 · 31 + 1 = 63
6 5
 Note that
m = 2n – 1
n
m = 264 – 1
64
  584.5 billion years 72

You might also like