1 00:00:01,210 --> 00:00:02,800 Hey, guys, what's up? 2 00:00:03,220 --> 00:00:06,050 So our today's topic is sorting. 3 00:00:07,000 --> 00:00:08,590 So what is the meaning of sorting? 4 00:00:09,040 --> 00:00:11,050 So, for example, my Eddys. 5 00:00:12,860 --> 00:00:19,310 Let's say it is seven, five, three, six and eight. 6 00:00:19,940 --> 00:00:25,130 So, for example, this is my area now after sorting, this area will become. 7 00:00:27,970 --> 00:00:34,810 Three, five, six, seven and eight, OK, so this is starting. 8 00:00:36,200 --> 00:00:37,910 So this is my unsorted Eddie. 9 00:00:39,260 --> 00:00:41,570 And this is my sorted Eddie. 10 00:00:43,200 --> 00:00:47,960 OK, so sorting means so are the elements. 11 00:00:48,290 --> 00:01:00,200 So I have sorted my data so that it is sorted in ascending order, the elements are in ascending order. 12 00:01:01,560 --> 00:01:08,940 We can also sort the data in descending order, for example, eight, then seven, then six, then five 13 00:01:08,940 --> 00:01:09,530 and three. 14 00:01:09,870 --> 00:01:15,960 So this data is also sorted, but this data is sorted in descending order. 15 00:01:17,370 --> 00:01:19,940 OK, so the elements are in descending order. 16 00:01:20,700 --> 00:01:27,390 So generally when we say sorting, so when we say sorting, we generally means that increasing order. 17 00:01:27,630 --> 00:01:32,760 OK, so we generally mean that sorting means increasing orders or elements in increasing order. 18 00:01:33,180 --> 00:01:34,570 So this is General. 19 00:01:34,590 --> 00:01:40,500 OK, so when we say solidary, that means so that in increasing order. 20 00:01:42,090 --> 00:01:50,590 OK, so why do we need sorting, we need sorting to make our search searching process faster. 21 00:01:51,690 --> 00:01:55,930 So if I have sorted data, I can search much, much faster. 22 00:01:56,700 --> 00:01:59,100 So this is the main purpose of sorting. 23 00:01:59,700 --> 00:02:06,960 Now, there are many algorithms used for sorting, so we have many sorting algorithms. 24 00:02:08,490 --> 00:02:14,490 So some of them are listed here, for example, selections, art lovers, art and accounting, counting 25 00:02:14,490 --> 00:02:18,390 bucket for some quick and there are many more. 26 00:02:19,140 --> 00:02:25,620 OK, so there are many sorting algorithms that will sort the eddy. 27 00:02:26,640 --> 00:02:31,080 So in this video, we will talk about selection, Saad. 28 00:02:32,400 --> 00:02:38,640 OK, so let us try to understand how this election site works and how it will sort the data. 29 00:02:41,760 --> 00:02:45,120 So the selection, Sa'ad. 30 00:02:47,380 --> 00:02:49,730 So let's suppose let's take an example. 31 00:02:50,200 --> 00:02:52,690 So suppose this is my area. 32 00:02:56,120 --> 00:03:01,760 So the arrangements are, let's say, seven, five, three, six and eight above example. 33 00:03:01,790 --> 00:03:08,310 OK, now what it will say, take one point out here, let's say name it. 34 00:03:08,340 --> 00:03:13,300 I so what it will say, find the smallest element in the right hand side. 35 00:03:13,970 --> 00:03:16,180 So which is the smallest element in the right hand side. 36 00:03:16,190 --> 00:03:20,450 I think three is the smallest element compared three with seven. 37 00:03:21,490 --> 00:03:26,890 OK, so compared to David seven, which one is smaller, three is smaller than slap. 38 00:03:28,740 --> 00:03:36,630 Since is smaller, what I will do, I will swipe so that he will come here and seven will come here 39 00:03:37,260 --> 00:03:41,910 against all the elements, it will be same five, six and eight. 40 00:03:47,840 --> 00:03:55,310 OK, so since three is smaller than seven, I will do swapping, so here swapping take place. 41 00:03:57,860 --> 00:04:04,550 Now, what will happen at this point that I will move ahead now I will point to five, so we have to 42 00:04:04,550 --> 00:04:07,310 find the smallest element in the right hand side. 43 00:04:07,970 --> 00:04:10,180 So which is the smallest element in the right hand side? 44 00:04:10,580 --> 00:04:13,820 I think six is the smallest element. 45 00:04:14,240 --> 00:04:16,660 Now compare six with five. 46 00:04:17,390 --> 00:04:19,750 So five is smaller than six do nothing. 47 00:04:20,390 --> 00:04:21,800 So do nothing. 48 00:04:23,150 --> 00:04:24,710 Keep that as it is. 49 00:04:26,040 --> 00:04:27,710 So my area will remain the same. 50 00:04:28,870 --> 00:04:29,260 Why? 51 00:04:29,320 --> 00:04:31,480 Because five is less than six. 52 00:04:32,870 --> 00:04:38,160 So three, five, seven, six and eight. 53 00:04:39,490 --> 00:04:47,000 Now my point, I will reach here because it is moving in this direction now, find the smallest element 54 00:04:47,000 --> 00:04:47,930 in the right hand side. 55 00:04:50,690 --> 00:04:57,500 So I think six is the smallest element now compare six with seven, so six is less than seven. 56 00:04:57,500 --> 00:05:00,620 Do swapping, do swapping. 57 00:05:02,810 --> 00:05:04,640 So my area will look like this. 58 00:05:08,430 --> 00:05:09,900 Three, five. 59 00:05:12,250 --> 00:05:21,510 It and here I am having sex and here I am having seven, OK, now this pointer will move ahead. 60 00:05:21,930 --> 00:05:24,570 Now at this point I will reach at seven. 61 00:05:24,750 --> 00:05:27,420 So find the smallest element in the right hand side. 62 00:05:28,380 --> 00:05:33,200 So it is the smallest element in the right hand side compared with seven. 63 00:05:33,690 --> 00:05:35,960 So seven is the smallest element. 64 00:05:36,440 --> 00:05:38,310 So seven, is this more or less relevant. 65 00:05:38,440 --> 00:05:39,360 So do nothing. 66 00:05:39,750 --> 00:05:41,300 No, nothing. 67 00:05:42,480 --> 00:05:43,810 There's no need to do anything. 68 00:05:44,430 --> 00:05:45,780 So now it is. 69 00:05:48,930 --> 00:05:58,160 So this is my area three, five, six, seven and eight, and my pointer will reach here. 70 00:05:59,130 --> 00:06:00,390 OK, so this pointer. 71 00:06:01,620 --> 00:06:04,770 Will reach here, this apron that is moving in this direction. 72 00:06:05,170 --> 00:06:09,540 Now I will reach here now find the smallest element in the right hand side. 73 00:06:10,050 --> 00:06:16,370 So right inside doesn't exist right inside and doesn't exist. 74 00:06:16,380 --> 00:06:18,450 And this is my final answer. 75 00:06:19,080 --> 00:06:20,850 So this is my final. 76 00:06:22,120 --> 00:06:30,970 Answer and you can see yourself, this ad is started, this ad started in ascending order. 77 00:06:33,910 --> 00:06:39,880 OK, so this is how Selection's art works, my area gets sorted. 78 00:06:40,240 --> 00:06:44,950 Let us take one more example, OK, to make things clear. 79 00:06:46,400 --> 00:06:47,000 So. 80 00:06:49,430 --> 00:06:50,720 Let's say my Ed is. 81 00:06:53,010 --> 00:06:59,830 Four, five, three, one and two, so these are added elements. 82 00:07:00,360 --> 00:07:07,020 So what selections are twenty one point out here now find the smallest element in the right hand side, 83 00:07:07,410 --> 00:07:08,880 so which is the smallest element? 84 00:07:09,330 --> 00:07:15,780 So one is the smallest element compared forward when one is smaller, do sweeping. 85 00:07:16,140 --> 00:07:21,110 So one will come here for will come here list all will remain the same. 86 00:07:21,120 --> 00:07:23,250 So five, three and two. 87 00:07:24,060 --> 00:07:28,180 OK, now what might this pointer welcome here. 88 00:07:29,280 --> 00:07:32,340 Find the smallest element in the right hand side. 89 00:07:32,760 --> 00:07:34,160 So which is the smallest element. 90 00:07:34,860 --> 00:07:38,280 So I think two is the smallest element. 91 00:07:38,550 --> 00:07:40,640 So compared to with five. 92 00:07:40,800 --> 00:07:44,180 Yes, two is smaller, so do swapping. 93 00:07:44,910 --> 00:07:46,250 So we have to do something. 94 00:07:46,260 --> 00:07:51,920 So two will come here and five will come here, arrest all the elements will remain same. 95 00:07:51,930 --> 00:07:58,530 So one, three and four and this pointer will reach here. 96 00:07:59,700 --> 00:08:07,620 Let's call it a day, so I and I now find the smallest element in the right hand side, so I think the 97 00:08:07,620 --> 00:08:11,040 smallest element is for now compare four and three. 98 00:08:11,610 --> 00:08:13,170 So four is greater. 99 00:08:13,290 --> 00:08:13,950 Do nothing. 100 00:08:14,430 --> 00:08:15,680 So do nothing. 101 00:08:18,030 --> 00:08:23,580 There will be no change in the area, so one, two, three, four and five. 102 00:08:24,830 --> 00:08:27,020 Now, my point, I will reach here. 103 00:08:28,440 --> 00:08:36,809 OK, find the smallest element in the right hand side, which is five compar five with four since five 104 00:08:36,809 --> 00:08:39,870 is greater than four, don't do anything. 105 00:08:39,870 --> 00:08:40,860 So do nothing. 106 00:08:43,280 --> 00:08:51,530 And my age, one, two, three, four and five, now, what will happen this point will reach here. 107 00:08:52,760 --> 00:08:56,240 And my right hand side doesn't exist, so I stop. 108 00:08:57,130 --> 00:08:57,700 Stup. 109 00:09:00,450 --> 00:09:07,070 OK, so this is my final answer, and you can see our ETA is sorted. 110 00:09:09,130 --> 00:09:13,240 OK, so this is so this is the thing that we have to do. 111 00:09:14,940 --> 00:09:15,390 OK. 112 00:09:17,750 --> 00:09:19,730 So let's see how we can do this. 113 00:09:25,350 --> 00:09:30,120 So first, let us out cold, so first of all, I need a variable. 114 00:09:32,410 --> 00:09:39,430 So first of all, I need one loop which loop this loop, this is starting from zero and it is moving 115 00:09:39,430 --> 00:09:40,500 in this direction. 116 00:09:40,960 --> 00:09:44,640 So I need outlook for I equals zero. 117 00:09:44,650 --> 00:09:53,690 I will start from zero and I will go still less than or equal to and minus two and I plus plus. 118 00:09:54,100 --> 00:09:57,710 So this is and minus two and minus two. 119 00:09:59,350 --> 00:10:02,970 OK then I will be coming close to end minus one. 120 00:10:02,980 --> 00:10:04,600 That is when I will reach here. 121 00:10:04,900 --> 00:10:06,850 My right hand side doesn't exist. 122 00:10:07,270 --> 00:10:09,820 OK, so I am going to hold this position. 123 00:10:10,090 --> 00:10:11,440 So is this thing clear. 124 00:10:12,190 --> 00:10:14,410 I will go to this position. 125 00:10:14,770 --> 00:10:18,250 If I will come at this position, my right hand side will not exist. 126 00:10:18,550 --> 00:10:19,720 So there is no need. 127 00:10:20,050 --> 00:10:22,330 So I will hotel and minus two. 128 00:10:23,360 --> 00:10:29,720 OK, so inside this loop, what I have to do, I have to find the smallest element in the right hand 129 00:10:29,720 --> 00:10:31,280 side, OK? 130 00:10:31,760 --> 00:10:34,910 So for finding the smallest element, we need a loop. 131 00:10:34,940 --> 00:10:37,990 Remember, we have solved the question how to find the smallest element. 132 00:10:38,570 --> 00:10:39,740 So we need a loop. 133 00:10:40,130 --> 00:10:42,420 So this look will start from a plus one. 134 00:10:43,220 --> 00:10:47,370 So this loop will start from let's take a variable J. 135 00:10:47,480 --> 00:10:55,490 So this will start from a place one Y plus one, because if I is here, I have to search on the right 136 00:10:55,490 --> 00:10:56,120 hand side. 137 00:10:56,150 --> 00:10:58,730 So I will start from IHI plus one. 138 00:11:00,470 --> 00:11:09,350 So starting from my lesson, we have to check the old lost position so g less than or equal to and minus 139 00:11:09,350 --> 00:11:18,590 one, we have to go to last position G plus plus what we will do, we will find the smallest element. 140 00:11:18,590 --> 00:11:23,720 We will write code for finding the smallest element and then this loop will finish. 141 00:11:23,720 --> 00:11:29,990 When this loop will terminate, what we will have, we will have the smallest element in the right hand 142 00:11:29,990 --> 00:11:30,380 side. 143 00:11:31,710 --> 00:11:35,660 OK, so we will be having the smallest element in the right hand side. 144 00:11:36,260 --> 00:11:43,890 Now I will compare if the smallest element on the right hand side is less than my current element. 145 00:11:44,330 --> 00:11:46,310 So what I will do, I will slap. 146 00:11:48,160 --> 00:11:56,830 I will swab I will swab the smallest element, and I otherwise I will do nothing. 147 00:11:57,940 --> 00:12:02,050 OK, so you can see yourself, for example, in this case. 148 00:12:03,220 --> 00:12:07,810 This was I and the smallest element was this one. 149 00:12:08,300 --> 00:12:13,830 OK, so this was our smallest element and this was our current element. 150 00:12:14,230 --> 00:12:21,910 So here I am checking if the smallest element that is if one if one is less than the current element, 151 00:12:22,150 --> 00:12:24,590 that is four, then do something. 152 00:12:25,000 --> 00:12:29,530 So when will come here and four will come here otherwise and do nothing. 153 00:12:30,430 --> 00:12:32,610 So this is how it works. 154 00:12:34,220 --> 00:12:36,860 OK, now let's write the code. 155 00:12:46,030 --> 00:12:49,060 So let's name this file as selection's art. 156 00:12:53,940 --> 00:12:55,110 Not CBP. 157 00:13:14,230 --> 00:13:15,620 OK, so now what do we do? 158 00:13:15,640 --> 00:13:17,910 First of all, we will take that as input. 159 00:13:18,520 --> 00:13:26,560 So give me the number of elements in the area and now I will take input so far and I was zero. 160 00:13:26,830 --> 00:13:29,560 I last and I placeless. 161 00:13:32,130 --> 00:13:41,700 What I will do, I will take input Potosí in if I OK, so first of all, let us make Eddie so the size 162 00:13:41,700 --> 00:13:47,700 of the ads and so I am making an area of size and then I am taking input. 163 00:13:48,150 --> 00:13:51,290 So in the last class we learn functions. 164 00:13:51,630 --> 00:13:54,410 So what we will do, we will make function. 165 00:13:55,380 --> 00:13:58,410 So let's say the name of the function is selecting the site. 166 00:13:59,370 --> 00:14:00,360 So selection. 167 00:14:02,440 --> 00:14:05,140 Selections art is the name of the function. 168 00:14:05,770 --> 00:14:14,230 OK, so what it will take as input, it will take an editor's input and also it will take the size of 169 00:14:14,230 --> 00:14:14,760 the editor. 170 00:14:15,820 --> 00:14:21,880 So what with the return of the selections, so that time will be void because this function will not 171 00:14:21,880 --> 00:14:22,680 return anything. 172 00:14:22,720 --> 00:14:24,250 It will start the editing. 173 00:14:24,700 --> 00:14:29,350 OK, and from here we will call selection art selection. 174 00:14:31,900 --> 00:14:36,280 And it will take Eddie and the size of the ad as input. 175 00:14:40,400 --> 00:14:46,670 OK, so we know they are biased by reference, so in the last class we have seen that it is our passed 176 00:14:46,670 --> 00:14:47,270 by reference. 177 00:14:47,570 --> 00:14:53,150 So if I will do some changes here, that changes will be reflected here, OK? 178 00:14:54,110 --> 00:14:59,810 Now, after doing selections or letters, write the code for printing that, so forth. 179 00:14:59,810 --> 00:15:03,290 And I equals and I equals zero. 180 00:15:04,010 --> 00:15:12,890 I list and I, I listin and I see out aof I. 181 00:15:16,290 --> 00:15:20,170 OK, so that thing that we have to do is we have to implement this function. 182 00:15:20,730 --> 00:15:23,340 We have to complete this function selection. 183 00:15:24,510 --> 00:15:30,020 So what we have decided, first of all, I need a variable I that will start from zero. 184 00:15:30,570 --> 00:15:31,590 So you can see here. 185 00:15:34,050 --> 00:15:39,030 We need a variable, I will to start from zero and it will go to and minus two. 186 00:15:39,460 --> 00:15:42,870 OK, so starting from zero so far. 187 00:15:45,320 --> 00:15:47,360 And I equals zero. 188 00:15:48,710 --> 00:15:52,980 I will go to Bill and minus two second last position. 189 00:15:53,660 --> 00:15:55,270 OK, I placeless. 190 00:15:56,990 --> 00:16:01,210 Now what we have to do, we have to find the smallest element in the right hand side. 191 00:16:02,000 --> 00:16:05,630 OK, so we already know how to find smallest element. 192 00:16:05,990 --> 00:16:14,180 What we used to do is we take a variable small smallest, which is initially intermix, which is initially 193 00:16:14,190 --> 00:16:19,670 intermix, and now we have to find the smallest element in the right hand side. 194 00:16:21,110 --> 00:16:25,940 So I will start my loop from IHI plus one. 195 00:16:26,480 --> 00:16:31,730 OK, so I am starting from my plus one because I have to find the smallest element in the right hand 196 00:16:31,760 --> 00:16:32,600 side of a. 197 00:16:34,550 --> 00:16:42,080 So you can see here from I went to Bill last position again, this, too, is the last position. 198 00:16:44,030 --> 00:16:51,910 So, Jay, less than or equal to and minus one and minus one is the last position in the Eddie Jay Placeless 199 00:16:53,120 --> 00:16:55,160 and now how to find smallest element. 200 00:16:56,000 --> 00:16:59,870 We already know we will compare the current settlement with the smallest element. 201 00:17:00,170 --> 00:17:04,359 If this current element is less than my smallest element. 202 00:17:04,369 --> 00:17:12,290 What we used to do was we was updating, we were updating our smallest value to the smallest equals 203 00:17:12,800 --> 00:17:13,119 G. 204 00:17:16,130 --> 00:17:24,530 Now, when I reach line number 15, when this loop will finish, when I reach line number 15, I know 205 00:17:24,530 --> 00:17:25,579 the smallest value. 206 00:17:27,500 --> 00:17:31,800 OK, so what I will do now, I will compare. 207 00:17:31,910 --> 00:17:42,860 So if my current value, which is if I so if my current value is greater than the smallest value, then 208 00:17:43,850 --> 00:17:46,300 what we have to do, we will have to swap. 209 00:17:46,790 --> 00:17:53,360 So swap of a and smallest. 210 00:17:56,680 --> 00:17:58,860 So this is all that we have to do. 211 00:18:00,430 --> 00:18:06,310 So you can see here, if the smallest element is less than the current element and then we were swapping. 212 00:18:07,790 --> 00:18:14,570 OK, so this is the so this is our entire logic now let's see whether our logic is correct or not. 213 00:18:18,570 --> 00:18:26,690 So the number of elements out of five and values are seven, five, three, six and eight. 214 00:18:28,470 --> 00:18:30,180 So this is my output. 215 00:18:31,730 --> 00:18:35,420 And we all know our art for this coming out to be wrong. 216 00:18:36,390 --> 00:18:38,080 But why this coming out to be wrong? 217 00:18:38,130 --> 00:18:42,620 We have done everything that we have discussed, then why our output is wrong. 218 00:18:42,630 --> 00:18:43,320 So let's see. 219 00:18:44,080 --> 00:18:48,030 Let's try to understand why our code is giving wrong output. 220 00:18:48,270 --> 00:18:51,540 OK, so what we will do, we will write in our code. 221 00:18:52,780 --> 00:18:57,280 So we will take an example and we will try an our called. 222 00:18:59,030 --> 00:19:06,020 So the example that we took was our area was seven, five, three, six and eight. 223 00:19:06,380 --> 00:19:09,590 So this was our last election. 224 00:19:09,600 --> 00:19:11,500 I thought I equals zero. 225 00:19:11,540 --> 00:19:18,410 So my eye is at this point, I will go to the second last position. 226 00:19:18,410 --> 00:19:23,870 So I will go I will go from this position to this position. 227 00:19:25,390 --> 00:19:28,510 Correct, smallest equals endemics. 228 00:19:28,540 --> 00:19:29,980 So initially, my smallest. 229 00:19:30,910 --> 00:19:35,600 Initially, my smallest is and that is plus infinity. 230 00:19:35,640 --> 00:19:41,440 OK, so we have to find the smallest element of the right hand side so the value of G will start from 231 00:19:41,440 --> 00:19:42,110 a plus one. 232 00:19:43,270 --> 00:19:44,530 So the value of. 233 00:19:44,950 --> 00:19:45,950 So the value of J. 234 00:19:46,300 --> 00:19:47,500 We start from here. 235 00:19:47,590 --> 00:19:48,640 So this is my G. 236 00:19:50,330 --> 00:19:54,650 And they will go till last weekend, so they will go tell here. 237 00:19:58,010 --> 00:20:03,480 OK, so what I am doing, I'm comparing the current value f.j. with the smallest value. 238 00:20:04,130 --> 00:20:07,160 So we are comparing five with infinity. 239 00:20:07,550 --> 00:20:09,640 So obviously five is smaller. 240 00:20:09,950 --> 00:20:11,710 So I will update my small list. 241 00:20:12,230 --> 00:20:15,860 So now the smallest becomes five. 242 00:20:16,080 --> 00:20:19,640 OK, now go above Gabler's plus. 243 00:20:19,910 --> 00:20:21,260 OK, so Jay will come here. 244 00:20:22,900 --> 00:20:28,720 Now, again, compare the current value, that is three with five since three years smaller. 245 00:20:28,870 --> 00:20:30,560 I will update the value of smallest. 246 00:20:30,640 --> 00:20:32,050 So smallest becomes three. 247 00:20:33,150 --> 00:20:41,880 Now, plus plus so J will reach here, so compare the current value with the smallest value, OK, this 248 00:20:41,880 --> 00:20:43,950 condition is this condition is false. 249 00:20:44,280 --> 00:20:46,050 Do nothing now. 250 00:20:46,170 --> 00:20:47,340 J will be incremented. 251 00:20:47,340 --> 00:20:48,410 J will reach here. 252 00:20:49,800 --> 00:20:52,910 Compare the current value with the smallest value. 253 00:20:53,730 --> 00:20:56,010 So this condition is again false. 254 00:20:56,490 --> 00:20:57,720 J will reach here. 255 00:20:58,080 --> 00:20:59,820 J will become sequel's to end. 256 00:21:00,180 --> 00:21:01,230 And this loop. 257 00:21:01,890 --> 00:21:03,060 This loop will break. 258 00:21:03,630 --> 00:21:06,760 Or you should say terminate this loop terminated. 259 00:21:08,290 --> 00:21:10,950 OK, now I will reach at this line. 260 00:21:11,670 --> 00:21:15,120 So if, if I so if I was seven. 261 00:21:16,890 --> 00:21:20,540 So if Elfy is greater than smallest. 262 00:21:20,550 --> 00:21:21,730 So smallest is three. 263 00:21:22,350 --> 00:21:24,130 So seven is greater than three. 264 00:21:24,150 --> 00:21:24,540 Yes. 265 00:21:25,020 --> 00:21:26,700 I am accepting the values. 266 00:21:27,410 --> 00:21:31,710 OK, so three will come here and seven will come here. 267 00:21:32,720 --> 00:21:32,920 OK. 268 00:21:33,150 --> 00:21:42,370 So when you add it becomes three five three six eight and smallest is seven. 269 00:21:42,810 --> 00:21:44,340 Now this is the main problem. 270 00:21:45,210 --> 00:21:50,850 You can observe the seven, this is seven should be slapped with this three. 271 00:21:51,880 --> 00:21:58,600 OK, so instead this is swiping its value from the smallest value with the smallest value. 272 00:21:59,510 --> 00:22:02,940 OK, so I think you got the logic where we have the domestic. 273 00:22:03,950 --> 00:22:12,680 So the mistake is we are sweeping Alfy, we are stepping elfy with the smallest value, OK? 274 00:22:12,710 --> 00:22:18,020 And what we should have done, we have swept this value with this value. 275 00:22:19,220 --> 00:22:25,010 OK, so you can see here three appears, two times here should be seven. 276 00:22:26,560 --> 00:22:30,590 So how we can correct this mistake, so the logic is very simple. 277 00:22:30,610 --> 00:22:36,010 Instead of storing the value, so here I am storing the value three, what I will do instead of storing 278 00:22:36,010 --> 00:22:43,210 the value store, that index store index, for example, this is this is an index. 279 00:22:43,240 --> 00:22:44,540 So zero one and two. 280 00:22:45,070 --> 00:22:46,330 So this is second index. 281 00:22:46,600 --> 00:22:49,210 So instead of storing the value, stored the index. 282 00:22:50,260 --> 00:22:56,200 Stoate index, and finally, instead of slapping these two values, what I will do, I will strap HFA 283 00:22:56,860 --> 00:22:59,200 with a ofthe smallest. 284 00:23:02,160 --> 00:23:10,190 So my smallest variable will contain the smallest variable will store the index having smallest value, 285 00:23:10,440 --> 00:23:13,380 so index having smallest value. 286 00:23:17,740 --> 00:23:26,790 OK, so the index of three is two, and finally what I will do, I will set afire, that is seven with 287 00:23:26,800 --> 00:23:28,930 a small child molesters. 288 00:23:28,930 --> 00:23:29,300 Three. 289 00:23:29,650 --> 00:23:33,820 OK, so then these values will be swabbed, which is correct. 290 00:23:34,670 --> 00:23:37,060 OK, so what I am doing. 291 00:23:38,080 --> 00:23:40,090 So let us come this whole court. 292 00:23:43,340 --> 00:23:45,800 And now we will write the characterful. 293 00:23:47,080 --> 00:23:55,600 So there will be some minor changes, so I will start from zero, no doubt I will go till second last 294 00:23:55,600 --> 00:24:04,780 position, so and minus two I plus plus so I am creating a variable smallest. 295 00:24:05,260 --> 00:24:11,700 So this smallest variable will contain the index of the smallest value. 296 00:24:11,980 --> 00:24:16,180 So let's say the smallest value is present at index eye. 297 00:24:17,250 --> 00:24:24,340 OK, so I am saying where I am standing, this is the smallest value, so smallest is containing the 298 00:24:24,340 --> 00:24:24,880 index. 299 00:24:26,420 --> 00:24:36,130 Now I have to find the smallest value in the right hand side, so four and J equals eight plus one, 300 00:24:36,140 --> 00:24:41,630 we will start from eight plus one and G will go to last position. 301 00:24:41,630 --> 00:24:46,210 So N minus one is the last position and G plus plus. 302 00:24:48,770 --> 00:24:50,060 So I will compare. 303 00:24:50,330 --> 00:25:03,860 If the current value, if the current value is less than my smallest value, then what I will do then 304 00:25:03,860 --> 00:25:10,790 smallest will store the index of the smallest value which is Gaono. 305 00:25:10,850 --> 00:25:17,450 OK, so initially I was saying that where I am standing this is the smallest value, so smallest is 306 00:25:17,450 --> 00:25:18,750 containing the index. 307 00:25:19,370 --> 00:25:21,500 OK, so now I am comparing. 308 00:25:21,980 --> 00:25:27,240 So your smallest, smallest will give me that value and I, I'm comparing. 309 00:25:27,620 --> 00:25:32,630 So if F.J. is less than the smallest then I will update the value of smallest. 310 00:25:33,110 --> 00:25:38,060 So you can again see here the smallest variable is storing the index. 311 00:25:39,570 --> 00:25:41,500 And then this loop is terminated. 312 00:25:42,150 --> 00:25:45,070 So when this loop will break, what will I have? 313 00:25:45,090 --> 00:25:48,250 I will have the index of the smallest value. 314 00:25:48,840 --> 00:25:52,840 So I just have to swipe it off. 315 00:25:53,220 --> 00:25:59,910 That is current value with the smallest value that I have found out in the right hand side. 316 00:26:02,220 --> 00:26:04,140 Now, this code is correct. 317 00:26:05,290 --> 00:26:07,650 OK, so let's run our program. 318 00:26:10,720 --> 00:26:18,940 So there are five elements and the elements are seven, five, three, six and eight, so output is 319 00:26:19,780 --> 00:26:20,280 correct. 320 00:26:21,190 --> 00:26:23,950 So you can see my output is correct. 321 00:26:24,910 --> 00:26:26,650 My editors and getting started. 322 00:26:27,940 --> 00:26:36,010 One more time, so no influence out of five and diluent to add one, two, five, four and three. 323 00:26:37,150 --> 00:26:41,650 So my output is one, two, three, four, five last time. 324 00:26:43,150 --> 00:26:49,120 So the number of elements are four and the elements are four, three, two and one, some are today's 325 00:26:49,120 --> 00:26:50,520 one, two, three and four. 326 00:26:50,530 --> 00:26:51,870 So it is getting started. 327 00:26:53,250 --> 00:26:59,610 OK, so that astronaut program, let us bring our goal to get how it is working. 328 00:27:00,690 --> 00:27:02,320 So let us take a small example. 329 00:27:02,460 --> 00:27:10,280 So suppose my array's three, two, one and four. 330 00:27:10,560 --> 00:27:11,580 So this is my area. 331 00:27:12,840 --> 00:27:14,340 I am taking small example. 332 00:27:16,410 --> 00:27:19,110 I equals zero, so I is here. 333 00:27:20,760 --> 00:27:25,950 Now, I will go tell her I will vary from this to this. 334 00:27:27,290 --> 00:27:27,760 Correct. 335 00:27:30,170 --> 00:27:35,960 So this is zero, this is one, this is two and the history, so these are indexes, OK, so smallest. 336 00:27:35,960 --> 00:27:37,880 Accorsi so smallest. 337 00:27:39,160 --> 00:27:40,570 Equals zero. 338 00:27:40,600 --> 00:27:43,490 OK, so J will start from a plus one. 339 00:27:43,510 --> 00:27:45,140 So here is G. 340 00:27:46,270 --> 00:27:46,690 OK. 341 00:27:46,720 --> 00:27:57,100 Now compare F.J. compared to so f.j. means aof G equals two with a smallest so aof smallest that is 342 00:27:57,250 --> 00:27:59,270 of zero equals three. 343 00:27:59,590 --> 00:28:01,690 So I am comparing two with three. 344 00:28:02,560 --> 00:28:04,660 OK, so compared to with three. 345 00:28:04,930 --> 00:28:07,300 So two is a smaller smaller. 346 00:28:07,310 --> 00:28:08,770 I will update smallest. 347 00:28:09,220 --> 00:28:13,180 So smallest now is one. 348 00:28:13,510 --> 00:28:15,580 OK, so it's more or less this one now. 349 00:28:17,480 --> 00:28:19,610 Incrementally, so they will come here. 350 00:28:21,280 --> 00:28:30,460 Now I have to compare the value of one with AOF smallest, so smallest is to compare one with the smallest 351 00:28:30,460 --> 00:28:35,140 will get updated, so smallest is now indexed three. 352 00:28:35,890 --> 00:28:37,750 OK, they will come here. 353 00:28:39,020 --> 00:28:43,880 Compare AFGE with aof smallest, so aof three. 354 00:28:45,280 --> 00:28:52,900 OK, so it should be two, it will be two, so compare AOF with each of the smallest of two. 355 00:28:53,130 --> 00:28:57,220 So afterwards when you compare one with four, do nothing. 356 00:28:57,990 --> 00:29:05,020 Now this will terminate because while this rule will terminate because Jaquiss and so G will come here, 357 00:29:05,500 --> 00:29:06,430 they become cell. 358 00:29:06,490 --> 00:29:07,710 So this law will terminate. 359 00:29:07,960 --> 00:29:11,110 I will reject line number 31 Sep AOF. 360 00:29:11,860 --> 00:29:13,450 So if I was three. 361 00:29:14,800 --> 00:29:25,020 If I was three with a smallest, smallest is two and afterwards one, so ASVAB three and one, OK, 362 00:29:25,120 --> 00:29:29,320 so new and it will be one, two, three and four. 363 00:29:31,460 --> 00:29:39,500 So this is my new editor now, I will come here, I placeless, I will come here and again we will repeat 364 00:29:39,500 --> 00:29:41,870 all the operations, all the instructions. 365 00:29:42,200 --> 00:29:43,730 Solidarité will get sorted. 366 00:29:45,090 --> 00:29:53,380 OK, so the main thing that I want to tell you is we will store the index, we will not store the value. 367 00:29:53,400 --> 00:29:58,700 So here you can see it's more or less because, A.J., we will not store the value. 368 00:29:58,710 --> 00:30:01,020 We will even we will store the index. 369 00:30:02,190 --> 00:30:03,720 OK, so if I have the next. 370 00:30:04,740 --> 00:30:07,770 I can write Elsmore list to get the value. 371 00:30:09,550 --> 00:30:11,530 So I think this algorithm is clear to you now. 372 00:30:12,320 --> 00:30:14,060 OK, so what do you have to do? 373 00:30:14,200 --> 00:30:15,620 So this is most OK. 374 00:30:15,850 --> 00:30:21,630 So what you have to do, you have to write this code on your own and you have to bring this code. 375 00:30:22,210 --> 00:30:23,970 OK, please, please, please. 376 00:30:24,340 --> 00:30:25,330 This is my request. 377 00:30:25,630 --> 00:30:28,330 Take my paper and Barondess code first. 378 00:30:28,330 --> 00:30:32,200 Try to understand why this logic was why this logic was wrong. 379 00:30:33,210 --> 00:30:38,260 And then try to understand when I am studying the indexes, how this code is working. 380 00:30:39,050 --> 00:30:43,860 OK, so if you have any doubt regarding the selections or deliver them, feel free to ask. 381 00:30:45,060 --> 00:30:45,670 OK, guys. 382 00:30:45,750 --> 00:30:47,070 So this is it for this video. 383 00:30:47,640 --> 00:30:48,210 Thank you.