Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views46 pages

UNIT-5 Counting and Discrete Probability

Unit 5 covers counting and discrete probability, focusing on combinatory techniques essential for solving counting problems in mathematics and computer science. Key principles include the Sum Rule, Product Rule, and the Pigeonhole Principle, which help in determining the number of ways to perform tasks or distribute objects. The section also discusses permutations and provides various examples to illustrate these concepts in practical scenarios.

Uploaded by

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

UNIT-5 Counting and Discrete Probability

Unit 5 covers counting and discrete probability, focusing on combinatory techniques essential for solving counting problems in mathematics and computer science. Key principles include the Sum Rule, Product Rule, and the Pigeonhole Principle, which help in determining the number of ways to perform tasks or distribute objects. The section also discusses permutations and provides various examples to illustrate these concepts in practical scenarios.

Uploaded by

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

Unit- 5 Counting and Discrete Probability

Combinatory is that branch of discrete mathematics which concerns with counting problems. Technique
for counting is important in mathematics and computer science, especially in probability theory and in the
analysis of algorithms.
For instance, counting is required to determine whether there are enough telephone numbers or internet
protocol addresses to meet demand, it is also used to determine the complexity of algorithms, counting
techniques are used extensively when probabilities of events are computer.
Counting problems arise throughout mathematics and computer science. For example, we need to count
the number of key operations used in algorithm to study its time complexity
Sum Rule Principle
If a task can be done in either in one of n1 ways or in one of n2 ways, where none of the set of n1
ways is the same as any of the set of n2 ways, then there are n1+n2 ways to do the task.
Example 1: If there are 24 boys and 18 girls in a class, find the number of ways of selecting one student
as class representative.
Solution: Using sum rule, there are 24+18 = 42 ways of selecting one student as a class representative
Example 2: Let E be the event of choosing a prime number less than 10, and F be the event of choosing
an even number less than 10, find the number of ways that E or F can occur.
Solution: E can occur in 4 ways [2,3,5,7] and F can occur in 4 ways [2,4,6,8]. However, Both can occur
in 1 ways. Hence total number ways E or F can occur in 4+4-1 = 7 ways.
Example 3: A student can choose a computer project from one of three lists. The three lists contain 23,
15 and 19 possible projects respectively. How many possible projects are there to choose from?
Solution: The student can choose a project from first list in 23 ways, from the second list in 15 ways, and
from the third list in 19 ways. Hence, there are 23+15+19 = 57 projects to choose from.
Example 4: How many ways we can get a sum of 4 or 8 when two distinguishable dice are rolled?
Solution: Since dice are distinguishable outcome (1,3) is different from (3,1) to get 4 as sum. We have
the pairs (1,3),(3,1),(2,2) so total of 3 ways. And similarly getting 8 can be from pairs (2,6),(6,2),
(3,5),(5,3),(4,4), so total of 4 ways. Hence getting sum of 4 or 8 is 3+5 =8 ways.

Product Rule Principle


Suppose that a procedure can be broken down into a sequence of two tasks. If there are n1 ways to
do the first task and for each of these ways of doing the first task, there are n2 ways to do the
second task, then there are n1*n2 ways to do the procedure.
Example 1: A office contains 27 floors and has 37 offices on each floor. How many offices are there are
in the building?
Solution:
No of floors in the office =27
No of offices in each floor = 37
Therefore, by the product rule there are 27.37 = 999 offices in the building.
Example 2: How many different three-letter initials with none of the letters can be repeated can people
have?
Solution: Here the first letter can be chosen in 26 ways, since the first letter is assigned we can choose
second letter in 25 ways, and in the same manner we can choose third letter in 24 ways. So by product
rule number of different three letter initials are 26.25.24 = 15600

1
Example 3: Three persons enter into a car where there are 5 seats. In how many ways can they take up
their seats?
Solution: The first person has a choice of 5 seats and can sit in any one of these five seats. So there are 5
ways of occupying the first seat. The second person has 4 ways to take seats and third person has 3 ways
to take seats.
Hence total number of ways in which all the three persons can sit is 3.4.5 = 60
Example 4: Suppose that plate contains two letters followed by three digits with first digit not zero. How
many different license plates can be printed?
Solution: Each letter can be printed in 26 different ways, the first digit in 9 ways and each of the other
two digits in 10 ways. Hence
26*26*9*10*10 = 608400 different plates can be printed.
Example 5: There are 32 microcomputers in a computer center. Each microcomputer has 24 ports. How
many different ports to a microcomputer in the center are there?
Solution: The procedure of choosing a port consists two tasks, first picking a microcomputer and the
picking a port on this computer. Since there are 32 ways to choose the micro-computer and 24 ways to
choose the port no matter which microcomputer has been selected. Using product rule, there are 32.24 =
768.
Example 6: How many ways can an organization containing 26 members elect a president, treasurer and
secretary (Assume no person is elected to more than one position)?
Solution: The president can be elected in 26 different ways, the treasure can be elected in 25 different
ways and following this, the secretary can be selected in 24 different ways. Thus, there are 26.25.24 =
15600 different ways in which the organization can select a president, a treasure and a secretary.
Example 7: How many strings are there of four lowercase letters that have the letter x in them?
Solution: There are total 26.26.26.26 strings of four lowercase letters, by product rule. In the same way,
we can say that there are 25.25.25.25 strings of lowercase letters without x. So there are total of
26.26.26.26-25.25.25.25 = 66351
Pigeonhole Principle
The pigeonhole principle states that if k+1 or more pigeons are placed into k pigeonholes then there is at
least one pigeonhole containing two or more of the pigeons.
Proof: We use proof by contradiction here. Suppose that k+1 or more boxes are placed int k boxes and no
boxes contain more than one object in it. If there are k boxes then there must be k objects such that there
are no two objects in a box. This contradicts that our assumption. So there is at least one box containing
two or more of the objects.
Example 1: Among any group of any 367 people, there must be at least two with the same birthday
because there are only 366 possible birthdays.
Example 2: In any group of 27 English words, there must be at least two that begin with the same letter,
because there are 26 letters in the English alphabet.
Example 3: How many students must be in a class to guarantee that at least two students receive the
same score on the final exam, if the exam is graded on a scale from 0 to 100 points.
Solution: There are 101 possible scores on the final. The pigeonhole principle shows that among any 102
students there must be at least 2 students with the same score.

Theorem: The Generalized Pigeonhole Principle


If N objects are placed into k boxes, then there is at least one box containing at least |N/k| objects.

2
Proof: We will use a proof by contradiction. Suppose that none of the boxes contain more than |N/k|-1
objects. Then, the total number of objects is at most
K(⌈N/k⌉-1)<k((N/k+1)-1) = N.
Where the inequality ⌈N/k⌉<(N/k)+1 has been used. This is contradiction because there total of N objects.

A common type of problem asks for the minimum number of objects such that at least r objects of these
objects must be in one of k boxes when these objects are distributed among the boxes. When we have N
objects, the generalized pigeonhole principle tells us there must be at least r objects in one of the boxes as
long as ⌈N/k⌉≥r. The smallest integer N with N/k>r-1, namely N = k(r-1)+1, is the smallest integer
satisfying the inequality ⌈N/k⌉≥r. Could a smaller value of N suffice? The answer is no, because if we
have k(r-1) objects, we could put r-1 of the them in each of the k boxes and no box would have at least r
objects.
Example 1: Among 100 people there are at least ⌈100/12⌉=9 who were born in the same month.
Example 2: What is the minimum number of students required in a discrete mathematics class to be sure
that at least six will receive the same grade, if there are five possible grades A, B, C, D and F?
Solution: The minimum number of students needed to ensure that at least six students receive the same
grade is the smallest integer N such that ⌈N/2⌉ = 6. The smallest such integer N = 5.5+1 = 26. If you
have only 25 students, it is possible for there to be five who have received each grade so that no six
students have received the same grade. This, 26 is the minimum number of students needed to ensure that
at least six students will receive the same grade.
Example 3: How many cards must be selected from a standard deck of 52 cards to guarantee that at least
three cards of the same suit are chosen?
b)How many must be selected to guarantee that at least three hearts are selected?
Solution: Suppose that there are four boxes, one for each suit, and as cards are selected they are placed in
the box reserved for cards of that suit. Using generalized pigeonhole principle, we see that if n cards are
selected, there is at least one box containing at least ⌈N/4⌉ cards. Consequently, we know that at least
three cards of suit are selected if ⌈N/4⌉≥3. The smallest integer N such that ⌈N/4⌉≥3 is N = 2*4+1=9, so 9
cards are suffice.
Note that is eight cards are selected, it is possible to have two cards of each suit, so more than eight cards
are needed. Consequently, nine cards must be selected to guarantee that at least three cards of the same
suit are chosen. One good way to think about this to note than after the eighth card is chosen, there is no
way to avoid having a third card of some suit.
b) We do not use the generalized principle to answer this question, because we want to make sure that
there are three hearts, not just three cards of one suit. Note that in the worst case, we can select all the
clubs, diamonds, and spades, 39 cards in all before we select a single, heart. The next three cards will be
all heart, so we may need to select 42 cards to get three hearts.
Example: If 9 books are to be kept in 4 shelves the show that there is one shief which contains 3 books.
Solution: The nine books can be thought of as pigeons and four shelves can be thought of as pigeonholes.
Then n=4 and kn+1=9
Therefore, k*4+1=9 or k=2
So at least 1 pigeonhole ie shief is occupied by k+1=3 pigeons or books.
Example 2: If a class has 24 students, what is the maximum number of possible grading that must be
done to ensure that there is at least two students with the same grade?

3
Solution: There are 24 students. Let k be the maximum number of grades. Then by pigeonhole principle,
ceil (24/k)=2
or Here the largest value that k can have is 23 since 24 = 1.23.+1
So, maximum number of possible grading to ensure that at least two of the students have same grading is
23.
Example 3: What is the maximum number of students required in a class to be sure that three of them are
born in the same month.
Solution:
Here n=12 months are pigeonholes and k+1=3 are pigeons are born in the same month. Then k+1=3 gives
k=2.
Thus kn+1=2*12+1=25

Permutations
Many counting problems can be solved by finding the number of ways to arrange a specified number of
distinct elements of a set of particular size, where the order of these elements matters. Many other
counting problems can be solved by finding the number of ways to select a particular number of elements
from a set of a particular size, where the order of the elements selected does not matter. For example, in
how many ways can we select three students from a group of five students to stand in line for a picture?
How many different committees of three students can be formed from a group of four students?
Permutation: A permutation of a set of distinct objects is an ordered arrangement of these objects. We
also are interested in ordered arrangements of some of the elements of a set. An ordered arrangement of r
elements of a set is called an r-permutation.
Theorem
If n is a positive integer and r is an integer with 1≤r≤n then there are
p(n,r) = n(n-1)(n-2)……(n-r+1) r-permutations of a set with n distinct elements.
𝑛!
Corollary: If n and r are integers with 0≤r≤n then P(n,r) = (𝑛−𝑟)!
Example 1: Show that (n-r+1) .nPr-1 = nPr
Solution:
LHS = (n-r+1)nPr-1
𝑛!
= (n-r+1)*[𝑛−(𝑟−1)]!
𝑛!
=(n-r+1)*[𝑛−𝑟+1]!
𝑛!
= (n-r+1)*(𝑛−𝑟+1)∗(𝑛−𝑟)!
= n!/(n-r)!
=nPr
Example 2: If 56Pn+6 :54Pn+3 = 30800:1 then find n
Solution:
𝑛!
We have nPr = (𝑛−𝑟)!
56 56!
So Pn+6 = (56−𝑛)!
Similarly,
54 54!
Pn+3 = (50−𝑛)!

