 We will study some applications of recurrence relations in particular what we will see today is that many counting problems can be solved by using recurrence relations relatively easily the basic strategy of handling these problems is that given a problem we will try to build up a recurrence relation on certain numbers and then we will solve that recurrence relation. So our topic today is applications of recurrence relations let us look at the first example using only three letters a b c how many words can be formed so that consecutive is do not appear in those words here we have a counting problem now if somebody asked me that given three letters how many words can be formed of which are of length n then I would have considered n positions like this total number n and then I know that each position can be occupied by three ways since we have three symbols a b c and therefore here we have three here we have three here we have three and the last also three so the total number is 3 x 3 x and so on up to 3 again n times which is equal to 3 to the power n but here we have a slightly different condition because here the problem says that I cannot consider the words which have consecutive is now let us consider if n equal to 0 if n equal to 0 then that means in the words there is no letter so the total number of such words is let us call it a 1 which is equal to 1 now when n equal to 1 and I have got three letters then that sorry here I will write a 0 this is a 0 of course because this is this corresponds to n equal to 0 now we have n equal to 1 for which we have a 1 and a 1 is equal to 3 the reason is that there are three letters and I can write a word a another word b and the third word c so these are three distinct words so a 1 equal to 3 now if we consider a 2 for n equal to 2 then let us count how many ways we can write a 2 the number of ways we can build up two letter words out of the three symbols is let us start counting we can write a a a b a c and then we can write b a b b b c and lastly c a c b c c so there are all together 3 x 3 9 words now what we see here is that there is one word which contains two consecutive a's so we have to cancel this therefore now we have 8 words and a 2 equal to 8 now like that of like this we can go on but we would like to have a compact relation in the form of a recurrence relation therefore what we do is that we say that suppose a n is the total number of such words so a n equal to the total number of such words so I have some n positions where letters have been put in now we ask a question what about the last position the last position can be occupied by a b or c now then we ask that suppose the last position is occupied by a then what will happen if the last position is occupied by a then of course in the position previous to that a cannot appear again so either it will be b or it will be occupied by c so now let us count the positions this is the position number 1 this is position number 2 and so on this is position number n – 2 this is position number n – 1 and this is position number n similarly here this is position number 1 this is position number 2 and we move up in this way and then ultimately we arrive at position number a n – 2 position number a n – 1 and lastly position number a n therefore we see that if we have a word in the set of all words which are ending with a and not having 2 consecutive a then ending with a means the nth position has a then the n – 1th position of those words will not have a will have either b or c so we have these two configurations and if we look at the segment from n to n – 2 in both these words then we will see that this segment can be occupied by any word of length n – 2 consisting of the three symbols a b c and not having two consecutive s now according to our notation a n – 2 is equal to the total number of words of length n such that no consecutive is appear so we will at least have a n – 2 plus a n – 2 many words in the set of words of length n having no consecutive is now let us move to the next page here so what we have seen is that when we are considering length n segment ending with a when we are considering length n segment ending with a then the previous position can be either b or c and there is there are n – 2 many positions and those positions for each case b and b or c can be occupied by a n – 2 many words of length n – 2 therefore I have got a n – 2 plus a n – 2 now we look at the other situation when the word of length n is not ending with a then it may end with either b or c in either of these cases the initial segment consisting of n – 1 letters can be occupied by a n – 1 and a n – 1 words so total number of words that we have is a n – 1 plus a n – 1 therefore we come to the conclusion that if we have words of length n ending with a then there will be a n – 2 plus a n – 2 many words of length n ending with a and not having two consecutive is anywhere and if the n length word is ending with b or c then we will have n plus 1 plus a n plus 1 many words and these are the only possible words of length n consisting of three symbols a bc so that no two consecutive as appear therefore we can write a recurrence relation in this form a n equal to a n – 2 plus a n – 2 plus a n – 1 plus a n – 1 in other words we have the recurrence relation a n – 2 times a n – 1 – 2 times a n – 2 which is equal to 0 once we have done this we need to solve this recurrence relation we note that it is a second order recurrence relation with constant coefficients and of course it is a linear recurrence relation we consider the solution a n equal to cr raise to the power n and substitute it in the recurrence relation which we denote by 1 to obtain cr to the power n – 2 c r to the power n – 1 – 2 c r to the power n – 2 which is equal to 0 that is taking the common factor c and r to the power n – c into r to the power n – 2 out from all the terms we will get r square – 2 times r – 2 equal to 0 and solving this we get r equal to 2 plus or minus 4 plus 8 and this gives me 2 plus or minus square root of 12 by 2 which is 1 plus or minus root of 3 therefore we get the general solution a n equal to a constant capital A times 1 plus square root of 3 raise to the power n plus b into 1 – square root of 3 raise to the power n now we have to substitute the values of a 0 and a 1 as we have already noted that a 0 is 1 so let us let us go to the next page and write the general solution of the recurrence relation a n equal to a 1 plus square root of 3 raise to the power n plus b 1 – square root of 3 whole raise to the power n and for n equal to 0 1 equal to a 0 equal to a plus b this implies that b is equal to 1 – a if we put n equal to 1 we know that a 1 is equal to 3 which is equal to a 1 plus square root of 3 plus b 1 – square root of 3 if we substitute the value of b in this equation then we will get a 1 plus square root of 3 plus 1 – a 1 – square root of 3 which gives us a 1 plus square root of 3 plus 1 – square root of 3 – a 1 – square root of 3 well and proceeding further we have a plus a square root of 3 plus 1 – square root of 3 – a plus a square root of 3 now there is some there are some cancellations first of all a will get cancelled and let me write the equation here which is 3 equal to 1 – square root of 3 plus 2 times a square root of 3 that is 2 times a square root of 3 equal to 2 plus root 3 which gives me a equal to 2 plus root 3 divided by 2 root 3 from this we see that b is equal to 1 – a which is equal to 1 – 2 plus square root of 3 2 root 3 which is equal to 2 into root 3 in the denominator and in the numerator 2 root 3 – 2 – root 3 which is equal to 2 root 3 root 3 – 2 therefore we have the solution to our recurrence relation which is a n equal to 2 plus square root of 3 divided by 2 square root of 3 this is the value of the first constant capital A and this is multiplied by 1 plus square root of 3 raise to the power n plus square root of 3 – 2 divided by 2 root 3 into 1 – square root of 3 raise to the power n this is our final answer let us look at another problem now this problem states that if a first case of measles if a first case of measles in a certain school system is recorded and Pn denotes the probability that at least one case is reported during the nth week after the first recorded case the school record provide evidence that Pn equal to Pn – 1 – 1 by 4 Pn – 2 then which week probability will decrease below 0.01 for the first time. So what we are looking at here is that suppose a school system checks the reports of a certain disease let us say measles among children and it starts counting from a week when one recorded event has occurred that is some case of measles have come up now what the school record says that starting from a week where at least one measles attack has been recorded if we start counting the number of weeks then the probability that in the nth week there will be at least one reported case is given by this recurrence relation now we have got no control over this recurrence relation it is from some data source possibly from which the school record is from the records of different years this has been observed let us say and we are asked a question that after how many weeks for the first time this Pn is going to go below 0.01 for that we have to solve this recurrence relation in order to do that we first write down the recurrence relation in the form 4 Pn – 4 Pn – 1 plus Pn – 2 which is equal to 0 and now considering that Pn is of the form C raise to the power r to the power n we have the characteristic equation as 4r square – 4r plus 1 equal to 0 and this leads to 2r – 1 whole square equal to 0 and therefore r is half half so half is a repeated root of this equation now from the discussions of the previous days we have seen that this means that Pn equal to a half raise to the power n plus Bn half raise to the power n and now we try to look at the initial conditions if we put n equal to 0 that is in the 0th week then by definition P0 is 0 because we have not started our observations now if we start from P1 what we have told in the statement of the problem that we start counting n from the point of observing at least one disease disease case therefore P1 is 1 now in the equation 1 if we substitute these values we get 0 equal to a plus B into 0 which is equal to a so the constant a reduces to 0 and we have 1 equal to a times half plus b times half now a is 0 therefore we have only b times half therefore we have b is equal to 2 thus we have the probability Pn is equal to 2 times n into 1 by 2 to the power n which is essentially n divided by 2 to the power n – 1 now we want this probability to drop below 0.01 for the first time 0.01 is 1 by 100 therefore we would like this equation to hold that is 100 n less than 2 to the power n – 1 now if we check this inequality and keep on varying n from 1 onward like 1 2 and 3 4 like that then we will find that the cutoff is n equal to 12 so when n equal to 12 then for the first time this inequality will be satisfied therefore Pn will become less than 0.01 now we will look at a case of application of non-homogeneous recurrence relations now we will again discuss one example let me write down the example first for n greater than or equal to 2 suppose that there are n people at a party and that each of these people shakes hands exactly once all the other people of course of course nobody shakes hands himself or herself now our question is that what is the number of handshakes what is the number of handshakes when we think of the solution we again start denoting the total number of handshakes when n people are present under the given constraints as an so an is equal to the total number of handshakes under the given constraints under the given set of constraints now I would like to build a recurrence relation now let us try to see what happens if we start with let us say two people because we have seen that we do not want n to be to go below 2 because if n is equal to 1 then of course there is no handshakes so we start with n equal to 2 so suppose I have got person number 1 and person number 2 let us call them v1 and v2 and I will join them to signify that shaken hand exactly once so we see that a2 is going to be 1 now if we consider that another person is coming now what will happen so let us draw the situation over here we have got three people so we have now a party of three and they are shaking hands with with the given constraints now what we can always do is that we can remove for the time being one person suppose we have left out v3 then there is only one handshake so this is the number of handshakes for two people so I have got a too many handshakes now when with v3 comes in then he does not shake hands with himself therefore he has to shake hand with all the other people exactly once so therefore he will shake hand with this person and shake hand with this person so the total number of handshakes will be a2 plus 2 which is denoted by a3 now suppose we know a3 so there are three people who shakes hands with each other v1 v2 v3 they are shaking hand with each other and suppose a fourth person is coming in and let us call him v4 and so that means now we have a party of four so when v4 is out the remaining people shakes hands in a3 many ways and when v3 v4 comes in he has to shake hand with all the people except for himself he shakes hand with v3 he shakes hand with v2 and lastly or whatever he shakes hand with v1 so he has to shake another three many hands so total number of handshakes is a3 plus 3 which is equal to a4 now we can go to the general case that suppose we have got n people so we have got v1 v2 and so on and lastly we have got let us say vn minus 2 vn minus 3 and over here vn minus 1 and here we have vn so we have a party of n people and we know that they shake hand in an many ways now suppose that we have got one more person vn plus 1 and vn plus 1 so we have a party of n plus 1 people now suppose they shake hands in the designated manner now what we do is that we can choose any of the vertices now let us let us take that we are taking out vn plus 1 and removing all the edges from vn plus 1 then we have a party of n and of course they are shaking hands exactly once with the others and not shaking hand with himself or herself so we have got total of a n minus 1 handshakes and then when vn minus 1 vn plus 1 is considered then he is bound to shake hands with each of the people in the other group so the total number of handshakes will be n so this is increased by n and which is the total number of handshakes with n plus 1 people so we have built up a recurrence relation corresponding to the handshakes let us write down this recurrence relation and then let us try to solve it the homogeneous part of this equation is a n plus 1 minus a n equal to 0 and we take a trial solution let us call it a n equal to CRS to the power n then we get CRS to the power n plus 1 minus CRS to the power n which is equal to 0 and this leads us to R minus 1 equal to 0 because we can of course assume very reasonably that C not equal to 0 and R not equal to 0 therefore we have R equal to 1 therefore the homogeneous part written as a n superscript H in bracket is C times 1 to the power n or C which is a constant next we try to find out a particular solution here we choose that trial solution to be a n particular equal to a 1 n square plus a 0 n which is indeed a rather complicated expression and if we substitute this in the recurrence relation then we will get a 1 n plus 1 whole square plus a 0 n plus 1 equal to a n which is a 1 n square plus a 0 n plus n and if we do the usual manipulations then we will get n square a 1 minus a 1 plus 2 times a 1 plus a 0 minus a 0 minus 1 plus a 0 plus a 1 equal to 0 and this should hold for all n therefore we have got a 1 equal to a 1 by equating the coefficients to 0 and when I equate the coefficients of n to 0 I get a 1 minus 1 equal to 0 that is a 1 equal to half and when I equate the constant term to 0 that is a 0 plus a 1 equal to 0 then I get a 1 equal to or minus a 1 equal to a 0 which implies a 0 equal to minus half therefore we arrive at the general solution a a n equal to constant plus half n square minus half n and now if I put the value of n equal to 2 we know that 2 is equal to sorry 1 here we have got 1 a 2 is 1 so therefore 1 equal to a 2 which is equal to c plus half of 4 minus half into 2 which gives me c plus 2 minus 1 which is c plus 1 this implies c equal to 0 therefore finally we have the solution as a n equal to half of n square minus half of n for n greater than or equal to 2 thus we know now that if we have n people in a party and each person shakes hand exactly once with each of the other people present in the party then the total number of handshakes is half of n square minus half of n with this handshaking problem I will end today's lecture thank you