Unit 2 DMS
Unit 2 DMS
. . . f fi . .
A hnear recurrenc e relation of degree k with constant coc 1c1ents ts a recurre
nee t
the form
0
an= C 1an-l + C2an-2 + CJan-3 + ... ... + Ckan-k. Where C1, C2,.... Ck are real numbers and o~.-!
is called linear, homogeneous, second order recurrence relation with constant coefficient
where Cl and C2 are not equal to zero.
nth order: an= Cl 3n-1 + C2 3n-2 + C3 an-3 + C4 3n-4 ••••••••• +Ck 3n-k
Example 3: Wbat is tbe solution for tbe recu1Tence relation an = an-I + 2an-2 with ao = 2 and a t
= 7?
Recurrence relation an = an- I + 2an-2
Characteristic equation: r2 - r- 2 =O
(r- 2) and (r + 1), Therefore r1 = 2 and r2 = -1
General Solution: an= C(2n) + D(-1").
Particular Solution:
ao=2
ao = C(2°) + D(-1 °) =2
C+D=2 (Equation 1)
a1 = 2C -D = 7 (Equation 2)
From Equation 1 and 2
C+D=2
2C-D= 7
3C = 9; C = 9/3 = 3
Apply C in Equation 1; 3 + D = 2; D = -1
Therefore Particular Solution is: an= 3(2°) - (-1 °).
3 + 3D = 6; 3D = 6 - 3 = 3
D = 3/3 = 1
C = I andD = 1
Example 5: Find the explicit fom,ula for the Fibonacci numbers (fn = fn.1 + f11.2) with the initial
conditions fo = 0 and f1 = 1)
C+ 4D + 9E= 15 Equation 3
C = 1, D = -1 and E = 2
When we solve these three equations, we get
(2°) + 2(38 ) .
Therefore Par ticu lar Solution is an = (1 °) -
Assignment:
1) an = San-I - 6an-2 with the initial condition
s ao = 1, a1 = 0
2) an= 4an-t - 4an-2 with the initial condition
s a0 = 6, a1 = 8
3) an= -4ao-J - 4ao-2with the initial condition
s ao = 0, a1 = 1
4) an= 4an-2 with the initial conditions ao =
0, a1= 4
INCLUSION AND EXCLUSION PRJNClPLE:
Ler A , B be any two fi nite sets.
Example I:
How many bit strings of length eight either start with a l bit or end with the two bits 00?
7
Number of bits start with 1 = 2 = 128
6
Number of bits end with 00 = 2 = 64
Number of bits start with 1 and end with 00 = 25 = 32
According to the inclusion and exclusion principle bit strings of length eight either start with a
1 bit or end with the two bits 00 = 128 + 64 - 32 = 160
Example2:
A computer company receives 3S0 applications from computer graduates for a job
planning a line of new Web servers. Suppose that 220 of these people majored in
computer science, 147 majored in business, and Sl majored both in computer science and
business. How many of these applicants majored neither in computer science nor in
business.
Number of people majored in computer science= 220
Number of people majored in business = 147
Number of people majored in both = 51
Therefore Number of people majored either in computer science or business= 220 + 147 -51
= 316
Number of People majored neither in computer science nor business= 350 - 316 = 34
Example 3:
In a discrete mathematics class every student is major in computer science or
mathematics or both. The number of students having computer science as a major is 25;
the number of students having mathematics as a major is 13; and the number of students
-
· · in both computer science
maJonng
nd
are ill tbiS
cIass.? a mathematics isl8. How many ·students
How many positive integers are not exceeding 1000 are divisible by 7 or 11?
The number of positive integers not exceeding 1000 that are divisible by 7 IAI = 11000171
The number of positive integers not exceeding 1000 that are divisible by 1 I IBI = II 000/1 I I
The number of positive integers not exceeding 1000 that are divisible by 7 and 11 jAnBI =
/100017 x 11 /
TI1e number of positive integers not exceeding 1000 that are divisible by 7 or 11 jAUBI = IAI +
/B/-/AnB/
IAnBnq= 7
Therefore, there are seven students who have taken courses in Spanish, French, and
Russian
Example 7: Give a formula for the number of' elements in the union of' four sets.
IAUBUCUDI = IAI + IBI + ICI + !DI
-IAnBI - IAnq - IAnoI - IBnq -1Bno1 -1cno1
+ jAnBnq + jAnBnoI + 1Ancno1 + jBncno1
-IAnBncno1
Generating Functions
Consider a sequence of real numbers au, a,. a2, a3.... \el us denote the sequence by ar, where r =
0, 1, 2, 3, ...
Therefore ar == ao, a ,, a2. a3, a4. ...
Suppose there exists a function f{x) whose expansion in a series of powers of x is shown below
1
f(x) == ao.X0 + a1.XI + a2.x-+ · · · r '\
- - - - - - - -11., J
f(x) can also be written as ftx) ~) 0 to 1t ar_,,,f· .Jf t-i. ) -=- ~ tl.11 ,c.
Here f(x) is called as function for the sequence of ao, a 1, a2, a3 ....
Example 1: Find out the generating function of the given sequence 1, 1, 0, 1, 1, 1 ....
Given Sequence= 1, 1, 0, 1, 1, 1. ...
ao = 1, a 1= 1, a2 = 0, a3 = 1, 34 = 1, as = 1....
Generating function f(x) = aox0 + a1 x 1+ a2x 2 + a3 x3 + 34x4 + as x5 ...
Substitue the valuees ao = 1, a1 = 1, a2 = 0, a3= 1, 34 = 1, as= 1
f(x) = 1 x0 + 1 x 1+ 0x2 + 1 x3 + 1 x4 + 1 x5 . .•
= 1 + x + 0 + x 3 + x4 + x5 + x 2 - x 2 (Add and Subtract x 2)
= 1 + x + x2 + x3 + x4 + x5 -x2
f(x) = {l-xf 1 -x2
f(x) = 1/(1 -x) - x 2
1'"'' tnf ·K11 rn•o•finJ ton,C,n 'l jJ,, t1Wfl
f , - 1I 0 I - I I
1I - I - -
(1+1)
bct. ) :::. Qo t
0 L
, Cl, j. I f Qz l
l
f Q3,!. J f ~ ;t. "f __ _
~ ~v~
bc.1) ::::. , i of 2 '1- '+ , 'j., + .,_ 3 +; 1. 4_ _ _
1 ~
- -
(f-X)
(
2..
IP'\ ~ Tl'ld(J l,f ~ II -1. ; - ,, -
..., c,- - T ' I I -· -
tel) : :- llt1
Cl I
·t Q,.1 f-ct,. l
'2
+Of ;t.
J
t q,, i Lf- - -
~l~&ti f;. ,fu VO.U~
yx) =- I -l f (- 2) l I t ', (l 1
) 1 c-,o j ~ f- - - -
{1.o.m("- ,; : l1 I " I Lf I ~ I LI
- Ci( l-1.)-•
- tJ
tCV
- '
--
0 - l)
de
11 , - ,, , o1 c: 6, a1 ·~ a,, 1C 1
I( l l
Vo&,tB
4
61 -f ~
t I 2
?1 +- "f 1 1 J. J --I IO l .
b(l ) :::=
t ( I -X )-' lv
~
~ / ,J .
IJt. ~T ,' ·O I O I 0 I 2 I t.f J ' J q I IOJ - - - -
\.. 1 - - .
o+ o+ o + 2t +~ ;;' f +btx."t - -·
3
===
2:t.
1
ft t j &f X 'f -- -
:::. 21
3
(If it +3lX t~Sl t- --) 2 3
- 2-
( 1- X)
') q . ·1 1 (,,
• I 1 1
~ I
;:- I 1.. ~ ( -
C
3 ),
f
f q (1 1
) + (. '? f ) '). /
4 0I( I )
~ I - 3-X +q X 1 _ 2 J. t:
1 +'o I 'J. 'f 1
_,
::: ( I t 5X)
b<X) - -
( I f-- 3.I)
( lr' Ff:J..'J.)
lt\!1'('U ft, I
', 1 1, w ,11.,~ ,
1 ~
l l \ (kl
(
f ll, "/. f
'
Q) '( f fl,J 1 I- --
f 2 ~ 1 ~ -I - -
I 1
,:., l r I 11 J f IV X
3
~ ( 1t I ) t (If 3) l. t ( It 9 ) X. 2 f- (f t ? t) t ·f - -
-
1
(r+- 1l+ 1+3 .r +-x tq x
2 +-x 3+ i l-x. 3
3
- '+- 1. t- 'X J +-x' +- -- + 1+ 31 r qx i t- ?. t:x
-I _,
to; - (f- XJ + U- 3:x )
{C t ) - -I +- - I
(1- i) ( f - '3:t)
-e1trunt{
2. j
&
I).. f fj :t f lo J.-
I
t tr; 1, - - -
•
t6
nl I
'f\,I ( n _qv)~
(1N111lt 1 : ,' ,, I "II I {f., 11
' ur, f, rt lr,1
1/ \
' \j
n n-1 () -) (I -',
·1
n r
I z' 1 nc
'2
C I '.X,
0
-t nc
I 7.
I l + nr3 1 J.
n< nc
(J I I I
3
- :; (1+1)
1 ~1 , ~ ::;; t.. , n~3
3 nf n-'1- 3-o o 3~1 1 3 - 2. -i ~- · 3
(3t :t.J :::: t 3 1.~5l 3 1. t 3c 3 ,., +- 3c 3 1- r 'r 'l
1
rn~o c 1 2 ~
2. j
= fii'f -t -~t1xt3X3.'.l tl 1
::: t'}f- 2.};( f.q .X
1
.f<t 3
I ~, '. / (. ) '
'( t z.
I 3
. .. ~
(' I
f 1
-- ---
II
+ J
7~
1' 1- ~ ~ -- -
,_-
3I
:l o
+ (?1 )'J., + (_Z-;r.)+'J
I
c =- (7 X) t 0 J. )
-C'/ ---I(- ---zl.- _,__.
9, /.
_ _,
l j 3
H- 'tX+ - ii +-
-
L1j
3
} 3,:
initial value.
Step l(Ba se step): It proves that a statement is true for the
i.e, P(I) = True
LHS: = (n 2 + n) / 2 + (n + 1)
= (n 2 + n + 2n + 2) /2
= (n 2 + 3n + 2)/2
= (n + I ) (n + 2) /2
Example 3: Show that if n is a positive integer, then ]+ 3+ Y+ ___ 3(n-J) = (3" -1)/2 using
Mathematical Induction.
= (3"+1-1) /2
LH S == RH S ; Th us Proved
e 2" = 2n+I -1
Basic Step: P ( 1) is true bec aus
1= 1
is tru e
Inductive Step: As sum e P (n)
l+ 2+ 22+ .. .2" = 2n+I -1
e
be sho wn tha t P (n + 1) is tru
Un der this ass um pti on it mu st
------------ -------------- (l)
P (n): l+ 2+ 22+ ... 2n = 2n+I -1---------
l + 2+ 22+ ... 2" + 2° = 2°
11 1111
-1----------------------- (2)
P (n + 1)
equation 2
Now Show that LHS = RHS in
LHS: = 2. zn+i -1
= 211+ 1+ 1 -1
= 2n+2 -1
LHS = RHS; Thus Proved
your conjecture using mathematical induction.
I =l
1+3 = 4
]+3+5 = 9
1+3+5+7= 16
1+3+5+7=25
2
TI1erefore the conjecture is 1+3+5+7 .......+ (2n-1) == n
== (n+l)2
Let the time taken to complete the whole problem be T(N), time taken to complete nl, n2, n3,
n4 respectively be T(nl ), T(n2), T(n3) and T(n4), time taken in dividing the problem into sub-
problems be D(N), time taken to combine the solutions of sub-problems into one final solution
be C(N).
Then,
T(N) = T(nl) + T(n2) + T(n3) + T(n4) + D(N) + C(N)
The General format of Recurrence Relation for Divide and Conquer algorithm
The Problem P is divided into P1 and P2
T (n) = T (n/2) + T (n/2) + f(n)
T (n) = 2T (n/2) + f (n)
Replace 2 by a and b = T (n) = aT (n/b) + f (n)