4
Now, given,
56 56! 54!
Pn+6: 54Pn+3 = :
(56−𝑛)! (50−𝑛)!
= 30800:1
n = 41
Example 3: How many license plates consisting of 3 digits can be made out of given integers 3,4,5,6,7?
Solution: This is just like arranging 3 objects out of 5 objects, So we have,
P(5,3) = 5!/(5-3)! = 60
The problem can also be solved by product rule.
Example 4: How many number of 3 digit can be formed from the digits 3, 4,5, 6, 7, 8? How many of
these are divisible by 5.
Solution: Here, n=6, r=3
Therefore P(6,3) = 6!/(6-3)! = 120
To find the number divisible by 5, we fix digit 5 on unit place
Therefore n = 6-1 = 5 and r = 3-1 = 2
Therefore P(5,2) = 5!/(5-2)! = 20
Example 5: Find the number of ways in which a party of seven persons can arrange themselves (a) in a
row of seven chairs (b) around a circular table.
Solution:
(a) The seven persons can arrange themselves in a row in 67.6.5.4.3.2.1 = 7! Ways which is P(7,7)
(b) One person can sit at any place in circular table. The other six persons can then arrange
themselves in 6! Ways around the table
Example 6: In how many ways can 4 girls and 4 boys be arranged alternatively on a round table?
Solution: First let all the girls i.e. 4 girls can be arranged in (4-1)!=3 ! Ways. But 4 boys between the girls
can be arranged in 4! Ways since a girl is already been fixed. Hence, 4 girls and 4 boys can be arranged
alternatively on a round table is 3!*4! Ways.
Example 7: In how many ways can 8 people be seated (a) in a row of 8 chairs (b) around a circular table
if two people insist on sitting next to each other?
Solution: If two people insist on sitting next to each other, we consider two people as one. Then 7 people
can be arranged in a row in 7! Ways. But two people can interchange their position in 2 ways.
Therefore total number of arrangements = 2*7! = 10080 ways.
(b)Similarly we consider two people as one. Then 7 people can be arranged in a round table in (7-1) !
ways i.e 6! ways. But two people can interchange their positions in 2 ways.
Therefore, total number of arrangements = 2*6! = 1440.
Permutations with Repetitions
The permutations of n objects taken all at a time when there are p objects of one kind, q objects are of
𝑛!
second kind, r objects are of third kind, is 𝑝!𝑞!𝑟!
Example 8 How many sever-letter words can be formed using the letters of word “BENZENE”?
Solution: There are seven letters of which there are three Es and two Ns. Therefore, the number of
7!
permutations is = 420
3!2!
Example 9: How may six-letter words can be made using the letters of the word “SUNDAY”
6!
Solution: There are six-letters of which none is repeated. Therefore, the number of permutations is 0!
=6.5.4.3.2.1=720
Example 10: Find the followings

5
a. In how many ways can the letters of the word “arrange” be arranged?
b. In how many ways can the letters of the word “arrange” be arranged so that the two rs always
come together?
c. In how many ways the letters can be arranged so that two rs never come together?
Solution:
a. There are 7 letters in which there are 2 a’s’ and two r’s’.
So, total number of alphabet to be arranged n = 7
Number of repetitions of a (p) = 2
Number of repetitions of r (q) = 2
𝑛! 7!
Therefore, total number of arrangements = 𝑝!𝑞! = 2!2! = 1260
b. For the case when two t’s’ always come together, we consider two r’s as a single one. Then the
word “arrange “ becomes “aRange”. So there are 6 letters including two as
Total number of arrangements = 6!/2! = 360! Ways.
c. The total number of arrangements of letters of the word ‘arrange’ is 1260 and the total number of
arrangements of the word ‘arrange’ where two r ‘s’ always come together is 360. So the total
number of arrangements of the word ‘arrange’ where two r’s never come together is (1260-360) =
900 ways.
Example 11: Find the following
a. Find the number of permutations that can be formed from the letters of the word “ELEVEN”
b. How many of the them begin and end with E?
c. How many of them have the three Es together
d. How many of them never have the three Es together?
e. How many of them begin with E and end with N?
Solution:
a. There are 6 letters of which three are Es. So, total number of alphabet to be arranged n = 6
Number of repetition of E (p) = 3
6!
Therefore total number of permutations = = 120
3!
b. When E is fixed at first and last position, then remaining 4 letters can be filled in 4! ways. That is
in 24 ways.
c. For the case when three Es come together, we consider three Es as one E. Then there are only
four letters E, L, V and N. So, four letters can be arranged in 4! = 24 ways
d. Since the total number of permutations of the letters of the word “ELEVEN” is 120 and the
number of permutations of the letters of word ELEVEN if 3 Es always come together is 24 then
the number of permutations of the letters of the word ELEVEN when 3 Es never come together is
(120-24) = 96
e. When first position is fixed with E and last position is fixed with N then there are 4 positions to
be filled with 4 letters of which there are 2 Es. Now permutations of the 4 letters in which two are
Es is = 4!/2! = 12.
Example 12: Find the number of permutations of the letters in the word “COMPUTER” taken four at a
time in which
a. Two letters M and R do not occur
b. Two letters M and R always occur
Solution:

6
a. From the word “COMPUTER”, if two letters M and R do not occur then the number of
permutations = P(6,4) = 360
b. If two letters M and R always occur, the number of permutations = P(6,2)*2 = 60
Example 13: A library has 5 copies of one book, 4 copies of each of two books, 6 copies of each of 3
books and single copies of 8 books. In how many ways can all the books be arranged?
Solution: Here,
First book has 5 copies = 5 copies
Second and third books has 4/4 copies = 4*2 = 8 copies
Fourth, fifth and sixth books has 6/6 copies = 18
Next 8 type of books has 1/1 copy = 1*8 = 8 copies
Total number of books = 5+8+18+8=39
This is a case of things not all different
39!
The total number of ways in which all the books can be arranged = 5!4!4!6!6!6! ways
Circular Permutation
The number of ways of arranging n unlike objects in a ring when clockwise and anticlockwise
arrangements are different is (n-1)!. For example, consider 4 people A,B,C and D who are to be seated at
a round table. To find the number of different arrangements, we fix A and then consider the number of
ways of arranging B, C and D. Therefore the number of different arrangements of 4 people around the
table is 3!.
The number of ways of arrangement n unlike objects in a ring, when clockwise and anticlockwise
arrangement are same and is (n-1)!/2.
Example 14 : In many ways can the numbers on a clock face be arranged?
Solution: In a clock face there are 12 numbers. So they can be arranged in (12-1)! = 11 ways.
Example 15: In how many ways can 6 boys be seated in a round table of 6 seats so that two particular
boys always come together?
Solution: There are 6 boys and 2 boys come together so, two boys are considered as one
Therefore 5 boys are sitting in a round table of 5 seats.
Arrangement of 6 boys in a round table = (5-1)!=4! = 24
But two boys can take their seats in P(2,2) ways.
Therefore P(2,2) = 2!/(2-2)! = 2*1 = 2
Total no of arrangement = 24*2 = 48 ways
Example 15: Find the number of ways in which 8 different beads can be arranged to form a necklace.
Solution: If we fix the position of one beads, the remaining of beds can be arranged in 7 ! ways but there
is no distinction between the clockwise and anticlockwise arrangements
Therefore, the required number of arrangement = ½(n-1)! = (8-1)!/2
= ½ *7! = 2520
Repeated Use of the Same Objects
The number of distinct arrangements of n objects taken r at a time with repetition is n r
Example 16: In how many ways can a garland of 15 different flowers be made?
Solution: The arrangement of 15 different flowers to make a garland, in both clockwise and
anticlockwise direction is same. So, they can arranged in (15-1)/2 = 14!/2 ways
Example 17: How many license plates consisting of 3 digits can be made if repetition is allowed?

7
Solution: As repetition is allowed, first digit can be chosen in 10 ways. Second digit can be chosen in 10
ways and similarly third digit can also be chosen in 10 ways. So, 3 digit license plates can be made in
1000 ways

Combination

Combination of objects means just their collection without any regard to order or arrangement. An
unordered selection of r objects from a set of n objects is called a combination or r-combination. It is
denoted by C(n,e) or nCr and is given by the expression.
𝑛!
C(n,r) = 𝑟!(𝑛−𝑟)!
Example 18: Calculate the value of C(12,10)
12!
Solution: C(12,10) = 10(12−10)! = 66 ways
Example 19: In how many ways can a hand of 4 cards be dealt from an ordinary pack of 52 playing
cards?
Solution: We need to consider combinations, since the order in which the cards are dealt is not
important.
52!
Now, C(52,4) = 4!(52−4)! = 270725 ways.
Example 20: In a meeting, everyone had shaken hands with everyone else. It was found that 66
handshakes were exchanged. How many members were present at the meeting?
Solution: Let the number of members present at the meeting be ‘n’. Any two members can make one
handshake.
Therefore the number of handshakes that can be made by n members = nC2
By the given conditions
n
C2 = 66
𝑛!
Or (𝑛−2)!.2! = 66
𝑛(𝑛−1)(𝑛−2)!
Or (𝑛−2)!.2!
= 66
𝑛(𝑛−1)
2
= 66
Or n(n-1) = 132
Or n2-n-132=0
Or n2-12n+11n-132=0
Or n(n-12)+11(n-12)=0
0r (n-12)+(n+11)=0
Or n=12 or n=-11
Therefore, number of members = 12

Example 21: Consider the set {a, b, c, d}. In how many ways can we select two of these letters
(repetition is not allowed)
i. Order matters
ii. Oder does not matter
Solution:

8
Example 22: A committee is to be chosen from 12 men and 8 women and is to consist of 3 men and 2
women. How many different committees can be formed?
12!
Solution: 3 men can be chosen from 12 men = C(12,3) = 3(12−3)!
= 220
8!
2 women can be chosen from 8 women in C(8,2) = 2(8−2)! = 28
Hence the total number of different committees possible is
220*28 = 6160
Example 23: A bag contains six while marbles and five red marbles. Find the number of ways four
marbles can be drawn from the bag if
a. They can be any color
b. Two must be white and two red
c. They all must be of the same color
Solution:
a. Here, total number of marbles is 11. The four marbles can be chosen from 11 marble in C(11,4)
11!
ways in C(11,4) ways = = 330
4(11−4)!
b. Two white marbles can be chosen in C(6,2) ways and two red marbles can be chosen in C(5,2)
ways. Thus there are C(6,2).C(5,2) ways of drawing two white marbles and two red marbles.
6! 5!
Therefore C(6.2).C(5,2) = 2(6−2)! ∗ 2(5−2)! = 150
c. There are C(6,4) = 15 ways of drawing four marbles where there are n1 indistinguishable objects
of four red marbles. Thus there are 15+5 = 20 ways of drawing four marbles of the same color.
Permutations with Indistinguishable Objects
The number of different permutations of n objects, where there are n1 indistinguishable objects of type 1,
n2 indistinguishable objects of type 2…….and nk indistinguishable objects of type k is
𝑛!
𝑛1! 𝑛2! 𝑛3! … … 𝑛3!
Example 24: How many different strings can be made by recording the letters of the word SUCCESS?
Solution: Because some of the letters of SUCCESS are the same, the answer is not given by the number
of permutations of seven letters. This word contains three Ss, two Cs and one U and one E. To determine
the number of different strings that can be made by reordering the letters, first note that the three Ss can
be placed among the seven positions in C(7,3) different ways, leaving four positions free. Then the two
Cs can be placed in C(4,2) ways, leaving two free positions. The U can be placed in C(2,1) ways, leaving
just one position free. Hence, E can be placed in C(1,1) way. Consequently, from the product rule, the
number of different strings that can be made is
C(7,2).C(4,2).C(2,1).C(1,1) = 240
Binomial Theorem
Let x and y be two variables and n be non-negative integers then the binomial theorem for positive index
n states that
(x+y)n = C0(n,0)xn+C1(n,1)xn-1y1+C2(n,2)xn-2y2+………………….+Cn(n,n)yn
The coefficient C0, C1, C2…Cn are called binomial coefficients.
General Term
The (r+1)th term in the expansion of (x+y)n is usually called its general term which is denoted by t r+1
In the expansion of (x+y)n
t1 = 1st term = C(n,0)xn

