CHAPTER 3 :
RECURSION AND GENERATING FUNCTIONS
RECURSIVE SEQUENCES
E. g (t - l ) a EIR
}
' "
f- (2) f- )
Cny
f- ( o ) -
- I
flo)
-
- I
,
fcc ) - a
,
= a =
a
,
. . .
,
f- ( htt) = a
f- ( )u
induction to show
use
E -
g ( C 27 -
} ! induction
I
f- Co) flu) n ← use
-
-
-
-
flute) = ( htt ) f- Ca)
E. g ( I -3 )
" ( rt "t )
'
Express flu) =
recursively .
via induction
)
"
S" " " t" "
"" = ° " "" "t " "" = " "" + " "" t '" " " "d to " th "
P"
=
"
"
f- ( c ) = l
flu ) =
02 ✓
tf (
' '
fcc) (n ( htt) ( Zntl ))
'
2
f Cz ) = 5 = t
flu ) t ti ) =
n t ( ht D 2n2+7nt6 = 2n2t4nt3nt 6
"
By t ( ntl ) (
#
f- (z )
= 14 =
f- (2) t 3 # H . =
n ( zntl) t G ( ht i ) =
2n (n t 2) t3(nt2 )
I ( htt ) ( 2n2 7- 6 ] ( znt 3) ( ntz)
=
=
+ n t
=
I ( atl ) ( ht 2) ( 2h t 3)
=
( htt ) ( ( ht c) t 1) ( 2 ( nti ) ti )
6 So the result holds for all n> o .
E.
g.
( 1.4 )
we define a recursive function fln ,
r ) for her > o and n > O as follows :
f- (n ,
o ) = f- ( n ,
n ) = I
f- ( n
,
r ) =
f (n -
I
,
r -
l ) t f- (n -
I
,
r )
( I It ( I ) )
"
Pascals identity ( ( F ) satisfies the conditions and boundary conditions f
:
same as .
So far r )
-
-
(7)
,×4
,
In :') F
vi. it
'
'
+
,
it: i!
" """ "
: innit ! n'÷
'
! inn
'
'
'
+
in .ir .net
-
= -
.
. r ! (n -
r )!
= r (n -
i )!
! (n
+ (n -
r ) (n -
i )! = (n -
i ) ! ( Yt
! (n )!
n -
A =
! (n
n !
)!
( =
( Y ))
r
-
r )! r -
r
r
-
r
, FIBONACCI NUMBERS
Definition :( 2. c)
The FIBONACCI NUMBERS fn are
given by the recurrence :
fn
'
-
O
,
f, -
- I for =
fn it for -
z
(n 32 )
,
-
E -
g . ( first few terms) :
1,1 2,3 5,8 13,21
, , , ,
. . -
2.2 )
g (
E -
:
theoretical Phd
Every computer scientist
graduates one student every year , except the first year after
how 2020 ?
they graduate . If there was one theoretical computer scientist in 1975
, many are there in
Let tn be the number of theoretical computer scientists ( Tcs ) in year 1975 t n :
t.in?:: : : :at:: :. . . e)boun::r:n:i: ions
I
to =
given
-
E I new student fn
no Has recurrence
but different
= -
same as
, ,
.
tn C- 1975
En t t n 2020 n 4S
-
= -
-
-
.
,
n -
z
^ n
l l tag =
fab
existing TCS , New graduates
Eg ( 2.3 )
How there long 1
many ways are to walk from step 0 to step n of a staircase
taking or 2
steps at a time with no
backtracking .
f
fi fi
n =3
' ' '
ar
.
( L
(
o o
o
let
Wn
=
number of walks / steps to step n .
W I to 1
step
→
to walk
only
=
, one
way
at
Wz 2
to walk to step directly to stop step I
=
→
Two step 2 : it or
ways .
'
:
For
larger n we can either to
step and then to walk to
walk n 2
step directly step n or
-
,
step n
-
l and take one
step .
walk
Every arises this
way ,
and the
types are
disjoint .
✓
(
^ ^
n -
I n -
l
Wn =
Wn .
. two -
z
but
boundary conditions so
2 z
Wn '
fret ,
n -
n -
Wn .
,
walks to
step n -
I Wn -
z
walks to
step n -
2