1 00:00:01,449 --> 00:00:02,629 Welcome back. 2 00:00:02,629 --> 00:00:11,219 So in last few lectures, we have seen how to use the recurrence relations to model various 3 00:00:11,219 --> 00:00:12,670 counting problems. 4 00:00:12,670 --> 00:00:23,080 Now, as we have told recurrence relations are very essential part of mathematics or 5 00:00:23,080 --> 00:00:25,540 particularly in counting. 6 00:00:25,540 --> 00:00:31,690 So in such, recurrence relation is an equation that recursively defines a sequence or multi-dimensional 7 00:00:31,690 --> 00:00:43,150 array of values where there are some initial terms and the nth term is defined as a function 8 00:00:43,150 --> 00:00:46,260 of the preceding terms. 9 00:00:46,260 --> 00:00:54,430 Recurrence relation is extensively used for combinatorics, analysis of algorithms, in 10 00:00:54,430 --> 00:01:00,960 computational biology, in theoretical economics and many other subjects. 11 00:01:00,960 --> 00:01:05,690 So we have already seen some of the recurrence relations. 12 00:01:05,690 --> 00:01:12,030 And we have seen how recurrence relations can be used to model various problems, particularly 13 00:01:12,030 --> 00:01:13,030 combinatorics problems. 14 00:01:13,030 --> 00:01:19,270 But we have not seen how to solve recurrence relations. 15 00:01:19,270 --> 00:01:26,719 In this video, we will be focusing on how to solve recurrence relations. 16 00:01:26,719 --> 00:01:35,340 So here, some of the recurrence relations that do appear in real life problems. 17 00:01:35,340 --> 00:01:45,754 So the first one says, T(1) equals to 1 and T(n) equals to 2 plus T(n minus 1). 18 00:01:45,754 --> 00:01:52,880 The second one say, T(1) equals to 1, T(2) equals to 2 and Tn is equals to T(n minus 19 00:01:52,880 --> 00:01:57,649 1) plus T(n minus 2). 20 00:01:57,649 --> 00:02:05,829 Or this one is what we got from the Tower of Hanoi problem H(1) equals to 1, H(2) equals 21 00:02:05,829 --> 00:02:14,640 to 2, and H(n) equals to 2 times H(n minus 1) plus 1. 22 00:02:14,640 --> 00:02:20,840 This one is basically what we have the Fibonacci series where F(1) equals 1, F(2) equals to 23 00:02:20,840 --> 00:02:25,120 1 and F(n) equals to F(n minus 1) plus F(n minus 2). 24 00:02:25,120 --> 00:02:31,700 This is what is known as the Fibonacci series is quite a famous series that appears again 25 00:02:31,700 --> 00:02:33,450 and again in real life. 26 00:02:33,450 --> 00:02:45,280 Then this one b(1) equals to 1 and b(n) equals to b (n over 2) plus 1. 27 00:02:45,280 --> 00:02:52,159 Then we have M(1) equals to 1 and M(n) equals to 2 times M(n over 2) plus n. 28 00:02:52,159 --> 00:03:00,599 So these two appears in various algorithms, particularly, the binary search algorithm 29 00:03:00,599 --> 00:03:10,000 and the merge sort algorithm that are very popular in the algorithm’s literature. 30 00:03:10,000 --> 00:03:12,120 And then we have applied some of complicated one. 31 00:03:12,120 --> 00:03:21,590 C(1) equals to 1 and C(n plus 1) is equals to submission of i equals to 0 to n. 32 00:03:21,590 --> 00:03:25,319 C(i) C( n minus i). 33 00:03:25,319 --> 00:03:30,640 Now for all of them, we have to now understand how one can solve them. 34 00:03:30,640 --> 00:03:35,000 So what is the technique for solving any of these recurrences? 35 00:03:35,000 --> 00:03:40,290 So, how to solve these recurrences? 36 00:03:40,290 --> 00:03:50,890 Now, the first technique that we are going to look at is, the simple thing of guess the 37 00:03:50,890 --> 00:03:54,719 solution and prove using induction. 38 00:03:54,719 --> 00:04:07,050 In this video, we will see how this technique is useful and then we will - In next video, 39 00:04:07,050 --> 00:04:16,380 we will see how one can guess the solution. 40 00:04:16,380 --> 00:04:17,950 So say here we have this example. 41 00:04:17,950 --> 00:04:24,420 T(1) equals to 1, T(n) equals to 2 plus T(n minus 1). 42 00:04:24,420 --> 00:04:27,430 Now how do you solve this particular problem? 43 00:04:27,430 --> 00:04:36,420 Now first of all, if somehow magically you can guess this number, then we are great. 44 00:04:36,420 --> 00:04:47,340 For example, if I tell you, that guess where T(n) equals to (2n minus 1). 45 00:04:47,340 --> 00:04:55,960 Now if this is the guess that we made, then we can try to prove the statement using induction. 46 00:04:55,960 --> 00:05:01,980 So the technique is first to guess and then prove by induction. 47 00:05:01,980 --> 00:05:05,700 Now I have skipped a big jump of how to guess this number. 48 00:05:05,700 --> 00:05:11,940 We will see that one – see the technique of guessing in the next video as well as in 49 00:05:11,940 --> 00:05:13,130 the next whole week. 50 00:05:13,130 --> 00:05:18,810 Guessing the solution for the recurrence relation is possibly the most challenging part of solving 51 00:05:18,810 --> 00:05:21,380 the recurrence relation. 52 00:05:21,380 --> 00:05:28,350 But in this video, we will be focusing on how to solve the guess if we have the induction, 53 00:05:28,350 --> 00:05:31,050 if we have the guess right. 54 00:05:31,050 --> 00:05:36,330 If we guess the thing right how to prove it? 55 00:05:36,330 --> 00:05:41,400 So how do you prove by induction? 56 00:05:41,400 --> 00:05:47,490 Now if you remember, so we should have a base case. 57 00:05:47,490 --> 00:05:58,300 In this case, base case is say n = 1 and we have T1 is equals to 1, this is a something 58 00:05:58,300 --> 00:06:05,080 that is given and which is of course same as T2 times 1 minus 1 right? 59 00:06:05,080 --> 00:06:11,440 So this value is correct for T1 right? 60 00:06:11,440 --> 00:06:25,220 And now, we have the induction hypothesis, induction hypothesis which says that say for 61 00:06:25,220 --> 00:06:31,220 some n T(n) equals to 2 times n minus 1. 62 00:06:31,220 --> 00:06:39,450 And in the case, what is the inductive step? 63 00:06:39,450 --> 00:06:48,500 Inductive step is to prove the same statement for T(n plus 1) which is 2 times (n plus 1) 64 00:06:48,500 --> 00:06:53,340 minus 1 which is 2n plus 1. 65 00:06:53,340 --> 00:06:57,180 How do you prove it? 66 00:06:57,180 --> 00:07:06,240 Now, of course by the thing that is given to us T of n plus 1 equals to 2 times 2 plus 67 00:07:06,240 --> 00:07:23,320 T of n which is equals to 2 plus 2n minus 1 by the induction hypothesis which is equals 68 00:07:23,320 --> 00:07:29,930 to of course 2n plus 1 and that is what we had to prove. 69 00:07:29,930 --> 00:07:31,650 Right? 70 00:07:31,650 --> 00:07:35,310 Hence, we are done. 71 00:07:35,310 --> 00:07:46,060 Hence, we have proved the inductive step that means T(n) equals to 2n minus 1 which is for 72 00:07:46,060 --> 00:07:53,670 all n greater than or equal to 1. 73 00:07:53,670 --> 00:08:02,970 So this is the proof by induction for how once we have the guess right. 74 00:08:02,970 --> 00:08:06,800 Correct? 75 00:08:06,800 --> 00:08:13,890 So let us go over the next one. 76 00:08:13,890 --> 00:08:27,550 One more example say, so this example two says that T(1) equals to 1 and T(n) equals 77 00:08:27,550 --> 00:08:29,420 to n plus T(n minus 1). 78 00:08:29,420 --> 00:08:36,120 Again first of all, you have to guess it and let us imagine that somebody just comes up 79 00:08:36,120 --> 00:08:41,669 and manages to guess it correctly and say somebody comes and says that T(n) equals to 80 00:08:41,669 --> 00:08:45,630 n into n plus 1 by 2. 81 00:08:45,630 --> 00:08:51,760 Now once someone has guessed it, we have to prove it, we have to ensure that the guess 82 00:08:51,760 --> 00:09:02,370 is right and to get that is true, we have to again use induction. 83 00:09:02,370 --> 00:09:06,580 So like in the earlier case, we have to again prove this one by induction and let us see 84 00:09:06,580 --> 00:09:10,090 how we prove it again. 85 00:09:10,090 --> 00:09:21,780 Say base case, n equals to 1, of course T1 equals to 1 which is 1 times 1 plus 1 by 2 86 00:09:21,780 --> 00:09:23,250 right? 87 00:09:23,250 --> 00:09:32,390 Which is what, so the thing is correct for the case where n equals to 1. 88 00:09:32,390 --> 00:09:47,370 Now we have the induction hypothesis, what is this says that T(n) equals to Tn sorry 89 00:09:47,370 --> 00:09:56,250 Tn equals to n into n plus 1 by 2. 90 00:09:56,250 --> 00:10:13,010 Now in inductive step, we have to prove that T of n plus 1 equals to n plus 1 into n plus 91 00:10:13,010 --> 00:10:16,070 2 by 2. 92 00:10:16,070 --> 00:10:19,520 Now how do you prove it? 93 00:10:19,520 --> 00:10:37,830 Now T of n plus 1 is given as n plus T(n-1) which is n plus n into n plus 1 by 2. 94 00:10:37,830 --> 00:10:54,730 This is by induction hypothesis which is taking - sorry I made a mistake here. 95 00:10:54,730 --> 00:11:03,160 This is not n, this should be n plus 1 right? 96 00:11:03,160 --> 00:11:14,210 So, this is also so Tn equals to n plus Tn minus 1, Tn plus 1, has to be n plus 1 plus 97 00:11:14,210 --> 00:11:33,630 T(n) and this is equals to n plus 1 plus the given induction hypothesis which is n into 98 00:11:33,630 --> 00:11:34,820 n plus 1 by 2. 99 00:11:34,820 --> 00:11:43,170 So now I can take n plus 1 common in that case, I get 1 plus n by 2, so this is 2 plus 100 00:11:43,170 --> 00:11:52,360 n by 2 which is of course n plus 1 into n plus 2 by 2 which is what we had to prove. 101 00:11:52,360 --> 00:12:03,080 So we have T of n equals to n into n plus 1 by 2 for all n greater than equal to 1. 102 00:12:03,080 --> 00:12:14,460 Again the idea is simple if you can guess the value correctly for T(n), then you can 103 00:12:14,460 --> 00:12:18,779 prove what T(n) is by induction. 104 00:12:18,779 --> 00:12:21,040 Right? 105 00:12:21,040 --> 00:12:34,970 Let us see one more example, what can be the various guesses? 106 00:12:34,970 --> 00:12:50,860 So, this is we say Tower of Hanoi problem, right, so H(1) equals to 1 and H(n) equals 107 00:12:50,860 --> 00:12:52,610 to 1 plus H(n minus 1). 108 00:12:52,610 --> 00:12:55,810 Again, we first have to guess it. 109 00:12:55,810 --> 00:13:01,380 Now, what is the guess here? 110 00:13:01,380 --> 00:13:14,140 Say the guess is H(n) equals to 2 power n minus 1 and again we have to prove this one 111 00:13:14,140 --> 00:13:15,850 by induction. 112 00:13:15,850 --> 00:13:23,500 Note here that if you guess it wrong, we will not be able to prove it by induction or we 113 00:13:23,500 --> 00:13:25,130 are not be able to prove it. 114 00:13:25,130 --> 00:13:32,061 So thus, only if you guess it right we will be able to prove this statement. 115 00:13:32,061 --> 00:13:40,750 So there are people who actually come up with these cases by some various intuitions of 116 00:13:40,750 --> 00:13:48,220 their brain but and there are some techniques also which will help to come up with the correct 117 00:13:48,220 --> 00:13:54,430 guesses which we will study in next few lectures. 118 00:13:54,430 --> 00:13:59,770 But again for this particular problem, how do we prove this statement? 119 00:13:59,770 --> 00:14:08,380 Again and again, we have to look at the base case, so base case n equals to 1. 120 00:14:08,380 --> 00:14:15,170 So here, H(1) equals to 1 which is 2 power 1 minus 1 which is 1 which is right. 121 00:14:15,170 --> 00:14:18,470 So base is correct. 122 00:14:18,470 --> 00:14:38,399 So induction hypothesis say H(n) equals to 2 power n minus 1, inductive step, so 123 00:14:38,399 --> 00:14:53,180 we have to prove, so to prove, H of n plus 1 equals to 2 power n plus 1 minus 1. 124 00:14:53,180 --> 00:15:04,690 Now let us see, H(n) equals to sorry, H of n plus 1 equals to by is given 2 times H(n) 125 00:15:04,690 --> 00:15:08,290 which is 1 plus 2 times 2 power n minus 1. 126 00:15:08,290 --> 00:15:25,270 This is again by induction hypothesis which is 1 plus 2 times n plus 1 minus 2 which is 127 00:15:25,270 --> 00:15:30,840 2 times n plus 1 minus 1 and this is what we had to prove. 128 00:15:30,840 --> 00:15:39,060 So H of n equals to 2 power n minus 1 for all n greater than or equal to 1. 129 00:15:39,060 --> 00:15:47,010 Note that, this is not only a way to proving the recurrence, this also if you go back to 130 00:15:47,010 --> 00:15:54,870 our previous video, this gives us a compact form for the number of moves required for 131 00:15:54,870 --> 00:15:58,430 the Tower of Hanoi problem. 132 00:15:58,430 --> 00:16:10,020 So the Tower of Hanoi problem, therefore requires 2 power n minus 1 moves and we got it by first 133 00:16:10,020 --> 00:16:13,780 modeling it as a recurrence relation and then solving the recurrence relation. 134 00:16:13,780 --> 00:16:19,910 Now how did you solve the recurrence relation, we first guess the recurrence relation and 135 00:16:19,910 --> 00:16:26,850 then we prove that the guess is right. 136 00:16:26,850 --> 00:16:35,300 So this is how most of the counting problems work, you first model it a recurrence relation 137 00:16:35,300 --> 00:16:38,120 and then you solve the recurrence relation. 138 00:16:38,120 --> 00:16:48,420 But this is all this is fine, if you can guess the recurrence relations correctly. 139 00:16:48,420 --> 00:16:53,430 You first guess the recurrence relation and then prove it using induction. 140 00:16:53,430 --> 00:16:59,270 The main question is how do you guess the solution? 141 00:16:59,270 --> 00:17:06,189 And we will be doing this problem of how to guessing the solution to the recurrence relation 142 00:17:06,189 --> 00:17:08,139 in the next video. 143 00:17:08,139 --> 00:17:14,860 We will see one of the techniques and in the the next few videos we will see the other 144 00:17:14,860 --> 00:17:15,860 techniques. 145 00:17:15,860 --> 00:17:16,609 Thank you.