9
t2 = 2nd term = C(n,1)xn-1y1
t3 = 3rd term = C(n,2)xn-2y2
t3 = 4th tem = C(n,3)xn-3y3
….
tr+1 = (r+1)th term = C(n,r)xn-ryr.
Thus, the general term in the expansion of (x+y)n is tr+1 which is C(n,r)xn-ryr
Example 25: Expand (2a+5)5 by the binomial theorem
Solution: here n=5
By using binomial theorem,
(2a+5)5 = C(5,0)(2a)5+C(5,1)(2a)5-1(5)1+C(5,2)(2a)5-2(5)2+C(5,3)(2a)5-3(5)3+C(5,4)(2a)5-4(5)4+C(5,5)(2a)5-
5
(5)5
= 32a5+400a4+2000a3+5000a2+6250a+6250
Example 26: Find the coefficient of the term containing y8 in the expansion of (x+3y 2)17
Solution: The term containing y8 in the expansion of (x+3y2)17 is C(17,4)x17-4 (3y2)4 = 2380x13.81y8
The coefficient of the term containing y8 in the expansion (x+3y 2)17 = 192780
Example 27: Find the coefficient of x16 in the expansion of (2x2-x/2)12
Solution:
Comparing (2x2-x/2)12 with (x+y)n we get, x = 2x2 , y = x/2 and n=12
The general term in the expansion of this expression by binomial theorem is
tr+1 = C(12,r)(2x2)12-r (-x/2)r
= C(12,r)212-r(-1/2)r x2(12-r)+r
= C(12,r)212—2r(-1)r x24-r
Then the coefficient of x16, we put 24-r = 16 thus r=8
Then the coefficient is C (12, 8)212-16.(-1)8
= C (12,8). (1/2)4
495/16
Example 28: Find the general term in the expansion of (x2+a2/x)5
Solution:
Comparing (x2+a2/x) 5 with (x+y)n we get x = x2, y = a2/x and n=5
Since the general term in the expansion of (x+y)n is tr+1 = C(n,r)xn-r yr, the general term in the expansion
of (x2+a2/2) is tr+1 = C(5,r)(x2)5-r (a2/x)r
= C(5,r)x10-2r a2r/xr
= C(5,r)x10-3ra2r
To get the coefficient of x
Let 10-3r = 1
Or r=3
Therefore tr+1 = t3+1 = t4 = C(5,3)xa 2*3
= C(5,3) xa6

Example 29: Find the term independent of x in the expansion of (2x+1/x2)9


Solution: Comparing (2x+1/x2)9 with (x+y)n we get x = 2x, y = 1/x2 and n=9
Since the general term in the expansion of (x+y)n is tr+1 = C(n,r)xn-ryr, then the general term in the
expansion of (2x+1/x2)9 is

10
tr+1 = C(9,r)(2x)9-r (1/x2)r
tr+1 = C(9,r)29-r .x9-r .(1/x2r)
tr+1 = C(9,r) (2)9-r x9-3r
To get the term which is independent of x we must have
9-3r = 0
Or r=3
tr+1 = t3+1 = t4 = C(9,3) (2)9-3 x0 = 5376, is the term independent of x.
Example 30: Find the 7th term of (x+1/x)10
Solution:
Comparing (x+1/x)10 with (x+y)n we get x = x and y = 1/x and n=10
The general term tr+1 of the expansion (x+1/x)10 is,
tr+1 = C(10,r) x10-r .(1/x)r
= C(10,r)x10-r (1/x)r
=C(10,r)x10-2r
To get t7, we put r=6 in tr+1 then
t6+1 = t7 = C(10,6)x10-2.3
10!
t7 = 6!(10−6)! x-2
210
t7 = 𝑥2
Middle Term
Now let us find the middle term or terms in the expansion of (x+y)n. we have to consider the case when n
is even number and when n is odd number.
When n is even number: When n is even, the number of terms in the expansion of (x+y) n is n+1 which is
odd. So there is exactly one middle term which is t n/2+1
When n is odd: When is n is odd, the number of terms in the expansion of (x+y) n is n+1 which is even.
So there are two middle terms which are t(n+1)/2 and t(n+1)/2+1
Example 31: Find the followings
a. Find the middle term in the expansion of (2a+3x)30
b. Find the middle term in the expansion of (x-1/x)18
c. Find the middle term in the expansion of (1+x/2)15
d. Find the middle terms in the expansion of (2x+1/2x)15
Solution:
a. Comparing (2a+3x)30 with (x+y)n we get x = 2a and y = 3x, n=30. Here n=30, which is even so
there is only one middle term. Middle term = (t30/2)+1 = t15+1 = t16 = C(30,15)(2a)15.(3x)15
b. Here n=18 which is even. So there are (18+1) = 19 terms in the expansion of (x-1/x), which is
odd. Therefore there exists exactly one middle term which is t 18/2+1 = t10. Therefore t10 =
C(18,9)x18-9(-1/x)9 = -18/9!.9!
c. Here, the number of terms in the expansion is 15+1 = 16 which is even. So, there are two middle
terms. The middle terms are t(15+1)/2 and t(15+1)/2+1. i.e. t 8 and t9
15 𝑥7!
t8 = t7+1 = C(15,7)(1)15-7 (x/2)7 = 7!.8!27 =
15 𝑥8!
t9 = t8+1 = C(15,8)(1)15-8 (x/2)8 =
7!.8!28
d. Here, the number of terms in the expansion is 15+1 = 16 which is even. So, there are two middle
terms, which are t (15+1)/2 and t(15+1)/2+1 that is t8, and t9

11
t8 = t7+1 = C(15,7) (2x)15-7 (1/2x)7
15!
= 8!7! (2x)8-7
15!
= (2x)
8!7!
= t9 = t8+1 = C(15,8)(2x)15-8 (1/2x)8
15!
= 8!7!
(1/2x)
Pascal’s Triangle
The geometrical arrangement of binomial coefficients in the expansion of (x+y)n in a triangular form is
called Pascal’s triangle. This triangle array of numbers is called Pascal’s triangle.
The coefficients of the successive powers of a+b can be arranged in a triangular array of numbers which
can be shown as:
Coefficients in (a+b)0 1
1
Coefficients in (a+b) 1 1
Coefficients in (a+b)2 1 2 1
3
Coefficients in (a+b) 1 3 3 1
The terms in Pascal’s triangle have the following properties:
a. The first and last number in each row is 1
b. Every other number in the array can be obtained by adding the two numbers appearing directly
above it.
Example 32: Write down the expansion of (1+y)6 using Pascal’s Theorem
Solution: Here n = 6, so we use Pascal’s triangle up to n=6
When n=0 1
When n=1 1 1
When n=2 1 2 1
When n=3 1 3 3 1
When n=4 1 4 6 4 1
When n=5 1 5 10 10 5 1
When n=6 1 6 15 20 15 6 1
Example 33: Prove that C(n+1,r) = C(n,r-1)+C(n,r)
Solution
RHS = C(n,r-1)+C(n,r)
𝑛! 𝑛!
= (𝑟−1)!(𝑛−𝑟+1)!+
𝑟!(𝑛−𝑟)!
𝑛!.𝑟 𝑛!.(𝑛−𝑟+1)
= 𝑟(𝑟−1)!(𝑛−𝑟+1)!+ (𝑛−𝑟+1)𝑟!(𝑛−𝑟)!
𝑛!𝑟 𝑛!(𝑛−𝑟+1)
= 𝑟!(𝑟−1)!(𝑛−𝑟+1)!+ 𝑟!(𝑛−𝑟+1)!
𝑛!𝑟+𝑛!.(𝑛−𝑟+1)
= 𝑟!(𝑛−𝑟+1)!
(𝑛+1)!
= 𝑟!(𝑛−𝑟+1)!
C(n+1,r) = LHS
Proved
Generating Permutations and Combinations

12
Any set of n-elements can be mapped one to one with the set {1,2,3,…n}. We can find the permutation of
any set of n elements by generating the permutation of the n-smallest positive integers and then replacing
these integers with the corresponding elements.
To generate permutations of a set of a elements there are many algorithms. One of these algorithm is
lexicographic ordering of the set of permutations of {1,2,3,4..n}.
Algorithm
Given a natural number ‘n’ enlist n! Permutations of given n distinct objects say 1,2,3… in ascending
order.
Steps
1. Let C = 1, print first permutations of 1,2,3…n. If n=1 then go to set 3
2. For C = 2 to “Total Count”, Generate next permutation from permutation a 1,a2,a3…an by
following steps:
a. Scan the digits of given permutation from right to left and note first consecutive pairs (a n-
1 and an) such that a n-1<an
b. Search for the smallest digit among digits a m-1, am+2,….an that is longer than am call it x
c. Interchange am and X
d. Arrange all digits am-1 to an in increasing order as am+1<am+2<an
e. Print a1,a2, a3…….an
3. Stop

Example 1: Generate all permutations of 1, 2, 3 and 4


Solution:
1234 1243 1324 1342 1423 1432 2134
2143 2314 2341 2413 2431 3124 3142
3214 3241 3412 3421 4123 4132 4213
4231 4312 4321
Example 2: Generate the permutation of the set {Physics, Chemistry, Math, biology}.
Solution: To generate permutation of set S {Physics, Chemistry, math, biology} we first can generate the
permutation of the set [1, 2, 3, 4} and the maps
1. Physics
2. Chemistry
3. Maths
4. Biology
Generating Combination
Algorithm
[Select k objects of n distinct, say 1, 2, 3, 4…..n]
1. List all a-digit in ascending order
2. Select first k-digit , print them
3. J=1,2,3,… k be the index on k-elements
4. Assign maximum value to each jth position as n-k+J
5. Start scanning the list from right to left, stop at location where there are consecutive digits such as
an-1 <an. Let m = n-1. If no such pair formed, go to step 8
6. Leave the digits before am as they were, follow am by am+1, am+2…. And until k-digits in all
have been listed down such that no digit crosses the limit assigned as in step 4

