1 00:00:02,020 --> 00:00:02,770 Hi, everyone. 2 00:00:02,800 --> 00:00:09,220 So in this video, we are going to discuss this question, Jack, if the phrase altered using recursion, 3 00:00:09,940 --> 00:00:13,210 we can easily use all this question using for loop or by loop. 4 00:00:13,360 --> 00:00:17,920 But since we are learning recursion, so we will use the occasion to check if the errors are dead or 5 00:00:17,920 --> 00:00:18,230 not. 6 00:00:19,150 --> 00:00:21,040 So input will basically be very. 7 00:00:22,000 --> 00:00:27,850 And we will take how many elements are present, so the size of the area and the area itself, so since 8 00:00:27,910 --> 00:00:28,980 we are going to use a caution. 9 00:00:29,020 --> 00:00:31,180 So first, let us discuss about the base case. 10 00:00:32,049 --> 00:00:38,650 So what would be the best case if the number of elements is zero or we can say the number of elements 11 00:00:38,650 --> 00:00:41,830 is one, then in that case I can say my area sorted. 12 00:00:43,780 --> 00:00:49,180 So basically, they're the functional people I will return, true or false, whether that is sorted 13 00:00:49,180 --> 00:00:56,080 or that is not sorted and my function will take that as input and it will take how many elements are 14 00:00:56,080 --> 00:00:57,400 there inside the area. 15 00:00:58,120 --> 00:00:59,490 And this will be the best case. 16 00:00:59,770 --> 00:01:06,520 So if that is an element or the area has only one element, then I can say my area sorted. 17 00:01:06,550 --> 00:01:10,770 So basically in this case, I will return to address what we need to do. 18 00:01:11,560 --> 00:01:13,150 So this is already. 19 00:01:14,870 --> 00:01:21,350 So for using that occasion, we need to split our big problem into smaller problems, so there are two 20 00:01:21,350 --> 00:01:22,570 ways for breaking the area. 21 00:01:22,850 --> 00:01:24,590 So first, which is basically this one. 22 00:01:25,430 --> 00:01:31,490 So I will work on this small part of the problem and the commission will work on this part. 23 00:01:31,700 --> 00:01:35,960 The second way of making our ready to use U.S. is basically this way. 24 00:01:37,140 --> 00:01:43,140 I will work on this small problem and the commission will work on this big problem, so there are two 25 00:01:43,140 --> 00:01:44,650 ways of splitting the area. 26 00:01:44,880 --> 00:01:48,360 So there are two ways of making our big problem into smaller problem. 27 00:01:48,370 --> 00:01:49,480 First, using this way. 28 00:01:50,340 --> 00:01:52,560 So I will give the commission this area to solve. 29 00:01:52,800 --> 00:01:56,040 And similarly, in this way, I will give you a commission decided to solve. 30 00:01:56,920 --> 00:01:58,540 So first, let's discuss this way. 31 00:01:58,930 --> 00:01:59,740 So what do. 32 00:02:01,780 --> 00:02:03,040 So this is area. 33 00:02:04,180 --> 00:02:05,660 So first of all, I can check. 34 00:02:06,610 --> 00:02:11,600 So this is my 08 and next the next one in next to and so on. 35 00:02:11,890 --> 00:02:17,730 So first of all, I can check whether AOF zero is Gherardini of one. 36 00:02:18,610 --> 00:02:21,540 So if this is a condition, that means there is not totted. 37 00:02:21,700 --> 00:02:23,880 So in this case, I will directly return false. 38 00:02:24,400 --> 00:02:27,590 I can actually done false from here and is what we need to do. 39 00:02:27,790 --> 00:02:28,870 So this is already. 40 00:02:31,630 --> 00:02:34,810 So I am checking the 08 element and the first element. 41 00:02:35,200 --> 00:02:40,440 So if the root element is greater than the first element, I returning false in the end. 42 00:02:40,500 --> 00:02:46,600 But what I will do so in the end part after comparing these two elements, so I will call the kitchen, 43 00:02:46,600 --> 00:02:51,610 I have worked on this small problem, so I will call the kitchen on this big problem and the kitchen 44 00:02:51,610 --> 00:02:57,510 will return me a bowl value, whether this array, this small area is sorted or not. 45 00:02:57,700 --> 00:03:02,620 So recursion will return me a true or false value and I will return that to Werfel's value. 46 00:03:02,680 --> 00:03:03,160 Simple. 47 00:03:04,240 --> 00:03:05,320 So let's ride the gold. 48 00:03:08,310 --> 00:03:13,740 So the name of the file is precautionary because in an edit or CBP and what we need to do. 49 00:03:15,060 --> 00:03:20,610 So let's create a function of the functional people and let's say the name of the function is is sorted. 50 00:03:21,420 --> 00:03:27,420 So what this function will take, it will take out as input and it will take how many elements are there 51 00:03:27,420 --> 00:03:29,640 inside the room, basically the size of the area. 52 00:03:30,000 --> 00:03:31,400 So this case is very simple. 53 00:03:32,040 --> 00:03:32,520 If. 54 00:03:34,820 --> 00:03:37,430 If my air is empty or. 55 00:03:39,220 --> 00:03:45,360 It is containing only one element, so in that case, what I will do, so I will return to my area, 56 00:03:45,360 --> 00:03:46,870 sorted, simple. 57 00:03:47,070 --> 00:03:49,830 So this is simple biscuits and now what we can do. 58 00:03:51,470 --> 00:03:52,490 So what do we do now? 59 00:03:52,910 --> 00:03:53,960 So if this is my area. 60 00:03:56,570 --> 00:04:02,390 I can't compare the 08 element and the first element, so if the 08 element is greater than the first 61 00:04:02,390 --> 00:04:05,630 element, then I can say that is not certain. 62 00:04:05,630 --> 00:04:10,030 I will return false without calling records and there is no need to call the occasion. 63 00:04:10,340 --> 00:04:11,700 So let's check this condition. 64 00:04:12,110 --> 00:04:20,029 So if AOF zero is the first in the 08 element, is then the first element, then we know the answer 65 00:04:20,120 --> 00:04:21,550 that the error is not sorted. 66 00:04:21,560 --> 00:04:23,290 So we cannot let it unfold from here. 67 00:04:24,050 --> 00:04:25,320 Otherwise what we need to do. 68 00:04:25,640 --> 00:04:26,720 So what I'm doing. 69 00:04:28,650 --> 00:04:33,940 I'm comparing the 08 element and the first element, so my small work has been done. 70 00:04:34,320 --> 00:04:39,390 I have completed my small work, so now I have worked on this small problem. 71 00:04:39,390 --> 00:04:41,370 So I will call the guys on this. 72 00:04:41,410 --> 00:04:41,690 Eddie. 73 00:04:42,000 --> 00:04:45,170 So this is a then they are easy. 74 00:04:45,420 --> 00:04:46,410 So what is this? 75 00:04:46,440 --> 00:04:47,640 This is a plus one. 76 00:04:47,870 --> 00:04:49,260 Remember pointers. 77 00:04:49,890 --> 00:04:51,700 So you should remember pointillism. 78 00:04:51,720 --> 00:04:52,890 So this is a plus one. 79 00:04:53,800 --> 00:04:55,130 So I need to pass this, Eddie. 80 00:04:56,070 --> 00:05:01,620 And here, the size of the area was and so what is the size of this area, the size of this area and 81 00:05:01,620 --> 00:05:03,870 minus one because of this one element? 82 00:05:03,880 --> 00:05:04,980 So this is one element. 83 00:05:04,990 --> 00:05:07,140 So the size of this area and minus one. 84 00:05:07,350 --> 00:05:10,550 So let's call occasion on this small area. 85 00:05:12,620 --> 00:05:16,460 So Boole is smaller. 86 00:05:17,510 --> 00:05:18,350 And assorted. 87 00:05:19,870 --> 00:05:22,630 So what I didn't do, I need to collocation it started. 88 00:05:23,560 --> 00:05:30,730 I need to pass this, Mollari smaller is E-Plus one, and the number of elements is reduced by one, 89 00:05:30,730 --> 00:05:31,670 so end minus one. 90 00:05:33,220 --> 00:05:38,440 So this function takes areas input and the sizes input and it will return, whether that is or did or 91 00:05:38,440 --> 00:05:38,680 not. 92 00:05:39,010 --> 00:05:43,100 So basically that equation will return, whether this area is sorted or not. 93 00:05:43,300 --> 00:05:45,090 So after getting that. 94 00:05:45,490 --> 00:05:46,270 So if. 95 00:05:49,730 --> 00:05:54,770 If that is sorted, so if the small at sorted, I will return to. 96 00:05:56,170 --> 00:05:59,530 It's a small area sorted, I will return true in the early part. 97 00:06:00,810 --> 00:06:05,690 I will return fault if the smaller is not sorted, then how can the three can be sorted? 98 00:06:05,910 --> 00:06:07,810 So the part I will return false. 99 00:06:08,670 --> 00:06:13,500 So what I am doing here, so the value of is smaller is true. 100 00:06:13,650 --> 00:06:16,020 If its value is true, then I am returning true. 101 00:06:16,200 --> 00:06:19,000 If its value is false, then I am returning false. 102 00:06:19,260 --> 00:06:20,930 So basically, can I write like this. 103 00:06:20,940 --> 00:06:22,290 So let's come and do this one. 104 00:06:24,700 --> 00:06:27,310 So basically, I can write like this, basically written. 105 00:06:28,670 --> 00:06:36,440 Is smaller started, so this is exactly the same, so here, if that Ismailov sorted that true. 106 00:06:36,500 --> 00:06:38,000 So I was returning true. 107 00:06:38,150 --> 00:06:39,800 If those smaller, that is false. 108 00:06:40,250 --> 00:06:41,750 If these smaller is not ordered. 109 00:06:41,750 --> 00:06:43,400 So I wondered I was returning false. 110 00:06:43,520 --> 00:06:44,930 And this is exactly the same. 111 00:06:45,290 --> 00:06:47,240 If it's really true, I will return true. 112 00:06:47,270 --> 00:06:49,550 If it's values fault, I will return false. 113 00:06:49,790 --> 00:06:50,330 Simple. 114 00:06:51,720 --> 00:06:53,400 So now let's test our function. 115 00:06:54,970 --> 00:06:55,950 Let's create another. 116 00:06:59,860 --> 00:07:04,450 Let's say the elements are one, two, three, four and five. 117 00:07:05,990 --> 00:07:07,250 So let's call the function. 118 00:07:08,330 --> 00:07:10,490 If it started. 119 00:07:11,550 --> 00:07:15,000 I will give Eddie and his number of elements his five. 120 00:07:16,110 --> 00:07:17,520 So we can print the message. 121 00:07:20,230 --> 00:07:20,890 Sorted. 122 00:07:23,320 --> 00:07:25,600 And the part I can bring the message. 123 00:07:30,120 --> 00:07:30,870 Nazar did. 124 00:07:32,220 --> 00:07:33,630 So let's see what will be the output. 125 00:07:38,690 --> 00:07:40,040 So let's send our file. 126 00:07:41,960 --> 00:07:47,260 So basically, the output is coming out to be sorted, so let's see how it is working. 127 00:07:47,270 --> 00:07:48,380 Let's write a novel called. 128 00:07:50,170 --> 00:07:56,470 So basically, this is the area that is one, two, three, four, five, so my area is. 129 00:07:58,550 --> 00:08:04,310 One, two, three, four and five, and the number of elements is five, so this function is taking 130 00:08:04,310 --> 00:08:06,840 out as input and it is taking how many elements are there. 131 00:08:07,430 --> 00:08:14,000 So the first step is basically size is not zero size sizes, not zero size is not one. 132 00:08:14,300 --> 00:08:16,720 So zero element is bigger than the first element. 133 00:08:16,730 --> 00:08:18,260 No one is not bigger to do. 134 00:08:18,470 --> 00:08:19,490 So call on this smaller. 135 00:08:20,120 --> 00:08:22,190 So I will call on smaller. 136 00:08:23,520 --> 00:08:27,780 And the smaller is two, three, four, five, and the number of elements for. 137 00:08:29,160 --> 00:08:35,610 So then size is not zero sizes, not one, though, is not greater than three, so I will call on the 138 00:08:35,610 --> 00:08:36,190 smaller. 139 00:08:38,190 --> 00:08:40,570 So I will call on similary, three, four, five. 140 00:08:40,830 --> 00:08:48,360 And number three, so three say it is not this is not one and it's not good than four. 141 00:08:48,600 --> 00:08:50,160 So I will call on this small area. 142 00:08:51,300 --> 00:08:53,030 So I'm calling on four and five. 143 00:08:54,300 --> 00:08:56,220 So now size is two. 144 00:08:57,000 --> 00:09:01,880 So size is not zero, size is not one and four is not bigger than five. 145 00:09:01,920 --> 00:09:03,480 So I will call on this more, Larry. 146 00:09:04,980 --> 00:09:09,480 Size is one, size is not zero, but size is one, so size is one. 147 00:09:10,500 --> 00:09:13,620 If that is one return, true, so dysfunction will return to. 148 00:09:15,290 --> 00:09:21,770 This function will return true, so basically I have worked for this problem, so basically for a small 149 00:09:21,770 --> 00:09:23,840 then five and smaller array sorted. 150 00:09:24,020 --> 00:09:25,100 So I will return to. 151 00:09:26,920 --> 00:09:33,310 So I compare 2004 and then I called on this small area, so small areas are done through this audit. 152 00:09:33,340 --> 00:09:34,960 So that means the big areas also saw. 153 00:09:35,140 --> 00:09:35,800 So I will return. 154 00:09:36,790 --> 00:09:39,210 So, too, is basically smaller than three. 155 00:09:39,850 --> 00:09:43,540 So I worked on this problem and I called the equation for this area. 156 00:09:43,690 --> 00:09:45,310 And this area is basically sorted. 157 00:09:45,310 --> 00:09:46,170 It is running through. 158 00:09:46,360 --> 00:09:48,220 So basically the big areas also sorted. 159 00:09:48,230 --> 00:09:49,120 So I really don't know. 160 00:09:49,690 --> 00:09:51,000 So I compared one and two. 161 00:09:51,220 --> 00:09:52,840 So one is smaller than two. 162 00:09:52,840 --> 00:09:56,850 And this area told me that this small area sorted. 163 00:09:57,100 --> 00:09:59,470 So the dining room for this small area. 164 00:09:59,470 --> 00:10:01,010 So that means the whole area sorted. 165 00:10:01,030 --> 00:10:02,020 So I will return to. 166 00:10:03,320 --> 00:10:08,050 So that's how this function will return true for this area one, two, three, four and five. 167 00:10:08,060 --> 00:10:12,890 So if it is returning true, I am printing the area sorted so the output is sorted out. 168 00:10:13,820 --> 00:10:17,660 Now, let's take one more example in which case the area is not sorted. 169 00:10:19,210 --> 00:10:25,570 So let's say let's replace the values of this is five and this is four, so one, two, three, five 170 00:10:25,570 --> 00:10:25,970 and four. 171 00:10:26,200 --> 00:10:29,860 So for this I should get the arrays not sorted. 172 00:10:30,160 --> 00:10:31,510 So let's run our file. 173 00:10:36,170 --> 00:10:40,510 And the output is not sorted, so let's see how it is working. 174 00:10:43,020 --> 00:10:50,790 So basically, you are passing the area, so you are giving this area one, two, three, five and four. 175 00:10:52,870 --> 00:10:57,760 And the number of elements is five, the value of five, so you will compare. 176 00:10:57,940 --> 00:11:02,050 So five is not zero, five is not one number of elements is not zero, not one. 177 00:11:02,590 --> 00:11:05,340 So it will call on smaller. 178 00:11:05,900 --> 00:11:09,880 And first of all, before calling, I am taking zero tolerance in the first 10 minutes. 179 00:11:09,880 --> 00:11:10,920 So I will check one or two. 180 00:11:11,140 --> 00:11:12,340 So in less than two. 181 00:11:12,520 --> 00:11:18,730 So I will call on this Mollari E plus and minus the number of elements is four and the smaller is two, 182 00:11:18,730 --> 00:11:19,720 three, five and four. 183 00:11:21,100 --> 00:11:25,890 So the size is not zero, the size is not one who is basically less than three. 184 00:11:26,140 --> 00:11:28,070 So I will call that equation on smaller. 185 00:11:28,070 --> 00:11:28,360 Very. 186 00:11:29,360 --> 00:11:33,790 So I will call that equation on three, five and four number of elements, history and minus one. 187 00:11:34,940 --> 00:11:39,590 So size is not zero, size is not one and three is less than five. 188 00:11:39,770 --> 00:11:41,530 So we will call on the smaller. 189 00:11:42,620 --> 00:11:49,610 So call on this, Mollari, the elements are five and four and the size is two, so size is not zero, 190 00:11:49,610 --> 00:11:53,240 size is not one, and five is basically bigger than four. 191 00:11:53,480 --> 00:11:56,180 So five is basically bigger than four. 192 00:11:56,330 --> 00:11:57,470 So I will return false. 193 00:11:57,650 --> 00:11:59,240 So I will return false from here. 194 00:12:01,040 --> 00:12:04,580 I will return false from here and then what will happen? 195 00:12:04,770 --> 00:12:07,660 So this is right is less than five. 196 00:12:07,970 --> 00:12:10,880 So the question is telling me that this smaller is not sorted. 197 00:12:10,880 --> 00:12:11,730 We are getting false. 198 00:12:11,960 --> 00:12:15,200 So if the smaller is not sorted, how can the big three will be sorted? 199 00:12:15,350 --> 00:12:16,870 So I'm likely returning false. 200 00:12:17,720 --> 00:12:19,910 You can see I am actually returning the value. 201 00:12:19,910 --> 00:12:22,150 I'm returning the small sorted area. 202 00:12:22,490 --> 00:12:25,800 So if this area is not sorted, if this is false, I will returning false. 203 00:12:26,090 --> 00:12:27,590 So again, so this was true. 204 00:12:28,010 --> 00:12:29,200 I worked for this problem. 205 00:12:29,210 --> 00:12:32,430 So too is basically less than three, but the small is not certain. 206 00:12:32,600 --> 00:12:35,280 So the smaller is not smaller, is returning false. 207 00:12:35,300 --> 00:12:37,700 So if it is returning false and likely returning false. 208 00:12:38,090 --> 00:12:40,790 So if this is not sorted, how can the bigger they will be sorted. 209 00:12:40,800 --> 00:12:41,790 So I am returning false. 210 00:12:42,260 --> 00:12:46,880 Similarly, when is less than two and recording is telling me this area is not sorted. 211 00:12:47,060 --> 00:12:49,170 So how can that be sorted. 212 00:12:49,190 --> 00:12:50,350 So I am returning false. 213 00:12:50,660 --> 00:12:52,060 So if I am returning false. 214 00:12:52,310 --> 00:12:56,000 So if this is false I will go into l'esprit and I will print not sorted. 215 00:12:56,150 --> 00:13:00,670 And you can see the output is not sorted, the output is not sorted. 216 00:13:00,860 --> 00:13:02,530 So that's how this function is working. 217 00:13:03,800 --> 00:13:05,550 So I told you there are two ways. 218 00:13:06,020 --> 00:13:07,160 So one more thing. 219 00:13:08,170 --> 00:13:14,860 So how we are calling our problem, how we are calling it question, so I'm calling recursion like this. 220 00:13:16,070 --> 00:13:21,200 First time checking the 08 element and the first element, and then I'm calling that equation for. 221 00:13:22,620 --> 00:13:27,090 This area, so you can do the opposite also for this problem, what you can do first. 222 00:13:28,130 --> 00:13:34,900 First, you can call dedication for this, Mulready, and then you can check 08 and the first element. 223 00:13:34,910 --> 00:13:35,820 So let's do that. 224 00:13:35,840 --> 00:13:37,310 So let's create another function. 225 00:13:39,170 --> 00:13:43,760 So Boulle is slated to. 226 00:13:45,730 --> 00:13:49,990 So it will take ideas, input, and it will take how many elements are present. 227 00:13:52,280 --> 00:13:58,370 So we can just copy the best case, this case will remain same, if that is Amberleigh or less containing 228 00:13:58,370 --> 00:14:01,080 only one element, then in that case, my order. 229 00:14:02,780 --> 00:14:08,480 So what I want to do here is so in this function, first I am taking this route and the first element 230 00:14:08,480 --> 00:14:10,660 and then I am calling the equation for the small area. 231 00:14:11,000 --> 00:14:14,530 But for this problem, what you can do first, you can call on this, Mulready. 232 00:14:14,750 --> 00:14:17,510 So let's call for this, Mulready. 233 00:14:17,780 --> 00:14:19,550 So let's copy this line. 234 00:14:21,160 --> 00:14:25,680 I am calling medication for this malaria first time, checking whether it is malaria sorted or not. 235 00:14:26,110 --> 00:14:27,550 So you can right here. 236 00:14:27,670 --> 00:14:28,390 So if. 237 00:14:29,590 --> 00:14:31,360 This smaller that is not sorted. 238 00:14:34,310 --> 00:14:38,390 So if smaller aid is not sorted, then you can return false. 239 00:14:40,140 --> 00:14:40,680 Simple. 240 00:14:41,570 --> 00:14:47,620 Otherwise, so what I'm doing here is first I am calling the equation for the smaller. 241 00:14:48,620 --> 00:14:54,770 So if the smaller that is returning false, if the smaller is returning for the smaller is not sorted. 242 00:14:55,070 --> 00:14:56,270 So you can return false. 243 00:14:56,900 --> 00:15:00,120 OK, this is not the bigger is also not certain. 244 00:15:00,380 --> 00:15:01,820 So if it is returning to. 245 00:15:03,140 --> 00:15:08,570 So if we will reach this land line number 29, so if it is returning true, then we need to check this 246 00:15:08,600 --> 00:15:09,170 root element. 247 00:15:09,170 --> 00:15:14,450 And the first element also, we need to do the comparison, so let's do the comparison so that this 248 00:15:14,450 --> 00:15:16,100 line is sorted. 249 00:15:16,430 --> 00:15:21,360 So now let's compare the zeroth element and the first element. 250 00:15:21,380 --> 00:15:25,230 So if you the any of one, I will return false. 251 00:15:25,250 --> 00:15:26,210 That is not sorted. 252 00:15:26,780 --> 00:15:29,900 Otherwise I will return to the Elzbieta I will return to. 253 00:15:32,390 --> 00:15:35,310 So the working is exactly the working is nearly the same. 254 00:15:36,440 --> 00:15:38,390 The working is nearly the same. 255 00:15:38,540 --> 00:15:39,650 So here's what we are doing. 256 00:15:39,960 --> 00:15:46,330 So first, I am calling the equation for this Eddie, for this malerie plus one and the number of elements 257 00:15:46,430 --> 00:15:46,670 and my. 258 00:15:47,330 --> 00:15:50,610 So that's Millerick and misogynous malartic and not order. 259 00:15:50,870 --> 00:15:54,720 So I have the smaller days and I thought it was the smaller array sorted through. 260 00:15:55,160 --> 00:16:00,470 So if the smaller area is a standing fault, so if it is retaining falls is a smaller is not then the 261 00:16:00,470 --> 00:16:01,840 bigger is also not shorter. 262 00:16:01,850 --> 00:16:04,930 So we are turning faults otherwise if it is returning true. 263 00:16:05,210 --> 00:16:12,020 So no, I don't mind if this smaller is returning true, then I need to compare this element and the 264 00:16:12,020 --> 00:16:12,810 first element. 265 00:16:13,250 --> 00:16:18,860 So if zeroth element is less then first element then the computer is ordered. 266 00:16:18,890 --> 00:16:19,550 So I'm returning. 267 00:16:19,550 --> 00:16:21,080 True, otherwise I am returning false. 268 00:16:22,700 --> 00:16:24,440 So let's test this function also. 269 00:16:24,470 --> 00:16:26,150 So this is a better way to write the code. 270 00:16:27,070 --> 00:16:28,000 It started to. 271 00:16:29,500 --> 00:16:31,630 So let's call the function is started to. 272 00:16:33,190 --> 00:16:34,900 And the output should be not sorted. 273 00:16:39,010 --> 00:16:42,760 So the output is not sorted, and that's just for sorted, Eddie. 274 00:16:44,000 --> 00:16:47,720 So this is four and five. 275 00:16:51,200 --> 00:16:52,910 So our protests started. 276 00:16:52,940 --> 00:16:57,520 So this is a Saturday, so I told you, there are two ways of making our. 277 00:16:59,120 --> 00:17:04,710 So remember, initially I told you there are two ways of breaking our area. 278 00:17:04,910 --> 00:17:06,800 So the first was basically. 279 00:17:07,839 --> 00:17:13,839 I will I will solve this problem and I will apply the commission on this area the other way of solving 280 00:17:13,839 --> 00:17:17,589 the problem that their way of splitting our area into two parts, basically. 281 00:17:17,619 --> 00:17:24,060 First, I will work on the last problem and I will work and dedication will work on this small area. 282 00:17:24,460 --> 00:17:26,880 So we have written the code for this. 283 00:17:27,099 --> 00:17:29,020 Now let's write the code for this, Eddie. 284 00:17:34,050 --> 00:17:37,050 So what I want to do, what I want to say it is see? 285 00:17:39,460 --> 00:17:42,730 So initially, I was comparing the zero element in the first element. 286 00:17:42,970 --> 00:17:46,650 Now what I will do, I will compare the last element and the second last element. 287 00:17:46,900 --> 00:17:51,840 So the last element has mix and minus one, and the second last element has an X and minus two. 288 00:17:52,150 --> 00:17:57,500 So if F and minus two is good, then minus one I will return false. 289 00:17:57,550 --> 00:17:58,600 That is not sorted. 290 00:17:59,320 --> 00:18:00,340 That is not sorted. 291 00:18:00,790 --> 00:18:02,730 Otherwise, if this condition is false. 292 00:18:02,770 --> 00:18:05,170 What I will do so I will call Dacogen. 293 00:18:05,170 --> 00:18:07,650 I have worked for this small problem. 294 00:18:07,660 --> 00:18:13,570 Now I will call it equation for deciding and recursion will tell me whether this is sorted or not solved 295 00:18:13,570 --> 00:18:18,230 because it will return true or false value and similarly I will return that value. 296 00:18:18,550 --> 00:18:24,400 So if this small array sorted and we already checked this smaller problem, so the computer is sorted, 297 00:18:24,640 --> 00:18:26,860 you don't know if this idea is not certain. 298 00:18:26,860 --> 00:18:29,800 If the similarity is not sorted, then how can the big three will be sorted? 299 00:18:29,800 --> 00:18:30,730 So I will return false. 300 00:18:31,090 --> 00:18:34,890 So I will directly return whether I will return the value. 301 00:18:35,230 --> 00:18:36,220 So let's write the code. 302 00:18:36,230 --> 00:18:39,220 So the name of the function is is sorted three. 303 00:18:41,040 --> 00:18:41,760 So, Abul. 304 00:18:43,040 --> 00:18:46,940 Is sorted three, it will take. 305 00:18:48,290 --> 00:18:53,450 And it has endured and it will take how many elements are there, so be it case will remain the same 306 00:18:53,450 --> 00:18:54,590 if that is empty. 307 00:18:55,770 --> 00:18:56,580 If that is an. 308 00:18:57,990 --> 00:19:03,990 Or it is containing only one element then return true, otherwise you need to we can compare. 309 00:19:04,200 --> 00:19:06,300 So if the second last element. 310 00:19:07,290 --> 00:19:09,600 Is greater in the last element. 311 00:19:12,360 --> 00:19:17,100 Then I can return false that marriage is not sorted otherwise for Tulu. 312 00:19:18,010 --> 00:19:19,510 We will call it equation. 313 00:19:20,950 --> 00:19:25,770 So I will call Dacogen on this already, so let's call verification on similary. 314 00:19:29,170 --> 00:19:33,220 That is still a and the number of elements and minus one. 315 00:19:34,880 --> 00:19:38,730 So what I'm doing here is, see, this is our area. 316 00:19:40,220 --> 00:19:41,030 This is a. 317 00:19:42,510 --> 00:19:48,120 And I am comparing the second last element and the last element, so I'm comparing the last and the 318 00:19:48,120 --> 00:19:48,960 second last element. 319 00:19:49,200 --> 00:19:49,830 So if. 320 00:19:51,510 --> 00:19:56,410 Now, that is correct, so if the if the last element defense minus one is the last element is greater 321 00:19:56,430 --> 00:19:59,170 than the second last element, so I will reach at this line. 322 00:19:59,550 --> 00:20:06,000 So what I'm doing here is I am calling the recursion on this area and for this idea how we can pass 323 00:20:06,000 --> 00:20:06,450 this area. 324 00:20:06,630 --> 00:20:08,580 So how we can pass this added to the recursion. 325 00:20:09,030 --> 00:20:13,740 So we need to pass it and the number of elements so you can see the number of elements. 326 00:20:13,740 --> 00:20:17,270 And minus one, because we removed we are not passing this element. 327 00:20:17,280 --> 00:20:18,910 We are passing only this area. 328 00:20:19,140 --> 00:20:21,190 So the number of elements will reduce by one. 329 00:20:21,510 --> 00:20:23,910 So that's why at it and a number of elements. 330 00:20:25,140 --> 00:20:28,080 So N minus one third equation will tell me. 331 00:20:28,260 --> 00:20:29,310 So the equation will return. 332 00:20:29,310 --> 00:20:34,390 True, if this is ordered, recursion will return false if this array is not sorted. 333 00:20:34,830 --> 00:20:36,850 So if recursion is returning false. 334 00:20:37,020 --> 00:20:40,820 So if this is not sorted, then the bigot is also not sorted. 335 00:20:40,830 --> 00:20:41,770 So I will return false. 336 00:20:42,270 --> 00:20:44,140 So that's why I am returning directly. 337 00:20:44,310 --> 00:20:48,740 So if this area, this model that is not sorted, then the results are not sorted. 338 00:20:48,750 --> 00:20:49,950 So I likely returning. 339 00:20:50,370 --> 00:20:56,760 Similarly, if this a small area sorted, if the smaller is sorted and we already checked for this condition, 340 00:20:56,760 --> 00:21:03,200 we will reject these elements then this sorted and these elements are in the correct position. 341 00:21:03,210 --> 00:21:05,390 So I will return to the also. 342 00:21:05,780 --> 00:21:07,530 So that's why I am returning directly. 343 00:21:08,900 --> 00:21:11,300 So now let's test this function is Sawtell three. 344 00:21:14,410 --> 00:21:19,810 So the output should be true for one, two, three, four and five, so the output is true and let's 345 00:21:19,810 --> 00:21:21,810 see how the code is working. 346 00:21:25,510 --> 00:21:26,860 So let's take the example. 347 00:21:27,990 --> 00:21:34,020 One, two, three, four and five, so one, two, three, four and five, the number of elements is 348 00:21:34,020 --> 00:21:38,400 five, so size is not zero, size is not one and basically four is less than five. 349 00:21:38,640 --> 00:21:40,310 So I will call on this, Mollari. 350 00:21:40,710 --> 00:21:43,170 So I am calling on smaller and minus one. 351 00:21:43,410 --> 00:21:49,320 So the elements are one, two, three and four and the size is four sizes, not zero sizes, not one, 352 00:21:49,440 --> 00:21:51,360 and basically three is less than four. 353 00:21:51,510 --> 00:21:56,550 So I will call on the smaller one to three then monofilament history. 354 00:21:57,060 --> 00:22:02,490 So basically size is not zero sizes, not one and two is less than three. 355 00:22:02,610 --> 00:22:03,930 So I will call on the smaller. 356 00:22:05,040 --> 00:22:08,510 Smaller is one and two and sizes basically two. 357 00:22:09,060 --> 00:22:14,630 So basically the size is not zero sizes, not one and one is basically less than two. 358 00:22:14,640 --> 00:22:18,000 So I will call on the smaller three, which is one size is one. 359 00:22:18,270 --> 00:22:21,700 So size is not zero, but size is one now, so size is one. 360 00:22:21,720 --> 00:22:24,120 Now if the value of size is when you will return. 361 00:22:24,120 --> 00:22:24,390 True. 362 00:22:25,470 --> 00:22:26,730 So I will return to. 363 00:22:28,640 --> 00:22:29,630 I am returning to. 364 00:22:31,160 --> 00:22:38,660 So basically, this small area is sorted and we already checked for this condition, so the computer 365 00:22:38,660 --> 00:22:40,130 will be sorted, so I am returning. 366 00:22:40,130 --> 00:22:42,080 True, we are likely returning to. 367 00:22:43,690 --> 00:22:49,660 So this small area sorted the small area, so that's a big area will also be sorted because we already 368 00:22:49,660 --> 00:22:50,680 checked for two entry. 369 00:22:51,520 --> 00:22:54,880 So I will return through again, this small area sorted. 370 00:22:55,060 --> 00:22:56,520 So big area will also be sorted. 371 00:22:56,530 --> 00:22:57,710 So I'm returning through. 372 00:22:58,090 --> 00:23:03,240 So this small area sorted we are getting through from the guys into the bigger area will also be sorted. 373 00:23:03,520 --> 00:23:04,600 So I am returning through. 374 00:23:05,500 --> 00:23:06,170 So that's why. 375 00:23:06,580 --> 00:23:07,930 So that's how it is working. 376 00:23:07,930 --> 00:23:10,330 So through means sprint sorted. 377 00:23:11,020 --> 00:23:14,890 So now let's test for when I would add is not sorted. 378 00:23:16,320 --> 00:23:17,440 Let's replace the value. 379 00:23:18,270 --> 00:23:21,870 So let's say this is five and let's say this is three. 380 00:23:22,790 --> 00:23:27,200 So now this time I should get nauseated so the output is not sorted. 381 00:23:27,560 --> 00:23:31,460 Now let's again test let's but I don't have a code and let's see how it will work. 382 00:23:31,790 --> 00:23:33,380 So basically, this is. 383 00:23:34,380 --> 00:23:41,120 I already went to five, four and three, the number of elements is five, so I'm checking. 384 00:23:41,700 --> 00:23:46,520 So five is not zero, size is not zero, size is not one, then I am checking. 385 00:23:46,710 --> 00:23:48,570 So basically four is a good entry. 386 00:23:49,440 --> 00:23:51,810 So four is basically a good entry. 387 00:23:51,990 --> 00:23:53,340 So that is not certain. 388 00:23:53,370 --> 00:23:55,440 If that is not sorted, I will return false. 389 00:23:55,650 --> 00:24:01,100 So I will likely return false from here and this one loose fault. 390 00:24:01,110 --> 00:24:03,870 So I will go in the expert and I will bring not sorted. 391 00:24:04,260 --> 00:24:10,320 So let's do one thing, let's make it two and let's make it one, the one winwin and then let's see 392 00:24:10,350 --> 00:24:11,150 how it will work. 393 00:24:14,290 --> 00:24:15,820 So let's make it. 394 00:24:17,300 --> 00:24:20,250 To here and let me get one here, and that is true, that is. 395 00:24:20,600 --> 00:24:21,170 So this is. 396 00:24:22,140 --> 00:24:28,940 This is three, four and five for this area, this area is also not sorted, so the output should be 397 00:24:28,980 --> 00:24:29,640 not sorted. 398 00:24:30,480 --> 00:24:31,920 So the output is not sorted. 399 00:24:31,940 --> 00:24:33,770 And let's see how. 400 00:24:33,930 --> 00:24:34,680 Let's let's. 401 00:24:34,960 --> 00:24:35,520 And have a good. 402 00:24:35,890 --> 00:24:38,490 So this is the area to one. 403 00:24:40,490 --> 00:24:44,540 Three, four and five, and the number of elements is basically five. 404 00:24:46,300 --> 00:24:52,600 So sizes in all sizes, not one of four, is less than five, so call on the smaller, smaller is to 405 00:24:52,600 --> 00:24:54,180 one, three and four. 406 00:24:54,190 --> 00:24:59,190 Number of elements for size is not zero sizes, not one and three is less than four. 407 00:24:59,380 --> 00:25:00,850 So I will call on this, Larry. 408 00:25:01,970 --> 00:25:08,660 Smaller to one entry number of elements, history, so size is not zero, size is not one and one is 409 00:25:08,660 --> 00:25:09,310 less than three. 410 00:25:09,500 --> 00:25:14,900 So I will call on this smaller, smaller arrays to number of elements to. 411 00:25:15,080 --> 00:25:17,480 So size is not zero sizes, not one. 412 00:25:17,660 --> 00:25:18,580 But this is wrong. 413 00:25:19,580 --> 00:25:20,760 So two is bigger than one. 414 00:25:20,790 --> 00:25:22,990 So two is bigger than one return false. 415 00:25:23,360 --> 00:25:24,860 So I will return false from here. 416 00:25:26,640 --> 00:25:31,980 Now, this area is not sorted, I'm getting false communication, so this site is not sorted, that 417 00:25:32,070 --> 00:25:33,980 is the big area is also not sorted. 418 00:25:34,230 --> 00:25:36,750 So I'm likely returning, so I will return false. 419 00:25:37,740 --> 00:25:39,300 So this site is not sorted. 420 00:25:39,300 --> 00:25:39,460 Who? 421 00:25:39,480 --> 00:25:40,680 One tree is not sorted. 422 00:25:40,830 --> 00:25:42,660 So the computer is also not sorted. 423 00:25:42,660 --> 00:25:43,350 So I will return. 424 00:25:43,350 --> 00:25:43,770 False. 425 00:25:45,160 --> 00:25:46,450 So basically, this Eddie. 426 00:25:47,600 --> 00:25:48,520 Is not sorted. 427 00:25:49,190 --> 00:25:53,750 I'm getting calls from The Guardian, so that means the bigot is also not sorted, so I will return 428 00:25:53,750 --> 00:25:54,080 false. 429 00:25:54,380 --> 00:25:56,600 So if this value is false, I will go anywhere. 430 00:25:56,600 --> 00:25:59,980 The but I will print not sorted, not sorted is the right output. 431 00:26:00,410 --> 00:26:01,960 So that's how everything is working. 432 00:26:02,330 --> 00:26:05,920 So we can do so what we are doing here. 433 00:26:06,230 --> 00:26:08,610 So this is only just one variable. 434 00:26:08,810 --> 00:26:10,520 So what is the value of this variable. 435 00:26:10,710 --> 00:26:12,350 The value of this variable is this one. 436 00:26:12,800 --> 00:26:17,540 So you can just like look at it and you can post it here and there is no need. 437 00:26:18,630 --> 00:26:19,680 To create this variable. 438 00:26:21,180 --> 00:26:27,500 Simple, so this will work is hard, it will work, you can test it also, so the output should be not 439 00:26:27,520 --> 00:26:29,820 sorted, the output is not sorted. 440 00:26:30,060 --> 00:26:31,680 And similarly, if that is sorted. 441 00:26:33,120 --> 00:26:33,510 When? 442 00:26:34,970 --> 00:26:37,730 Two, three, four and five, so the output will be sorted now. 443 00:26:40,300 --> 00:26:41,440 Now, police are now. 444 00:26:42,640 --> 00:26:45,510 So we were creating this extra variable is more or less. 445 00:26:46,090 --> 00:26:47,570 So it was used only once. 446 00:26:47,590 --> 00:26:50,160 So why to create variables we can just basically return. 447 00:26:50,680 --> 00:26:53,040 OK, so this is it from this video. 448 00:26:53,080 --> 00:26:54,340 I will see you in the next one.