13
7. Go to step 5
8. Stop
Example 1: Find the next layer 4-combinations of the set {1,2,3,4,5,6} and after {1,2,5,6}.
Solution: The last term among the terms ai with a1 = 1, a2 = 2, a3 = 5 and a4 = 6 such that a1 = 6-4+i is
a2 = 2;
To obtain the next layer 4-combination increment a2 by 1 to obtain a2 = 3. Then set a3 = 3+1 = 4 and a4
= 3+2 = 5. Hence, the next layer -4 combination is [1 3 4 5]

Discrete Probability
The word probability denotes chance and the theory of probability deals with laws governing the chances
of occurrence of phenomena, which are unpredictable in nature. The theory of probability was first
developed in the seventh century when certain gambling games were analyzed by the French
Mathematician Blaise Pascal. Probability theory today has many applications for beyond the games of
chance. Its utility is in almost all branches of Science, Engineering, Economics, Business, industry.
The theory of probability plays a vital role in making decisions in situation where there is a lack of
certainty.
Some definitions in probability theory
Random Experiment: An operation which can produce some well defined outcome is known as
experiment. An experiment whose outcome cannot be determined in advance in a random experiment. For
example, tossing a coin is an random experiment because if a coin is tossed then either head or tail will
turn up.
Example of random experiment is: Tossing a coin, throwing a die etc.
Sample Space: The set of all possible outcomes in a random experiment is called a sample space. Each
element of a sample space is called a sample point.
The number of sample points in S may be denoted by n(S).
For example, in the rolling of die, the sample space S = {1,2, 3, 4, 5, 6}
Event: The results or outcomes of experiments are called events. An event is subset of sample space. For
example, for the sample space in tossing two coins, a subset E = {HH, HT} is event. The number of
sample points in an event E is denoted by n(E).
Equally Likely Events: A number of events are said to be equally likely if any of them cannot be
expected to occur in preference to the other
Exhaustive Events: Events are said to be exhaustive when they include all possible outcomes of a
random experiment. In tossing a coin, exhaustive events are two
Mutually Exclusive Events: Two or more events are said to be mutually exclusive or disjoint if the
events cannot occur simultaneously. That is occurrence of one of the events prevents the occurrence of
others
Probability of Events
Every event associated with a random experiment is assigned a weight or measure of the change of it
occurring called its probability. The probability of an event E is denoted by P(E) and defined as
𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑜𝑢𝑡𝑐𝑜𝑚𝑒 𝑓𝑎𝑣𝑜𝑢𝑟𝑎𝑏𝑙𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑜𝑐𝑐𝑢𝑟𝑟𝑒𝑛𝑐𝑒 𝑜𝑓 𝐸 𝑛(𝐸)
P(E) = 𝑇𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑎𝑙𝑙 𝑝𝑜𝑠𝑠𝑖𝑏𝑙𝑒 𝑜𝑢𝑡𝑐𝑜𝑚𝑒𝑠
= 𝑛(𝐸)
The probability of non-occurrence of the event A is
𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑜𝑢𝑡𝑐𝑜𝑚𝑒 𝑢𝑛 𝑓𝑎𝑣𝑜𝑢𝑟𝑎𝑏𝑙𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑜𝑐𝑐𝑢𝑟𝑟𝑒𝑛𝑐𝑒 𝑜𝑓 𝐸 𝑛(𝑠)−𝑛(𝐸) 𝑛(𝐸)
= = = 1- = 1-P(E)
𝑇𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑎𝑙𝑙 𝑝𝑜𝑠𝑠𝑖𝑏𝑙𝑒 𝑜𝑢𝑡𝑐𝑜𝑚𝑒𝑠 𝑛(𝑆) 𝑛(𝑆)

14
Example 1: Three coins are tossed
a. Write the sample space S
b. Find the probability of all heads, at most two heads
Solution: Let S denotes the sample space of tossing three coins
(a) S = {HHH, HHT, HTH, THH, HTT, TTH, THT, TTT}
Therefore n(S) = 8
(b) Let E1 be the set of favorable events that all are heads
E1 = {HHH} and n(E1) = 1
Therefore P(E1) = n(E1)/n(S) = 1/8

Let E2 be the set of favorable events that at most two heads


E2 = {HHH, HTH, THH, HTT, TTH, THT, TTT} and P(E2) = 7
Therefore P(E2) = n(E2)/n(S) = 7/8

Example 2: Three electric bulbs are chosen at random from 15 bulbs of which 5 are defective. Find the
probability that: exactly one is defective, at least one is defective.
Solution: The number of ways of selecting one defective from 5 defective bulbs and two non-defective
from 10 non-defective n(E) = C(5,1)*C(10,2) = 2*45 = 225
Three bulbs can be chosen from 15 bulbs in
n (s) = C (15,3) = 15*14*13/(3*2) = 455 ways
Required probability = n (E)/n(s) = 225/455 = 45/91
Additional Principle
For any events A and B,
P(AUB) = P(A)+P(B) –P(A∩B)

Example: Suppose a student is selected at random 200 students, where 70 are taking C programming, 50
are taking Java and 20 taking both. Find the probability P that the student is taking C or Java.
Solution: Let C: Students taking C programming
J: Students taking Java
70
Therefore P(C) = 200
50
P(j) =
200
70
P(C∩J) =
200
Then P = P(CUJ) = P(C )+P(J) – P(C∩J)
70 50 20 1
= 200
+ 200 − 200 = 2

Example : Two dice are tossed once. Find the probability of getting an even number on first dice or a total of 8.

Solution: P(even number on Ist die or a total of 8) = P (even number on Ist die)+P (total of 8)= P(even number on
1st die and a total of 8)

∴ Now, P(even number on 1st die)=

15
Ordered Pairs showing a total of 8 = {(6, 2), (5, 3), (4, 4), (3, 5), (2, 6)} = 5

∴ Probability; P(total of 8) =

P(even number on Ist die and total of 8) =

∴ Required Probability =

Conditional Probability
Let E be an event in a sample space S with P(E)>0 then probability than an event A occurs once E has
occurred or specifically, the conditional probability of A given E, written as P(A/E), is defined as,
𝑃(𝐴∩𝐸)
P(A/E) = 𝑃(𝐸)

Example: What is the conditional probability that a randomly generated bit string of length four contains
at least two consecutive 0s, given that the first bit is a 1? (Assume the probability of a and a 1 are the
same).
Solution:
Let E be the event that a bit string of length four contains at least two consecutive 0s and F be the event
that the first bit is a 1. The probability that a bit string of length four has at least two consecutive 0s, given
that its first bit is a 1 equals P(E/F).
Without restriction the number of ways of bit string of length four can be formed with digits 0 and 1 is 2 4
= 16.
Keeping 1 fixed at the beginning, there are 8(23) bit strings of length four that starts with a 1. Thus P (F)
8 1
= = .
16 2
Again EF = {1000, 1100, 1001}
So, P(EF) = 3/16
Consequently
𝑃(𝐸∩𝐹) 3/16 3
P (E/F) = 𝑃(𝐹)
= 8/16 = 8

Example: Find the probability of drawing a heart on each of two consecutive draws from well shuffled-packs of
cards if the card is not replaced after the draw.

Solution: Let event A is a heart on the first draw, and event B is a heart on the second draw.

When we get a heart on the first draw, the second draw has 51 outcomes and 12 are favorable.

16
Example: A problem in Discrete Mathematics is given to three students whose chances of solving its are
½, 1/3, ¼ respectively. What is the probability that only one of them solves it correctly?
Solution:
Let A be the event that student A will solve the problem. Similarly B and C be the events for the students
B and C respectively, so solve the problem
Then P(A) = ½
P(B) = 1/3
P (C ) = ¼
P(Ac) = Probability that A will not solve the problem
1-P(A) = 1-1/2 = ½
Similarly
P( Bc ) = 1 - 1/3 = 2/3
And P(Cc) = 1-1/4 = ¾
The probability that none of the students A, B, C will solve the problem = P(A c).P(Bc).P(Cc)
½*2/3*3/4 = ¼
Hence, the required probability that the problem will be solved 1-1/4 = ¾
Independence
Events A and B in a probability space S are said to be independent if the occurrence of one of them does
not influence the occurrence of the other. In other words, B is independent of A if P(B) is the same as
P(B/A).
I.e Events are independent if P(A∩B) = P(A).P(B)
For example, in tossing of two coins, the appearance of head on one coin does not affect the appearance
of head on second coin.
Example: Suppose A is the event that a randomly generated bit string of length four begins with a 1 and
B is the event that this bit string contains an even number of ones. Are A and B independent, if the 16 bit
strings of length four are equally likely.
Solution: There are eight bit strings of length that begin with a one: 1000, 1001, 1010, 1011, 1100, 1101,
1110 and 1111
There are also eight bit strings of length four that contains an even number of ones: 0000, 0011, 0101,
0110, 1001, 1010, 1100, and 1111.
Because A B = {1111, 1100, 1010, 1001}, we that
P(A∩F) = 4/16 = ¼
Since P(A∩B) = ¼ = ½*1/2 = p(A).p(B)
Hence, A and F are independent

Random variable

17
Many problems are concerned with a numerical value associated with the outcome of an experiment. For
instance, we may want to know the probability that there are nine one bits generated when ten bits are
randomly generated. To study problems of this type we introduce the concept of random variables.
A variable whose numerical value is determined by the outcome of a random experiment is called a
random variable. A random variable X is a real valued function, X(x, of the elements of the sample space
S where x is an element of the sample space. Random variable assigns a real number to each possible
outcome. It should be noted that the range of the random variable will be a set of real numbers.
Example: If we toss a coin denote the head by 1 and tail by 0, then the random variable X takes only two
values 1 and 0. Symbolically, the random variable,
X(x) = {x: x= (0,1) ∈ S}
Expected Value and Variance
The expected value of random variable is the sum of overall elements in a sample space of the
product of the probability of the element and the value of the random variable at this moment.
The expected value of a random variable provides a central point for the distribution of the
values of this random variable.
Another useful measure of a random variable is its variance, which tells how spread out the
values of this random variable is:
Therefore, the expected value of the random variable X(s) on the sample space S is equal to
E(X) = ∑𝑠∈S 𝑃(𝑠)𝑋(𝑆)
Example: Let X be the number that occurs up when a die is rolled. What is expected value of X?
Solution: The random variable X takes the values 1, 2, 3, 4, 5 or 6. What is expected value of X?
The random variable X takes the values 1, 2, 3, 4, 5 or 6 each of them has probability 1/6
1 1 1 1 1 1 7
This results: E(X) = 6*1+6 ∗ 2 + 6 ∗ 3 + 6 ∗ 4 + 6 ∗ 5 + 6 ∗ 6 = 2
Example: An unbiased coin is tossed three times. Let S be the sample space of the eight possible
outcomes and X be the random variable that assigns to an outcome the number of tails in this
outcome. What is the expected value of X?
Solution: When an unbiased coin is tossed three times, the eight possible outcomes in sample
space are:
S = {HHH, HHT, HTH, THH, TTH, THT, HTT, TTT}.
Since coin is unbiased and toss is independent then the probability of each outcome is 1/8
Therefore E(x) = 1/8[X(HHH)+X(HHT)+X(HTH)+X(THH)+X(THT)+X(XTT)+X(TTT)
=1/8(0+1+1+1+2+2+2+3)
=12/8
=3/2
Example: Suppose an element X and list of n distinct real numbers are given as input then the
average case complexity of linear search algorithm is the probability that X is in the list is P and
it is equally likely that X is any of n element in the list.
Solution: The linear search algorithm locates and element X by successively comparing it to
each element in the list and terminates when X is located and when all the elements have
searched and it has been determined that X is not present in the list. 2i+1 comparisons are used if

18
X equals the ith element of the list and 2n+2 comparisons are used if X is not in the list. Then the
probability that X equals ai is p/n and probability that X is not in the list is q=1-p.
It follows that the average case complexity of linear search algorithm is:
3𝑝 5𝑝 𝑝
E= + 𝑛 +…..+(2n+1) 𝑛 +(2n+2)q
𝑛
𝑝
= 𝑛(3+5+….+(2n+1))+(2n+2)q
𝑝
= 𝑛((n+1)2-1)+(2n+2)q
= p(n+2)+(2n+2)q
Variance
The expected value of a random variable tells us its average but nothing about how widely its
values are distributed. So, the variance of a random variable helps characterize how widely a
random variable is distributed.
Let X be a random variable on a sample space S. The variance of X, denoted by V(X) is
V(X) = ∑𝑠∈𝑆(𝑋 (𝑆) − 𝐸 (𝑋)2𝑃(𝑆)

Example: What is the variance of the random variable X, where X is the number that comes up
when a die is rolled?
Solution: We have V(X) = E(X2)-E(X)2
The random variable X takes the values 1, 2, 3, 4, 5,or 6 each of them has probability 1/6.
1 1 1 1 1 1 21 7
This results: E(X): 6 . 1 + 6 . 2 + 6 . 3 + 6 . 4 + 6 . 5 + 6 . 6 = =2
6
1
Since X2 takes the values i2, i=1,2,3,4,5,6 each with probability 6.
It follows that
E(X2) = 1/6(12+22+32+42+52+62) = 91/6
91 7 2 35
Hence V(X) = -( ) =
6 2 12

Randomized Algorithm
An algorithm that uses random numbers to decide what to do next anywhere in its logic is called
Randomized Algorithm. For example, in Randomized Quick Sort, we use random number to
pick the next pivot
Example: Algorithm to find an element ‘a’ in an array of n elements.
Input: An array of n≥2 elements, in which half are ‘a’ s and the other half are ‘b’ s.
Output: To find ‘a’ in the array
There are two randomized algorithm to solve it
a. Las Vegas Algorithm
b. Monte Carlo Algorithm
Las Vegas Algorithm: Pseudo code
finding_LV(array A, n)
begin:
repeat

19
randomly select one element out of n elements until ‘a’ is found
end
Monte Carlo Algorithm
findingA_MC (array A, n, k)
begin:
i=0
repeat
randomly select one element out of n elements
i = i+1;
until i=k or ‘a’ is found
end
How to analyze Randomized Algorithm?
Some randomized algorithms have deterministic time complexity. For example, this
implementation of Karger’s algorithm has time complexity as O(E). Such an algorithms are
called Monte Carlo Algorithms and are easier to analyze for worse case
One the other hand, time complexity of other randomized algorithms (other than Las Vegas) is
dependent on value of random variable. Such randomized algorithms are called Las Vegas
Algorithms. These algorithms are typically analyzed for expected worst case. To compute
expected time taken in worst case, all possible values of the used random variable needs to be
considered in worst case and time taken by every possible value needs to be evaluated. Average
of all evaluated times is the expected worst case time complexity. Below facts are generally
helpful in analysis of such algorithms.

Advanced Counting
Recurrence Relation
Suppose a0, a1, a2, a3….an is a sequence. A recurrence relation for the nth term an is a formula
giving an in terms of some of all previous terms. To find the complete sequence, the rest few
initial conditions are needed. These initial values are called the initial conditions. If a recurrence
relation with initial conditions is given then we can write down as many terms of the sequence as
we want. If we just keep applying the recurrence.
The example, f0=1 and f1 = 1 are the initial condition with recurrence relation fn = fn-1+fn-2 for
n>2
The terms of sequence are 1, 1, 2, 3, 5, 8, 13 where each subsequent term is the sum of the
preceding two terms. On the other hand, if you are given a sequence, you may or may not be able
to determine a recurrence relation with initial conditions which describes it.

20
Example 1: If the given recurrence relation is an = an-1+an-2 with a0 = 3 and a1=5. Find the terms
a2 and a3
Solution: Here, an = an-1+an-2
Then, a2 = a1+a0 = 5-3=2
And a3 = a2+a1 = 2-5 = -3

Example 2: Find the recurrence relation with initial conditions of the sequence 3,8,13, 18…
Solution: Here, a1 = 5
a2 = a1+5 = 8
a3 = a2+5=13
a4 = a3+5 = 18
………………………
an = an-1+5
Hence, the recurrence relation is
an = an-1+5, n2, a1=3
Example 3: Find the recurrence relation of the sequence 2, 5, 11, 23, 47
Solution:
Here a1 = 2
a2 = 5 = 2*a1+1
a3 = 11 = 2*a2+1
a3 = 23 = 2*a3+1
…………………………..
a4 = 2an-1+1
Hence, the recurrence relation is a4 = 2an-1+1 with initial conditions a1 = 2, n≥2
Example 4: Find the recurrence of the sequence 1, 1, 2, 3, 5, 8, 13 ….
Solution:
Here a1 = 1
a2 = 1
a3 = 2 = a1+a2
a4 = 3 = a3+a2
a5 = a4+a3
………………….
an = an-1+an-2
Hence, the recurrence relation is
an = an-1+an-2 with initial conditions a1 = 1, a2 = 1 for n≥3
Solving recurrence Relations
If the given recurrence relation involving sequence a0, a1, a2….an then the solution of such
recurrence relation is to find an explicit formula for the general term a n
To solve the recurrence relation, we may replace each of an-1, an-2,…… by their predecessors.
This process continues until an explicit formula for nth term a n.

21
Example 5: Solve the recurrence relation an = 2n-1, n≥1 and a0=3
Solution:
a0 = 3
a1 = 2a0 = 2.3
a2 = 2a1 = 2(2.3) = 22.(3)
a3 = 2a2 = 2(22.3) = 23(3)
a4 = 2a3 = 2(23.3) = 24(3)
………………………………………….
an = 2n(3)
Hence, general solution for the given recurrence relation is an = 2 n(3)
Example 6: Solve the recurrence relation an = an-1 +2 subject to initial condition a1 = 3
Solution:
an = an-1+2 step 0
=(an-2+2)+2 step 1
=(an-3+2)+4 Step 2
=(an-4+2)+6 step 3
=(an-5+2)+8 step 4
=……………………………………
an = a1+2(n-1) step n-1
Example 7: Show that solution of Recurrence relation an = 2an-1- an-2 is an = 3n
Solution:
an = 2an-1-an-2
an = 2[3(n-1)-3(n-2)]
an = 2(3n-3)-3n+6
an = 6n-6-3n+6
an = 3n

Example 8: Find the first five term of sequence defined by a n = 6an-1, a0=2
Solution: Given an = 6an-1
Then a1 = 6a0 = 6*2 = 12
a2 = 6a1 = 6*12 = 72
a3 = 6a2 = 6*72 = 432
a4 = 6a3 = 6*432
Hence first five terms are: 2, 12, 72, 432, and 2592
Example 9: Find the first three terms of sequence define by a n = an-1+3an, a0 = 2, a1 = 2
Solution:
an = an-1+3an-2
a2 = a1+3a0 = 2+3*2 = 8
a3 = a2+3a1 = 8+3*2 = 14

22
Therefore three terms are 2,8,14

Example 10: Solve the recurrence relation an = an-1+4 subject to the initial condition a1 = 3
Solution:
Here, an = an-1+4, a1=1
a1 = 2
a2 = a1+4 = 3+4 = 7
a3 = a2+4 = 7+4 = 11
a4 = a3+4 = 11+4 = 15
a5 = a4+4 = 15+4 = 19

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 a 0,a1,…..an-1 for all integers n with n≥n0 where n0 is a non-
negative integer. A sequence is called a solution of recurrence relation if its terms satisfy the recurrence
relation.
Note: There is an important connection between recursion and recurrence relations. A recursive algorithm
provides the solution of a problem of size n in terms of the solutions of one or more instances of the same
problem of smaller size. Consequently, when we analyze the complexity of recursive algorithm, we
obtain a recurrence relation that expresses the number of operations required to solve a problem of size n
in terms of the number of operations required to solve the problem for one or more instances of smaller
size.
Solving linear recurrence relations
A wide variety of recurrence relations occur in models. Some of these recurrence relations can be solved
using iteration or some other ad hoc technique. However, one important class of recurrence relations can
be explicitly solved in a systematic way. These are recurrence relations that express the terms of a
sequence as linear combination of previous terms.
Definition:
A linear homogenous recurrence relation of degree k with constant coefficients is a recurrence relation of
the form
an = c1an-1+c2an-2…..ckan-k
where c1,c2,c3…. ck are real numbers and ck≠0
The recurrence relation in the definition is linear because the right hand side is sum of previous terms of
the sequence each multiplied by a function of n. The recurrence relation is homogeneous because no
terms occur that are not multiples of ajs. The coefficients of the terms of the sequence are all constants;
rather than functions that depend on n. The degree is k because a n is expressed in terms of previous k
terms of the sequence
Example 1: The recurrence relation Pn = {1.11}Pn-1 is a linear homogeneous recurrence relation of degree
one. The recurrence relation fn = fn-1+fn-2 is a linear homogeneous recurrence relation of degree two.
The recurrence relation an = an-1+a2n-2 is not linear.

General form of Linear Homogeneous Recurrence Relation


The homogeneous recurrence of degree k1 with constant coefficient has the general form
an = c1an-1+c2an-2+….+ck.an-k………………..(i)

23
If an = rn is a solution of equation (i) then it must satisfy equation (i) i.e.
rn = c1rn-1+c2rn-2+….+ckrn-k

Dividing both sides rn-k on both side we get


rk = c1rk-1+c2rk-2+…..ck
or rk-c1rk-1c2rk-2……-ck=0
This equation is known as characteristic equation of given recurrence relation and it provides
characteristics roots of recurrence relation which are used to give on explicit formula for all the
solution of recurrence relation

Solving Linear Homogeneous Recurrence Relations with Constant Coefficients

A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence


relation of the form an = c1an-1+c2an-2+………….+ckan-k, where c1, c2, c2, …. are real numbers
and ck ≠0. The above relation is linear since right had side is sum of the multiples of previous
terms of the sequence. It is homogeneous since no term occurs without being multiple of some
aj,s. All the coefficients of the terms are constants and degree k is due to the representation of in
terms of previous ‘k’ terms of sequence.
In solving recurrence relation of this type, the approach is to look for the solution of the form an
= rn where r is a constant. An =rn is a solution of a recurrence relation a n = c1an-1+c2an-
2+….+ck.an-k if and only if r = c1r +c2r +….+ck r
n n-1 n-2 n-k

When we divide both sides by rn-k and transpose the right hand side we have

rk-c1rk-1c2rk-2……-ck=0

Here we say an = rn is a solution if and only if r is the solution if the equation r n-c1rk-1-c2rk-2-….-ck
= 0 (characteristic equation of the recurrence relation) and solutions to this equations are called
characteristic root of the recurrence relation.

Theorem 1 (Without Proof): Let c1 and c2 be real numbers. Suppose that r2-c1r-c2 =0 has two
distinct roots r1 and r2. Then the sequence {an} is a solution of the recurrence relation a n = c1an-
1c2an-2 if and only if a n = α1r1 + α2r2 for n=0, 1, 2, 3…. where α1 and α2 are constants.
n n

Example 1: Solve the recurrence relation an = 5an-1-6an-2 for n≥2, a0 = 1 and a1 = 0


Solution: The given recurrence relation is: an = 5an-1-6an-2 …..(i)
The characteristics equation is
r2-5r+6=0
r2 – 3r-2r+6=0
r(r-3)-2(r-3)=0

24
(r-2)(r-3) = 0
r = 2,3
r1 = 2, r2 = 3
Since, two characteristics roots are distinct; we use the “theorem 1” to write the general solution
The general form of the solution is:
an = α1r1+ α2r2n
or an = α12n+ α23n ……………(ii)

Form initial conditions


a0 = α120+ α230
1 = α1+ α2
And
a1 = α121+ α231
0= 2α1+ 3α2

Solving we get,
α1 = 3 and α2 = -2

Therefore, the solution of given recurrence relation is


an = 3.2n+ (-2)3n

Example 2: Solve the recurrence relation an = 6an-1-8an-2 for n≥2, a0= 4 and a1=10
Solution:
The given recurrence relation is
an = 6an-1-8an-2
The characteristic equation is
r2-6r+8=0
r2-4r-2r+8 = 0
r(r-4)-2(r-4)=0
(r-4)(r-2)=0
i.e. r=4, 2
→r1=4 and r2 = 2
Since roots are distinct, the general form of solution is:
an = α1r1n+ α2r2n
Or an = α14n+ α22n
From initial conditions, we have
a0 = α140+ α220
or 4 = α1+ α2……………………..(i)
And

25
a1 = α141+ α221
10 = 4 α1+2 α2………………….(ii)

Solving equation (i) and (ii), we get


α1 = 1 and α2 = 3
Therefore, the solution of given recurrence relation is
an = 1.4n+3.2n

Example 3: What is the solution of recurrence relation an = an-1+2an-2 with a0= 2 and a1=7
Solution:
The given recurrence relation is:
an = an-1+2an-2
And the initial conditions are a0 = 2 and a1 = 7
Now, we have a characteristic equation for the above given recurrence relation is
r2-4-2=0
r(r-2)+1(r-2) = 0
Or (r-2)(r+1)=0
Or r=2, -1
That is r1 = 2 and r2=-1 both are distinct
Hence the solution sequence is:
an = α1r1n+ α2r2n with r1=2 and r2=-1
That is
an = α12n+ α2(-1)n

From the initial conditions, we put the value of a0 and a1 in (1) and get the equation as
an =2= α120+ α2(-1)0
Or 2 = α1+ α2……………………………….(1)
And
a1 =7 = α12+ α2(-1)
7 = 2α1- α2…………………………(2)
Solving these two equations, we have
α1 = 3 and α2 = -1

Hence, the solution to the given recurrence relation and initial condition is the sequence {a n}
with an = 3.2n-1.(-1)n

Example 4: Solve the recurrence relation an = an-1 +6an-2 for n>2, a0=3, a1 = 6
Solution:
Here, the given recurrence relation is:
an = an-1+6an-2

26
And the initial conditions are a0= 3 and a1=6
Now, the characteristic equations for the above recurrence relation is
r2-r-6=0
Now, solving this equation by factorizing
r2-3r+2r-6=0
or r(r -3)+2(r-3)=0
(r-3)(r+2)=0
Or r=3, -2
That is, r1 = 3 and r2=-2
Hence, the solution sequence is

an = α1r1n+ α1r2n with r1=3 and r2=-2

or an = α13n+ α1(-2)n…………………………………(1)
Form the initial conditions; we put the value of a0 and a1 in (1) and get the equation as
a0 = 3 = α1+ α2……………………..(2)
a1 = 6 = 3α1+ (-2)α2…………….(3)

Solving these two equations


α1 = 12/5
α1 = 3/5
Hence, the general solution is the sequence {an} with an = (2.2*3n+0.6(-2)n)/5.

Example 5: Find the solution of recurrence relation fn = fn-1+fn-2, n>2 and f0=0 and f1=1
Solution:
Here, the given recurrence relation is
fn = fn-1+fn-2

The characteristic equation of this equation recurrence relation is


r2-r-1=0
Comparing r2-r-1=0 with ax2+bx+c=0, we get
a=1, b=-1 and c=-1
Now,
−𝑏±√𝑏2 −4𝑎𝑐
Roots = 2𝑎
−(−1) ± √(−1)2 − 4 ∗ 1 ∗ −1
=
2∗1

Taking positive sign


1+√5
r1 =
2

27
1−√5
r2 = 2

Hence characteristic roots are different, the general form of solution is


fn = α1+r1rn+ α2r2n
1+√5 1−√5 n
fn = α1( ) n+ α2( )
2 2

From initial condition we have,


f0 = α1+ α2
or 0 = α1+ α2……………………..(i)
1+√5 1−√5 n
f1 = α1( ) n+ α2( )
2 2
or
1+√5 1−√5 n
1 = α1( ) n+ α2( ) …………….(ii)
2 2
From equation (i) and (ii) we have
1
α1 =
√5
And
1
α2 = - -
√5
Hence the solution to the given recurrence relation
1 1+√5 1 1−√5 n
fn = ( )n - ( )
√5 2 √5 2

Example 6: What is the solution of recurrence relation an = an-1-2an-2 with initial conditions a0 =
2 and a1 = 7
Solution:
The given recurrence relation is:
an = an-1-2an-2
The characteristic equation is:
r2-r-2=0
r(r-2)+1(r-2)=0
or (r-2)(r+1) = 0
r = 2, -1
That is r1 = 2 and r2 = -1

Since roots are distinct, the general form of solution is

an = α1r1n+ α2r2n

an = α12n+ α21n

28
From initial conditions we have
a0 = α120+ α2.10
or 2 = α1+ α2 ………………………(i)
and
a1 = α121+ α211
Or
7 = 2α1+ α2……………………(ii)

Solving (i) and (ii) we get


5
α1 = 3
11
α2 = 3

Therefore, the solution of given recurrence relation is


5 11 n
an = 32n+ 1
3

Theorem 2: (Without proof): Let c1 and c2 be real numbers with c2≠0. Suppose that r2-c1r-c2=0 has only
one root r0. Then the sequence {an} is a solution of the recurrence relation an = c1an-1+c2an-2 if and only if
an = 1r0n +2r0n for n=0, 1, 2,….. where 1 and 2 are constants.
Example 1: Solve the recurrence relation an = 6a n-1 – 9an-2 for n≥2, n0 =1, a1=6
Solution: Characteristic equation of the given relation is:
r2-6r+9=0
(r-3)2 = 0
r = 3, 3
Therefore its only roots are = 3, 3
Hence, the sequence {an} is a solution to the recurrence relation if and only if
an = 13n+23 for some constants 1 and 2
From initial conditions we have
a0 = 1 = 1+2
a1 = 6 = 31+31

Solving these two equations we have 1 = 1 and 2 = 1


Hence, the solution is the sequence {an} with
an = 1.3n+1.n.3n

Example 2: Solve the recurrence relation an = 2an-1 –an-2 for n≥2, a0= 4 , a1=1
Solution:
The given recurrence relation is
an = 2an-1 –an-2
The characteristic equation for this recurrence relation is
r2-2r+1=0

29
(r-1)2 = 0
r=1,1
Since the characteristic roots are same, the general form of solution is
an = α1 r0n+α2n.r0n
That is
an = α1 1n+α2n.1n………………………….(i)
From initial conditions, we have
a0 = α1 10+α2n.10
Or 4 = α1 +α20
Or α1 =4
And
a1 = α1 11+α2.1.11
or 1 = α1+ α2………………………………(ii)
Putting value of α1 = 4 in equation (iii), we have
1 = 4+ α2
Or
α2 = -3
Therefore, the solution of given recurrence relation is
an = 1. 1n+(-3)n.1n

Example 3: Solve the recurrence relation an = 2an-1-an-2 for n≥2, a0=3, a1=6
Solution :
The given recurrence relation is
an = 2an-1-an-2
The characteristic equation for this recurrence relation is
r2-2r+1=0
(r-1)2 = 0
r=1,1
Since the characteristic roots are same, the general form of solution is
an = α1 r0n+α2n.r0n for constants α1 and α2
That is
an = α1 1n+α2n.1n………………………….(i)
From the initial conditions we have,
an = α1 1n+α2n.1n
Or 3 = α1 10+α20.10
Or 3 = α1
And
a1 = α1 11+α2.1.11
or 6 = α1 +α2
Or 6 = 3+ α2
α2 = 3
Hence, the solution is the sequence {an} with
an = 3 1n+3n.1n

30
Example 4: Solve the recurrence relation an = -6an-1 -9an-2 for n≥2, a0 = 5, a1 = -1
Solution:
The given recurrence relation is:
an = -6an-1 -9an-2
The characteristic equation for this recurrence relation is:
r2+6r+9=0
Or r(r+3)+3(r+3) = 0
(r+3)(r+3) = 0
r = -3,-3
Since the roots of characteristic equations are same, we have the general form of solution is:
an = α1 r0n+α2n.r0n for constants α1 and α2
That is,
an = α1 (-3)n+α2n.(-3)n for constants α1 and α2

From the given initial condition, we have


a0 = α1 (-3)0+α20.(-3)0
Or
5 = α1
And
a1 = α1 (-3)1+α2.1.(-3)1
Or
Or -1 = α1 (-3)1+α2.1.(-3)1
Or -1 = (-3).5 +(-3)α2
Or -3 α2 = -15+1
α2 = -14/3
Therefore, the solution of given recurrence relation is:
an = 5(-3)n+(-14/3)n.(-3)n

Theorem 3: (without proof)


Let c1, c2 c3,…. ck be real numbers. Suppose that r k-c1rk-1-….-ck =0 has k distinct roots r1,r2,r3……rk. Then
the sequence {an} is a solution of the recurrence relation a n = c1an-1+c2an-2+….+ckan-k if and only if an =
α1r1n+ α2r2n+…………….+ αnrkn for n=0,1,2,3….. where α1, α2 ….. αk are constants.

Example 1: Find the solution to an = 2an-1+an-2-2an-3 for n≥3 with a0 = 3, a1 = 6 and a2 = 0


Solution: The given recurrence relation is:
an = 2an-1+an-2-2an-3 ……………..(i)
The characteristics equation is:
r3 - 2r2 – 4 + 2 = 0
r3 - r2 – r2 2r – r – 4 + 2 = 0
r2(r – 1) – r (r – 1) – 2(r-1) = 0
(r-1)(r2 – r-2) = 0
(r-1)(r2 – 2r + r – 2) = 0
(r-1)(r(r-2)+1(r-2)) = 0
(r – 1 )(r – 2) (r + 1) = 0

31
Therefore, r1 = 1, r2 = 2, r3 = -1
Since all three roots are different, we can write the general form of solution as:
an = α1r1n + α2r2n + α3r3n
or an = α11n + α22n + α3(-1)n …………………………(ii)

From given initial conditions, we have


an = α1r1n + α2r2n + α3r3n
3 = α110 + α220 + α3(-1)0
Again
a1 = α1.1 + α2.2+ α3(-1)
or 6 = α1 + 2 α2 - α3
and
a2 = α1.12 + α2.22+ α3(-1)2
or 0 = α1 + 4 α2+ α3
Solving we get
α1 = 6
α2 = -1
α3 = -2
Therefore the solution of given recurrence relation is:
an = α1r1n + α2r2n + α3r3n
an = (-1).1n + 6 . 2n - (-2) (-1)n

Example 2: Solve the recurrence relation an = 2an-1+an-2-2an-3 for n≥3, a1 = 6 and a2=9
Solution:
The given recurrence relation is:
an = 2an-1+an-2-2an-3
The characteristic equation of this recurrence relation is
r3-2r2-r+2=0
r3-r2 -r2+r-2r+2=0
r2(r-1)-r(r-1)-2(r-1) = 0
(r-1)(r2-r-2)=0
(r-1)(r2-2r+r-2)=0
(r-1)(r(r-2)+1(r-2))=0
(r-1)(r+1)(r-2)=0
The roots of this characteristic equation are
r=1, -1, 2
Hence the sequence {an} is a solution to the recurrence relation if and only if an = α11n+ α2(-1)n+ α32n for
some constants α1, α2 and α3
From initial conditions we have,
a0 =3 = α1+ α2+ α3
a1 = 6 = α1- α2+ 2α3
And
a2 = 9 = α1+ α2+ 4α3
Solving these equations we have,

32
α1 = 3/2
α2 = -1/2
α3 = 2
Hence, the solution is the sequence {an} with
an = (3/2)1n+ (1/2)(-1)n+ 2.2n

Example 3: Find the solution of the recurrence relation a n = 6an-1 - 11an-2 + 6an-3 for n>3, a1 = 5 and a2 =
5
Solution:
The given recurrence relation is:
an = 6an-1 - 11an-2 + 6an-3
The characteristic equation is:
r3-6r2-11r-6=0
Since r = 1 satisfy this equation, r=1 is a root of this equation, so we try to find the factor (r-1) from this
equation
r3 – r2 – 5r2+5r+6r-6 = 0
r2(r-1)-5r(r-1) + 6(r-1) = 0
(r-1)(r2-5r+6)=0
(r-1)(r2-3r-2r -6) = 0
(r-1)(r(r-3)-2(r-3))=0
(r-1)(r-2)(r-3)=0
r1 = 1, r2 = 3, r3 = 2
Since all three roots are different, we have the general form of solution is
an = α1r1n+r2n+r3n
Or
an = α11n+3n+2n
From initial condition
a0 = α110+ α230+ α320
Or
2 = α1+ α2+ α3………………………….(i)
Again
a1 = α111+ α231+ α321
or 5 = 1α1+ 3α2+ 2α3……………….(ii)
And
a2 = α112+ α232+ α322
5 = 1.α1+ 9α2+ 4α3………………….(iii)
Solving equation (I, (ii) and (iii), we get
α1 = -4
α2 = -3
α3 = 9
Therefore, the solution of given recurrence relation is
an = (-4)1n+(-3)3n+9.2n

Theorem 4 (Without proof)

33
Let c1, c2, c3,c4……ck be real numbers. Suppose that rk-c1rk-1-….ck = 0 has distinct roots r1,r2,r3…rk with
multiplicity m1.m2,m3…mk respectively such that mi≥1 for i=0,1,2,3…t and m1+m2+m3+…+mt = k
Then the sequence {an} is a general solution of the recurrence relation
an = c1an-1+c2an-2+……….+ckan-k if and only if
an = (α1,0 + α1,1 n+…….+ α1,m1-1nm1-1) r1 n+ (α2,0 + α2,1 n+…….+ α2,m2-1.nm2-1)r2n+…………………
…+( (αt,0 + αt,1 n+…….+ αt,mt-1n mt-1)rt n
For n=0, 1, 2………… where αi,j are constants for 1≤j≤mi-1
Example 1: Solve the recurrence relation an = 5an-1-7an-2+3an-3 for n≥3, a0 = 1, a1 = 9 and a2 = 15
Solution: Characteristic equation of the given relation is r 3-5r2+7r-3 = 0.
Its roots are r1 = 1, r2=3 and r = 1
That is, r1 = 1 with m1 = 2 and r2 = 3 with m2=1
Hence, the sequence {an} is a solution to the recurrence relation if and only if an = (α 1,0+ α1,1n)1n +
(α2,0)3n, for some constants α1,0, α1,0, α2,0
From the initial conditions we have
a0 = 5 = α1,0 + α2,0
a1 = 9 = α1,0 + 3 α2,0
a2 = 15 = α1,0 + 2 α1,1 + 9 α2,0
Solving these three equations, we get,
α1,0 = 3/2
α1,1 = 9
α2,0 = -1/2
Hence, the solution is the sequence {an} with
an = (3/2)1n+ 91n – (1/2)3n

Example 2: Solve the recurrence relation an = -3an-1-3an-2-an-3 with a0=-5, a1 = 4 and a2=15
Solution: The given recurrence relation is:
an = -3an-1-3an-2-an-3
The characteristic equation is:
r3+3r2+3r+1=0
(r+1)3=0
r = -1,-1,-1
Since all these roots are same with multiplicity m=3
The general solution is:
an = (α1+ α1n+ α3n2)rn
an = (α1+ α1n+ α3n2)(-1)n
From given initial condition
a0 = (α1+ α10+ α302)(-1)0
or -5 = (α1+ 0+ 0)1
Or α1 = -5…………………………..(i)
Again,
a1 = (α1+ α11+ α312)(-1)1
or
4 = (α1+ α11+ α312)(-1)1
or α1+ α1+ α1 = -4………………………………..(ii)

34
And
a2 = (α1+ α12+ α322)(-1)2
or
a2 = (α1+ α12+ α322)(-1)2
15 =( α1+2 α2+4 α3)(-1)2
Or α1+2 α2+4 α3 = 15…………………………….(iii)
Solving equation (i), (ii) and (iii), we get
α1 = -5
α2 = -8
α3 = 9
Therefore, the solution of given recurrence relation is:
an = (-5- 8n+ 9n2)(-1)n

Example 3: Solve the recurrence relation an = 2an-1, n≥1 with initial condition a0 = 3
Solution:
The given recurrence relation is;
an = 2an-1
The characteristic equation of this recurrence relation is:
r1- 2=0
or r=2
Since r=2 with multiplicity m = 1, the general solution form of this solution is:
an = αrn
That is
an = α2n
From initial condition,
a0 = 3, we have
a1 = α20
Or α = 3
Hence, the solution of given recurrence relation is
an = 3.2n
Solving Linear Non-homogeneous Recurrence Relations with Constant Coefficients
The recurrence relation of the form
an = c1an-1+c2an-2+…..+ckan-k+ F(n)
where c1, c2, c3,….. ck are real numbers and F(n) is a function depending upon n. The recurrence relation
preceding F(n) is called associated homogeneous recurrence relation
For example,
an = 7an-1+3an-2+6n is a linear non-homogeneous recurrence relation with constant coefficients.

Theorem 5: (without proof)


If {an(p)} is a particular solution of the non-homogeneous linear recurrence relation with constant
coefficients an = c1an-1 + c2an-2+…+ckan-k + F(n), then every solution of the form
{an(p)+an(h)},
where an(h) is a solution of the associated homogeneous recurrence relation a n = c1an-1 + c2 an-2 +……+
ckan-k

35
Example 1: Find all solutions of the recurrence relation a n = 4an-1+ n2. Also find the solution of the
relation with initial condition a1 = 1
Solution:
We have associated linear homogeneous recurrence relation as a n = 4an-1. The root is 4, so the solutions
are an(h) = α4n where α is a constant. Since F(n) = n2 is a polynomial of degree 2, a trial solution is a
quadratic function in n, say, pn = an2+bn+c, where a,b,c are constants.
To determine whether there are any solutions of this form, suppose that
pn = an2+bn+c is such solution.
Then the equation an = 4an-1+n2 becomes
an2+bn+c = 4(a(n-1)2+b(n-1)+c)+n2
= 4an2 -8an +4a +4bn-4b+4c+n2
= (4a+1)n2+(-8a+4b)n+(4a-4b+4c)
2
Here an +bn+c is the solution if and only if
4a+1=a . That is a=-1/3
-8a+4b = b or b = -8/9
And
4a-4b+4c =c or c = -28/27
So an(p) = -1/3(n2+8/9.n+28/9) is a particular solution and all other solutions are
an = [an(p)+an(h)} = 1/3(n2+8/3n+28/9)+ α4n where α is a constant
For solution with a1 = 1, we have
a1 = 1 = -1/3(1+8/3+28/9)+α.4
Or α = 22/27
Then the solution is
an = [an(p)+an(h)} = 1/3(n2+8/3n+28/9)+ 22/27.4n
Example 2: Find all the solution of recurrence relation a n = 2an-1 + 3n and a solution with initial condition
a1 = 5
Solution:
The given recurrence relation is
an = 2an-1 + 3n……………………(i)
The linear homogeneous part of above equation is:
an = 2an-1 ………………….(ii)
Now the characteristic equation, we write
r-2=0 or r=2
Now, the solution of equation (ii) is
an = α1rn
or an = α1 2n…………………….(iii)
To find the particular solution, we write
F(n) = 3n………………………..(iv)
The trial solution of (iv) is
a(p) = c.3n …………….(v) where c is constant
Substituting terms of this sequence into recurrence relation we have
an = 2an-1+3n
put an(p) = c.3n

36
c3n = 2c3n-1+3n
c.3n = 2c.3n/3+3n
c3n = 3n(2c/3+1)
Comparing the coefficient of 3n
c = 2c/3+1 or c = 3
Therefore, the particular solution is
an(P) = 3.3n
And all solution of given recurrence relation is
an = an(h)+an(p)
an = α1 2n+3.3n = α1 2n +3n+1
From initial conditions, we have
a1 = α1 2n +3n+1
or 5 = 2 α1+9
5-9 = 2 α1
Or α1 = -2
Hence, the solution of given Recurrence relation is
an = -2. 2n +3n+1
Example 3: Find the solution of the recurrence relation a n = 3an-1+2n. What is the solution with a1 = 3?
Solution:
To solve this linear nonhomogeneous recurrence relation with constant coefficients, we need to solve its
associated linear homogeneous equation and to find a particular solution for the given non-homogeneous
equation. The associated homogeneous equation is a n = 3an-1. Its solutions are an = α3n
Where α is constant
We now find a particular solution. Because F(n) = 2n is a polynomial in n of degree one, a reasonable
trial solution is a linear function in say pn = cn+d, where c and d are constants. To determine whether
there are any solutions of this form, suppose that pn = cn+d is such a solution. Then the equation a n = 3an-1
+2n becomes cn+d = 3(c(n-1)+d)+2n.
Simplifying and combining like terms gives (2+2c)n+(2d-3c) = 0.
It follows that cn+d is a solution if and only if 2+2c = 0 and 2d-3c=0.
This shows that cn+d is a solution if and if c=-1 and d=-3/2.
Consequently, an(p) = -n-3/2 is a particular solution
By theorem 5 all solutions are of the form
an = an (p)+an(h) = -n – 3/2+ α.3n
where α is constant
To find the solution with a1 = 3, let n = 1 in the formula we obtained for the general solution. We find
that 3 = -1-3/2 +3 α which implies that α = 11/6
11
The solution we seek is an = an (p)+an(h) = -n – 3/2+ .3n
6
Example 4: Find all solutions of the recurrence relation a n = 5an-1 -6an-2 +7n
Solution: This is a linear nonhomogeneous recurrence relation. The solution of its associated
homogeneous recurrence relation
an = 5an-1 -6an-2
are an(h) = α13n + α22n where α1 and α2 are constants. Because F(n) = 7n, a reasonable trial solution is an
(p) = C 7n where C is a constant. Substituting the terms of this sequence into the recurrence relation
implies C.7n = 5C. 7n-1 -6C. 7n-2 +7n

37
Factoring out 7n-2, this equation becomes 49C = 35C-6C +49 which implies that 20C = 49 or C = 49/20.
Hence, an (p) = (49/20)7n is a particular solution.
By theorem 5, all solutions are of the form
an = α13n + α22n + (49/20)7n

Theorem 6: (without proof)


Suppose that {an} satisfies the linear non-homogeneous recurrence relation an = c1an-1 + c2an-2 +…. + ckan-
k +F(n), where c 1, c2, c3….ck are real numbers and F(n) = (b tn + bt-1n + ….. +b1n +p0) sn, where b0, b1,
t t-1

b2…. bt and s are real numbers. When s is not root of the characteristic equation of the associated
homogeneous recurrence relation, there is a particular solution of the form
(ptnt + pt-1nt-1+…….+p1n+p0)sn
When s is the root of the characteristic equation and its multiplicity is m, there is a particular solution of
the form
nm (ptnt + pt-1nt-1+…….+p1n+p0)sn
Example: Find the solution of the recurrence relation a n = 2an-1+n.2n
Solution:
We have associated linear homogeneous recurrence relation is
an(h) = 2an-1
The characteristic equation for this would be r-2 =0, so the root is 2 and hence the solution is a n(h) = α1 2n,
where α is a constant
We have F(n) = n2n where s is the root of the characteristic equation and the multiplicity of 2 is 1, so the
particular solution has the form
c = n.(p1n)2n
or an(p) = p1n22n
The all solution is an = α1 2n+p1n22n
Example 2 : What form does a particular solution of the linear nonhomogeneous recurrence an = 6an-1-
9an-2 +F(n) have when
a) F(n) = 3n
b) F(n) = n3n
c) F(n) = n22n
d) F(n) = (n2+1)3n?
Solution: The associated linear homogeneous recurrence relation is a n = 6an-1 – 9an-2. Its characteristic
equation is, r2-6r+9 = (r-3)2=0 has a single root which is 3 with multiplicity 2. Theorem 6 with F(n) of the
form P(n)sn, where P(n) is a polynomial and s is a constant, we need to ask whether s is a root of this
characteristic equation

a. Because s=3 is a root with multiplicity m=2. Theorem tells us that a particular solution has the
form (p0n23n) if F(n) = 3n
b. Particular solution has the form n2(p1n+p0)3n
c. Particular solution has the form (p2n2+p1n+p0)2n
d. Particular solution has the form n2(p 2n2+p1n+p0)3n

Recurrence Applications

38
One of the application areas of recurrence relations is analysis of divide and conquers algorithms
Divide and Conquer Algorithms
Divide and conquer algorithms divide a problem of larger size to the problem of smaller size so that the
problem of smallest size that has trivial solution is obtained. If f(n) represents the number of operations
required to solve the problem of size n, then follows the recurrence relation f(n) = af(n/b)+ g(n), called
divide and conquer recurrence relation. In the relation above, the problem of size n is partitioned into a
part.
Example 1: Fibonacci Numbers
We know that the Fibonacci numbers are generated by the formula fn = fn-1 + fn-2. Here nth Fibonacci
number is the sum of (n-1)th and (n-2)th Fibonacci numbers. Here, for the initial conditions are f0 = 0 and
f1 = 1. Use of the above relation does not exactly produce the recurrence relation mentioned above.
However, this is an example of divide and conquer algorithm since each time the problem is changed into
two problems of smaller size
Example 2: Merge Sort
In merge sorting, the input sequence of n items is broken down into two halves. Since the list of size n
need more comparisons than list of size n/2, the problem here is simplified. This process continues until
all the comparisons are trivial.
This problem satisfies the divide and conquers recurrence relation
M (n) = 2M (n/2) +O (1)
Example 3: Binary Search: The binary search algorithm reduces the search for an element in a search
sequence of size n to the binary search for this element in a search sequence by n/2 when n is even. The
problem size n has been reduced to one problem of size n/2. So two comparisons are needed to implement
this reduction. Hence if f(n) is the number of comparisons required to search for an element in a search
sequence of size n, then
f(n) = f(n/2)+2

Assignment 5
1. If three persons enter a bus in which there are ten vacant seats. Find in how many ways they can
seat
2. State the Pigeonhole principle. How many students must be in a class to guarantee that at least
two students receive the same score on the final exam is graded on a scale from 0 to 100?
3. From a group of 11 men and 8 women, how many committees consisting of 3 men and 2 women
are possible
4. A candidate is required to answer 6 out of 10 questions which are divided into two groups each
containing 5 questions and he is not permitted to attempt more than 4 from any group. In how
many different ways can he make up his choice
5. In how many ways can 10 adults and five children stand in a circle so that no two children are
next to each other?
6. In how many permutations can be made out of the letters of the word “SUNDAY”? How many of
these:

39
a. Begin with s
b. End with y
c. Begin with s and end with y
d. s and y always come together
7. For each of the following, expand using binomial theorem and simplify
i. (x+y)10
ii. (2x+3y)6
8. Find the coefficient of x10 in the expansion of (1+x2)10
9. What is the coefficient of x5x7 in the expansion of (x-2y)12
10. Find the general term in the expansion of (a/b+b/a)2n+1
11. Find middle term or terms in the expansion of
(ax+1/ax)17
12. A dice is thrown two times. Find the probability of getting a number greater than 2
13. A ball is drawn at random from a box containing 6 white, 8 red and 10 green balls. Determine the
probability, that ball drawn is (i) white (ii) green (iii) not red (iv) red or green.
14. Solve the following recurrence relation a n = 4an-1 - 4an-2 with the initial conditions n≥2,a0=6,
a1=8
15. Find the explicit formula for the Fibonacci numbers with recurrence relation fn = fn-1+fn-2 with
f1 = 1 and f2 = 2
16. Find the solution to an = 7an-2 + 6an-3 with a0 = 9, a1 = 10, a2 = 32
17. Let {an} be a sequence that satisfies the recurrence relation an = an-1-an-2 for n≥2 and suppose that
a0 = 3 and a1 = 5. Find the value of a2 and a1.

Lab 5:
Write a program to generate permutations and combinations
Ans:
Program to generate permutation
#include<conio.h>
#include<stdio.h>
int factorial(int n);
int main()
{
int n,r,i;
printf("Enter value of n and r\n");
scanf("%d%d",&n,&r);
printf("The permutation P(%d, %d) = %d\n",n,r,factorial(n)/(factorial(n-r)));
getch();
return 0;
}
int factorial(int n)
{
if(n<=1)

40
return 1;
else
return n*factorial(n-1);
}
Output:
Enter value of n and r
10 5
The permutation P(10, 5) = 30240

Program to implement Combination

#include<conio.h>
#include<stdio.h>
int factorial(int n);
int main()
{
int n,r,i;
printf("Enter value of n and r\n");
scanf("%d%d",&n,&r);
printf("The combination C(%d, %d) = %d\n",n,r,factorial(n)/(factorial(n-r)*factorial(r)));
getch();
return 0;
}
int factorial(int n)
{
if(n<=1)
return 1;
else
return n*factorial(n-1);
}
Output
Enter value of n and r
12 10
The combination C(12, 10) = 66
Write a C programs to implement quick sort
Ans:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void quickSort(int arr[],int l,int r);
int partition(int arr[],int l,int r);
int main()
{
int arr[] = {1,0,10,8,3,6,4,7,2,5};

41
int i;
printf("Array before sorting\n");
for(i=0;i<10;i++)
{
printf("%d\t",arr[i]);
}
quickSort(arr,0,9);
printf("\nArray after sorting\n");
for(i=0;i<10;i++)
{
printf("%d\t",arr[i]);
}
getch();
return 0;
}
void quickSort(int arr[],int l,int r)
{
if(l<r){

int p = partition(arr,l,r);
quickSort(arr,l,p-1);
quickSort(arr,p+1,r);
}
}
int partition(int arr[],int l,int r)
{
int x,y,p,t;
x=l;
y=r;
p=arr[l];
while(x<y)
{
while(arr[x]<=p && x<=y)
x++;
while(arr[y]>p&& x<=y)
y--;
if(x<y)
{
t = arr[x];
arr[x] = arr[y];
arr[y]=t;
}
}
t = arr[l];

42
arr[l]=arr[y];
arr[y]=t;
return y;
}
Write a C program to implement quick sort using randomized algorithm
Ans:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int Randpartition(int arr[],int l,int r);
void quickSort(int arr[],int l,int r);
int partition(int arr[],int l,int r);
int main()
{
int arr[] = {1,0,10,8,3,6,4,7,2,5};
int i;
printf("Array before sorting\n");
for(i=0;i<10;i++)
{
printf("%d\t",arr[i]);
}
quickSort(arr,0,9);
printf("\nArray after sorting\n");
for(i=0;i<10;i++)
{
printf("%d\t",arr[i]);
}
getch();
return 0;
}
void quickSort(int arr[],int l,int r)
{
if(l<r){

int p = Randpartition(arr,l,r);
quickSort(arr,l,p-1);
quickSort(arr,p+1,r);
}
}
int Randpartition(int arr[],int l,int r)
{
int rp = l+rand()%(r-l+1);
int t = arr[l];
arr[l] = arr[rp];

43
arr[rp]=t;
return partition(arr,l,r);
}
int partition(int arr[],int l,int r)
{
int x,y,p,t;
x=l;
y=r;
p=arr[l];
while(x<y)
{
while(arr[x]<=p && x<=y)
x++;
while(arr[y]>p&& x<=y)
y--;
if(x<y)
{
t = arr[x];
arr[x] = arr[y];
arr[y]=t;
}
}
t = arr[l];
arr[l]=arr[y];
arr[y]=t;
return y;
}
#include<stdio.h>
#include<conio.h>
void combi(int arr[], int data[], int start, int end,int index, int r)
{

if (index==r)
{
for (int j = 0; j < r; j++)
printf("%d ",data[j] );
printf("\n");
return;
}
for (int i=start;i<=end &&end-i + 1>=r-index;i++)
{
data[index] = arr[i];
combi(arr,data,i+1,end,index+1,r);
}

44
}
void printCombination(int arr[], int n, int r)
{
int data[r];
combi(arr, data, 0, n-1, 0, r);
}

int main()
{
int arr[] = {1, 2, 3, 4, 5};
int r = 3;
int n = 5;
printCombination(arr, n, r);
}
Program to generate permutation
#include<stdio.h>
#include<conio.h>
#include<string.h>
void swap(char *a,char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
void permutate(char *a, int i,int n )
{
if(i==n)
{
printf("%s\n",a);
}
else
{
for(int j=i;j<=n;j++)
{
swap((a+i),(a+j));
permutate(a, i+1,n);
swap((a+i),(a+j));
}
}
}
int main()
{
char str[20];
printf("Enter any string\n");

45
gets(str);
permutate(str,0,strlen(str)-1);
getch();
return 0;
}

46

You might also like