1
00:00:01,270 --> 00:00:02,800
Hey, guys, what's up?

2
00:00:03,280 --> 00:00:06,040
So our today's topic is starting.

3
00:00:07,030 --> 00:00:08,620
So we're just not meaning or starting.

4
00:00:09,100 --> 00:00:11,050
So, for example, my Eddys.

5
00:00:12,950 --> 00:00:19,340
Let's say it is seven, five, three, six and eight.

6
00:00:20,000 --> 00:00:21,730
So, for example, this is my Eddie.

7
00:00:22,430 --> 00:00:25,160
Now, after sorting this, Eddie will become.

8
00:00:28,010 --> 00:00:32,600
Three, five, six, seven and eight.

9
00:00:33,290 --> 00:00:34,790
Okay, so this is starting.

10
00:00:36,260 --> 00:00:41,570
So this is my unsorted Eddie and this is my sorted Eddie.

11
00:00:43,340 --> 00:00:47,960
OK, so sorting means these elements.

12
00:00:48,330 --> 00:00:51,880
So I have sorted my data.

13
00:00:54,390 --> 00:01:00,210
So the details sorted in ascending order, the elements are in ascending order.

14
00:01:01,650 --> 00:01:08,460
We can also sort that data in descending order, for example, eight, then seven, then six, then

15
00:01:08,460 --> 00:01:09,560
five and three.

16
00:01:09,930 --> 00:01:11,810
So this data is also sorted.

17
00:01:12,540 --> 00:01:15,960
But this data is sorted in descending order.

18
00:01:17,550 --> 00:01:19,920
OK, so the elements are in descending order.

19
00:01:20,760 --> 00:01:22,640
So generally when we say sorting.

20
00:01:23,430 --> 00:01:27,360
So when we say starting, we generally means that increasing order.

21
00:01:27,780 --> 00:01:28,010
OK.

22
00:01:28,320 --> 00:01:31,080
So we generally mean that sorting means increasing order.

23
00:01:31,140 --> 00:01:32,760
So DeLeon's in increasing order.

24
00:01:33,240 --> 00:01:34,480
So this is General.

25
00:01:34,710 --> 00:01:34,990
OK.

26
00:01:35,580 --> 00:01:40,470
So when we say SA Dairy, that means saw that in increasing order.

27
00:01:42,220 --> 00:01:44,340
OK, so why do we need sorting?

28
00:01:44,850 --> 00:01:50,580
We need sorting to make our search searching process faster.

29
00:01:51,750 --> 00:01:55,890
So if I have sorted data, I can search much, much faster.

30
00:01:56,760 --> 00:01:59,100
So this is the main purpose of sorting.

31
00:01:59,760 --> 00:02:02,910
Now, there are many algorithms used for sorting.

32
00:02:03,510 --> 00:02:06,960
So we have many sorting algorithms.

33
00:02:08,490 --> 00:02:14,970
So some of them are listed here, for example, Selection's art bubbles, art insertion, counting Bucket

34
00:02:14,970 --> 00:02:16,420
Reddick's and marriage quick.

35
00:02:16,830 --> 00:02:18,360
And there are many more.

36
00:02:19,100 --> 00:02:19,300
OK.

37
00:02:19,920 --> 00:02:25,540
So there are many sorting algorithms that Lusardi Eddie.

38
00:02:26,700 --> 00:02:31,080
So in this we do we will talk about selection, Saad.

39
00:02:32,520 --> 00:02:38,570
OK, so let us try to understand how this election site works and how it will SORDI data.

40
00:02:41,820 --> 00:02:45,120
So selection sort.

41
00:02:47,440 --> 00:02:49,780
So I suppose let us take an example.

42
00:02:50,260 --> 00:02:52,670
So suppose this is my area.

43
00:02:56,180 --> 00:03:01,730
So the elements are, let's say a seven five, three, six ended above example.

44
00:03:01,880 --> 00:03:02,160
OK.

45
00:03:03,200 --> 00:03:06,980
Now word selection is will say take one point ahead.

46
00:03:07,360 --> 00:03:08,680
Let's say named I.

47
00:03:09,920 --> 00:03:10,830
So what it will say.

48
00:03:10,980 --> 00:03:13,280
Find the smallest element in the right hand side.

49
00:03:14,030 --> 00:03:16,680
So which is the smallest element in the right hand side, I think.

50
00:03:16,700 --> 00:03:20,470
Three is the smallest element compared to eBid seven.

51
00:03:21,480 --> 00:03:21,680
OK.

52
00:03:21,910 --> 00:03:23,550
So compared to David seven.

53
00:03:23,950 --> 00:03:24,970
Which one is smaller?

54
00:03:25,060 --> 00:03:26,860
Three is smaller than slap.

55
00:03:28,800 --> 00:03:29,280
Since.

56
00:03:29,350 --> 00:03:29,630
Trees.

57
00:03:29,760 --> 00:03:30,210
Smaller.

58
00:03:30,310 --> 00:03:30,990
What I will do?

59
00:03:31,560 --> 00:03:32,420
I will swap.

60
00:03:33,120 --> 00:03:34,630
So three will come here.

61
00:03:35,100 --> 00:03:36,600
And seven will come here.

62
00:03:37,390 --> 00:03:37,700
Rest.

63
00:03:37,710 --> 00:03:38,710
All the elements will sit.

64
00:03:38,820 --> 00:03:39,450
Will be same.

65
00:03:39,480 --> 00:03:41,910
Five, six and eight.

66
00:03:47,920 --> 00:03:48,130
OK.

67
00:03:48,230 --> 00:03:52,720
So since three is smaller than seven, I will do swapping.

68
00:03:52,910 --> 00:03:55,330
So here, slapping take place.

69
00:03:57,980 --> 00:04:03,430
Now, what will happen this point that I will move ahead now I will point to five.

70
00:04:04,040 --> 00:04:07,320
So we have to find the smallest element in that right hand side.

71
00:04:08,020 --> 00:04:10,190
So which is the smallest element in the right hand side?

72
00:04:10,700 --> 00:04:13,820
I think six is the smallest element.

73
00:04:14,330 --> 00:04:16,640
Now compare six with five.

74
00:04:17,450 --> 00:04:19,730
So five is smaller than six do nothing.

75
00:04:20,450 --> 00:04:22,170
So do the thing.

76
00:04:23,210 --> 00:04:24,710
Keep Daddy as it is.

77
00:04:26,120 --> 00:04:27,710
So my area will remain same.

78
00:04:28,960 --> 00:04:29,230
Why?

79
00:04:29,320 --> 00:04:31,480
Because five is less than six.

80
00:04:32,930 --> 00:04:38,180
So three, five, seven, six and eight.

81
00:04:39,600 --> 00:04:45,080
No, my pointer will reach here because it is moving in this direction.

82
00:04:45,530 --> 00:04:47,930
Now find the smallest element in the right hand side.

83
00:04:50,750 --> 00:04:53,210
So I think six is the smallest element.

84
00:04:53,270 --> 00:04:55,430
Now compare six with seven.

85
00:04:55,820 --> 00:04:57,440
So six is less than seven.

86
00:04:57,530 --> 00:04:58,280
Do swapping.

87
00:04:59,270 --> 00:05:00,620
Do swapping.

88
00:05:02,870 --> 00:05:04,640
So my edit will look like this.

89
00:05:08,490 --> 00:05:09,900
Three, five.

90
00:05:12,360 --> 00:05:15,380
It and here I am having sex.

91
00:05:15,900 --> 00:05:17,490
And here I am having seven.

92
00:05:18,130 --> 00:05:18,450
OK.

93
00:05:19,110 --> 00:05:21,480
Now this pointer will move ahead.

94
00:05:21,990 --> 00:05:24,570
Now this point I will reach at seven.

95
00:05:24,840 --> 00:05:27,390
So find the smallest element in the right hand side.

96
00:05:28,440 --> 00:05:31,230
So it is the smallest element in the right hand side.

97
00:05:31,520 --> 00:05:33,210
Compare it with seven.

98
00:05:33,750 --> 00:05:35,940
So seven is the smallest element.

99
00:05:36,480 --> 00:05:38,310
So seven is the smallest element.

100
00:05:38,520 --> 00:05:39,330
So do nothing.

101
00:05:39,780 --> 00:05:41,310
Do nothing.

102
00:05:42,540 --> 00:05:43,810
There is no need to do anything.

103
00:05:44,400 --> 00:05:44,960
So no.

104
00:05:45,200 --> 00:05:45,780
It is.

105
00:05:48,990 --> 00:05:58,140
So this is Mary, three, five, six, seven and eight, and my pointer will reach here.

106
00:05:59,290 --> 00:06:00,390
OK, so this winter.

107
00:06:01,710 --> 00:06:02,520
We'll reach here.

108
00:06:02,700 --> 00:06:04,770
This, I point out, is moving in this direction.

109
00:06:05,190 --> 00:06:09,540
Now I will reach hit now, find the smallest element in the right hand side.

110
00:06:10,110 --> 00:06:16,350
So right hand side doesn't exist right inside and doesn't exist.

111
00:06:16,470 --> 00:06:18,420
And this is my final answer.

112
00:06:19,140 --> 00:06:20,850
So this is my final.

113
00:06:22,170 --> 00:06:22,580
Answer.

114
00:06:23,380 --> 00:06:24,730
And you can see yourself.

115
00:06:24,910 --> 00:06:26,830
This ad is started.

116
00:06:28,090 --> 00:06:30,940
This ad is altered in ascending order.

117
00:06:34,060 --> 00:06:37,570
OK, so this is how Selection's art works.

118
00:06:38,380 --> 00:06:39,880
My area gets sorted.

119
00:06:40,350 --> 00:06:41,920
Let's take one more example.

120
00:06:42,650 --> 00:06:43,000
OK.

121
00:06:43,990 --> 00:06:44,940
To make things clear.

122
00:06:46,460 --> 00:06:47,030
So.

123
00:06:49,520 --> 00:06:50,750
Let's say my error is.

124
00:06:53,070 --> 00:06:57,460
Four, five, three, one and two.

125
00:06:57,960 --> 00:06:59,850
So these are my added elements.

126
00:07:00,420 --> 00:07:01,920
So what's selection side will see.

127
00:07:02,270 --> 00:07:03,460
But one point out here.

128
00:07:04,340 --> 00:07:07,020
Now find the smallest element in the right hand side.

129
00:07:07,470 --> 00:07:08,850
So which is the smallest element?

130
00:07:09,390 --> 00:07:14,640
So one is the smallest element compared forward when one is smaller.

131
00:07:14,730 --> 00:07:15,720
Do swapping.

132
00:07:16,200 --> 00:07:18,780
So one will come here for will come here.

133
00:07:19,110 --> 00:07:21,090
Rest all will remain same.

134
00:07:21,120 --> 00:07:23,190
So five, three and two.

135
00:07:24,160 --> 00:07:24,420
OK.

136
00:07:25,020 --> 00:07:32,330
Now my this pointer will come here, find the smallest element in the right hand side.

137
00:07:32,770 --> 00:07:34,140
So which is the smallest element.

138
00:07:34,890 --> 00:07:38,250
So I think two is the smallest element.

139
00:07:38,640 --> 00:07:40,650
So compared to with five.

140
00:07:40,920 --> 00:07:41,340
Yes.

141
00:07:41,430 --> 00:07:42,510
Two is smaller.

142
00:07:42,840 --> 00:07:44,130
So do swapping.

143
00:07:44,970 --> 00:07:51,050
So we have to do some things or two will come here and five will come here, arrest all the elements

144
00:07:51,060 --> 00:07:51,900
will remain same.

145
00:07:51,930 --> 00:07:58,500
So when three and four and this pointer will reach here.

146
00:07:59,790 --> 00:08:00,720
Let's call it a day.

147
00:08:01,380 --> 00:08:06,120
So I and I now find the smallest element in the right hand side.

148
00:08:07,050 --> 00:08:09,010
So I think the smallest element is four.

149
00:08:09,300 --> 00:08:11,120
Now compare four and three.

150
00:08:11,670 --> 00:08:13,170
So four is greater.

151
00:08:13,320 --> 00:08:13,950
Do nothing.

152
00:08:14,490 --> 00:08:15,660
So do nothing.

153
00:08:18,110 --> 00:08:19,710
There will be no change in the area.

154
00:08:19,800 --> 00:08:23,550
So one, two, three, four and five.

155
00:08:24,920 --> 00:08:26,990
Now, my point, I will reach here.

156
00:08:28,570 --> 00:08:28,840
OK.

157
00:08:28,920 --> 00:08:36,810
Find the smallest element in the right hand side, which is five compared five with four since five

158
00:08:36,810 --> 00:08:37,270
is good.

159
00:08:37,500 --> 00:08:37,880
Four.

160
00:08:38,640 --> 00:08:39,750
Don't do anything.

161
00:08:39,960 --> 00:08:40,860
So do nothing.

162
00:08:43,400 --> 00:08:48,020
And my ad is one, two, three, four and five.

163
00:08:48,620 --> 00:08:49,460
Now, what will happen?

164
00:08:49,700 --> 00:08:51,530
This pointer will reach Paire.

165
00:08:52,880 --> 00:08:55,340
And my right hand side doesn't exist.

166
00:08:55,550 --> 00:08:57,680
So stop, stop.

167
00:09:00,410 --> 00:09:00,620
OK.

168
00:09:00,900 --> 00:09:02,970
So this is my final answer.

169
00:09:03,390 --> 00:09:07,080
And you can see our error is sorted.

170
00:09:09,220 --> 00:09:09,460
OK.

171
00:09:09,640 --> 00:09:10,360
So this is.

172
00:09:11,050 --> 00:09:13,270
So this is the thing that we have to do.

173
00:09:15,080 --> 00:09:15,370
OK.

174
00:09:17,810 --> 00:09:19,760
So let's see how we can do this.

175
00:09:25,410 --> 00:09:27,270
So first lady's side called.

176
00:09:27,750 --> 00:09:30,150
So first of all, I need a variable.

177
00:09:32,500 --> 00:09:36,070
So first of all, I need one loop which loop this loop.

178
00:09:36,670 --> 00:09:40,480
This eye is starting from zero and it is moving in this direction.

179
00:09:41,020 --> 00:09:44,600
So I need our outer loop for I equals zero.

180
00:09:44,650 --> 00:09:53,710
I will start from zero and I will go then less than or equal to and minus two and a plus plus.

181
00:09:54,190 --> 00:09:54,750
So this is.

182
00:09:54,840 --> 00:09:55,570
And minus two.

183
00:09:56,740 --> 00:09:57,730
And minus two.

184
00:09:59,210 --> 00:09:59,490
OK.

185
00:10:00,170 --> 00:10:02,960
Then I will become equals to end minus one.

186
00:10:02,980 --> 00:10:04,600
That is when I will reach here.

187
00:10:04,990 --> 00:10:06,850
My right hand side doesn't exist.

188
00:10:07,390 --> 00:10:07,690
OK.

189
00:10:07,960 --> 00:10:09,770
So I am going this way Ed..

190
00:10:10,150 --> 00:10:11,440
So is this thing clear.

191
00:10:12,310 --> 00:10:16,480
I will go to this position if I will come at this position.

192
00:10:16,510 --> 00:10:18,250
My right hand side will not exist.

193
00:10:18,610 --> 00:10:19,720
So there is no need.

194
00:10:20,110 --> 00:10:22,330
So I will vote in and minus two.

195
00:10:23,480 --> 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

196
00:10:29,720 --> 00:10:30,140
side.

197
00:10:31,130 --> 00:10:31,440
OK.

198
00:10:31,820 --> 00:10:34,790
So for finding the smallest element, we need a loop.

199
00:10:35,000 --> 00:10:38,000
Remember, we have solved the question how to find the smallest element.

200
00:10:38,660 --> 00:10:39,740
So we need a loop.

201
00:10:40,190 --> 00:10:42,440
So this loop will start from a plus one.

202
00:10:43,280 --> 00:10:47,420
So this loop will start from let's take a variable G.

203
00:10:47,510 --> 00:10:54,230
So this loop will start from a place one way, a plus one, because if I is here, I have to search

204
00:10:54,260 --> 00:10:56,060
on the right hand side.

205
00:10:56,180 --> 00:10:58,700
So I will start from I E-Plus when.

206
00:11:00,530 --> 00:11:09,350
So starting from a place when we have to check the last position so g less than or equal to N minus

207
00:11:09,350 --> 00:11:09,590
one.

208
00:11:09,680 --> 00:11:14,690
We have to go to last position G plus plus.

209
00:11:15,560 --> 00:11:16,310
What do we do?

210
00:11:16,610 --> 00:11:18,560
We will find the smallest element.

211
00:11:18,590 --> 00:11:20,750
We will write code for finding the smallest element.

212
00:11:21,410 --> 00:11:25,280
And then this loop will finish when this loop will terminate.

213
00:11:26,240 --> 00:11:30,350
What we will have, we will have the smallest element in that ident side.

214
00:11:31,500 --> 00:11:31,740
OK.

215
00:11:32,420 --> 00:11:35,570
So we will be having the smallest element in that identified.

216
00:11:36,350 --> 00:11:43,910
Now, I will compare if the smallest element on the right hand side is less than my current element.

217
00:11:44,420 --> 00:11:46,310
So what I will do, I will slap.

218
00:11:48,310 --> 00:11:54,220
I will swab I will swab the smallest element and I.

219
00:11:54,970 --> 00:11:56,830
Otherwise I will do nothing.

220
00:11:57,980 --> 00:11:58,200
OK.

221
00:11:58,390 --> 00:12:02,080
So you can see yourself, for example, in this case.

222
00:12:03,310 --> 00:12:07,810
This was I and the smallest element was this one.

223
00:12:08,370 --> 00:12:08,590
OK.

224
00:12:09,010 --> 00:12:10,990
So this was our smallest element.

225
00:12:11,770 --> 00:12:13,790
And this was our current element.

226
00:12:14,290 --> 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.

227
00:12:22,250 --> 00:12:22,860
That is four.

228
00:12:23,350 --> 00:12:24,610
Then do swapping.

229
00:12:25,060 --> 00:12:26,460
So when will you come here?

230
00:12:26,500 --> 00:12:29,530
And four will come here otherwise and do nothing.

231
00:12:30,490 --> 00:12:32,650
So this is how it works.

232
00:12:34,390 --> 00:12:36,860
OK, now let us write the code.

233
00:12:46,120 --> 00:12:49,060
So let's name this file as selections art.

234
00:12:54,050 --> 00:12:55,130
Not CBP.

235
00:13:14,370 --> 00:13:15,600
OK, so now what do we do?

236
00:13:15,660 --> 00:13:17,780
First of all, we will take areas input.

237
00:13:18,570 --> 00:13:20,410
So give me the number of elements in the.

238
00:13:21,510 --> 00:13:24,410
And now I will take input so far.

239
00:13:24,450 --> 00:13:26,580
And I was zero.

240
00:13:26,970 --> 00:13:29,580
I less than an A plus plus.

241
00:13:32,220 --> 00:13:36,720
What I will do, I will take inputs or see in a off I.

242
00:13:37,560 --> 00:13:40,700
OK, so first of all, it does make any.

243
00:13:41,130 --> 00:13:42,270
So the size of the arrays.

244
00:13:42,300 --> 00:13:47,670
And so I am making an area of size and then I am taking input.

245
00:13:48,210 --> 00:13:51,300
So in the last class we learn functions.

246
00:13:51,690 --> 00:13:54,420
So what we will do, we will make function.

247
00:13:55,440 --> 00:13:58,380
So let's say the name of the function is selection site.

248
00:13:59,430 --> 00:14:00,390
So selection.

249
00:14:02,510 --> 00:14:05,150
Selections art is the name of the function.

250
00:14:05,900 --> 00:14:07,700
OK, so what it will take as input.

251
00:14:08,300 --> 00:14:14,790
It will take an editor's input and also it will take the size of the area.

252
00:14:15,890 --> 00:14:16,630
So what do we do with that?

253
00:14:16,680 --> 00:14:20,090
Don't drop this election's art so they don't dive will be wide.

254
00:14:20,360 --> 00:14:22,670
Because this function will not return anything.

255
00:14:22,790 --> 00:14:24,250
It will sort the eddy.

256
00:14:24,830 --> 00:14:25,130
Okay.

257
00:14:25,670 --> 00:14:28,540
And from here we will call selection's art.

258
00:14:28,550 --> 00:14:29,360
So selection.

259
00:14:32,020 --> 00:14:36,250
And it will take Eddie and the size of the Eddie as input.

260
00:14:40,550 --> 00:14:42,900
OK, so we know they are biased biodefense.

261
00:14:43,490 --> 00:14:47,300
So in the last class we have seen that ad is at Boston Biodefense.

262
00:14:47,630 --> 00:14:52,070
So if I will do some changes here, that changes will be reflected here.

263
00:14:52,850 --> 00:14:53,150
OK.

264
00:14:54,200 --> 00:15:01,010
Now, after doing Selection's art and let us write the code for printing the Eddi, so forth, and I

265
00:15:01,010 --> 00:15:05,720
equals and de equals zero i.e. less than n I.

266
00:15:06,650 --> 00:15:12,860
I listin in a blessed place c out of I.

267
00:15:16,310 --> 00:15:16,600
OK.

268
00:15:17,050 --> 00:15:20,170
So I think that we have to do is we have to implement this function.

269
00:15:20,800 --> 00:15:23,720
We have to complete dysfunction selection, Saad.

270
00:15:24,580 --> 00:15:27,910
So what we have decided first of all, I need a variable.

271
00:15:27,970 --> 00:15:30,070
I need to start from zero.

272
00:15:30,640 --> 00:15:31,600
So you can see here.

273
00:15:34,110 --> 00:15:39,030
We need a variable, I need to start from zero and it will go to and minus two.

274
00:15:39,570 --> 00:15:39,860
OK.

275
00:15:40,680 --> 00:15:41,940
So starting from zero.

276
00:15:42,210 --> 00:15:42,870
So for.

277
00:15:45,430 --> 00:15:47,410
And I equals zero.

278
00:15:48,820 --> 00:15:53,010
I will go to Bill and minus two second last position.

279
00:15:53,770 --> 00:15:54,070
OK.

280
00:15:54,250 --> 00:15:55,300
I bless, bless.

281
00:15:57,100 --> 00:16:01,210
Now what we have to do, we have to find the smallest element in that right hand side.

282
00:16:02,090 --> 00:16:02,480
OK.

283
00:16:03,040 --> 00:16:05,620
So we already know how to find smallest element.

284
00:16:06,100 --> 00:16:14,170
What we used to do is we take a variable small list, which is initially intermix, which is initially

285
00:16:14,170 --> 00:16:14,880
intermix.

286
00:16:15,880 --> 00:16:19,690
And now we have to find the smallest element in the right hand side.

287
00:16:21,160 --> 00:16:25,930
So I will start my loop from a plus one.

288
00:16:26,620 --> 00:16:26,790
OK.

289
00:16:26,880 --> 00:16:28,810
So why I am starting from a plus one?

290
00:16:28,930 --> 00:16:32,590
Because I have to find the smallest element in that I tend side of a.

291
00:16:34,610 --> 00:16:42,080
So you can see here from a place where until Bill last position again, this, too, is the last position.

292
00:16:44,090 --> 00:16:44,750
So G.

293
00:16:45,210 --> 00:16:51,260
Less than articles two and minus one and minus one is deal last perdition in the Eddie J.

294
00:16:51,260 --> 00:16:51,950
Plus Bliss.

295
00:16:53,240 --> 00:16:55,130
And now how to find smallest element.

296
00:16:56,060 --> 00:16:59,870
We already know we will compare the current element with the smallest element.

297
00:17:00,260 --> 00:17:07,700
If this current element is less than my smallest element, where we used to do was we was updating,

298
00:17:07,710 --> 00:17:10,760
we were updating our smallest value.

299
00:17:11,220 --> 00:17:13,100
So smallest equals f g.

300
00:17:16,220 --> 00:17:23,640
Now, when I reach line number fifteen, when this loop will finish, when I reach plane number fifteen,

301
00:17:24,020 --> 00:17:25,550
I know does my Lesterville you.

302
00:17:27,630 --> 00:17:31,800
OK, so what I will do now, I will compare.

303
00:17:31,980 --> 00:17:42,900
So if my current value, which is if I so if my current value is greater than the smallest value, then

304
00:17:43,940 --> 00:17:44,820
what do we have to do?

305
00:17:45,180 --> 00:17:46,220
We'll have to scrap.

306
00:17:46,860 --> 00:17:47,970
So scrap.

307
00:17:49,870 --> 00:17:50,710
A of a..

308
00:17:52,160 --> 00:17:53,360
And smallest.

309
00:17:56,740 --> 00:17:58,850
So this is all that we have to do.

310
00:18:00,460 --> 00:18:06,310
So you can see here, if the smallest element is less than the current element and then we were swapping.

311
00:18:07,940 --> 00:18:08,860
OK, so this is the.

312
00:18:09,170 --> 00:18:10,990
So this is our entire logic.

313
00:18:11,630 --> 00:18:14,540
Now let's see where that our logic is, correct or not.

314
00:18:18,630 --> 00:18:26,700
So the number of elements out of five and we'll lose a seven, five, three, six and eight.

315
00:18:28,530 --> 00:18:30,150
So this is my output.

316
00:18:31,850 --> 00:18:35,410
And we all know our out for days coming out to be wrong.

317
00:18:36,470 --> 00:18:38,020
But why this coming out to be wrong?

318
00:18:38,210 --> 00:18:42,590
We have done everything that we have discussed, then why our output is wrong.

319
00:18:42,680 --> 00:18:43,340
So let's see.

320
00:18:44,150 --> 00:18:47,990
Let's try to understand why other gold is giving wrong output.

321
00:18:48,420 --> 00:18:48,630
OK.

322
00:18:48,710 --> 00:18:51,530
So what we will do, we will drive an hour called.

323
00:18:52,870 --> 00:18:57,250
So we will take an example and we will drive an our called.

324
00:18:59,090 --> 00:19:05,990
So the example Edward took was our area was seven, five, three, six and eight.

325
00:19:06,410 --> 00:19:07,930
So this was our eddy.

326
00:19:08,970 --> 00:19:11,510
Now, as elections are, I equals zero.

327
00:19:11,570 --> 00:19:14,450
So my eye is at this point.

328
00:19:15,650 --> 00:19:18,360
I will go till the second last portion.

329
00:19:18,410 --> 00:19:23,870
So I will go I will go from this position to this politician.

330
00:19:25,460 --> 00:19:28,330
Correct, smallest equals in mix.

331
00:19:28,610 --> 00:19:29,960
So initially, my smallest.

332
00:19:31,030 --> 00:19:35,580
Initially, my smallest is and makes this place infinity.

333
00:19:35,660 --> 00:19:35,830
OK?

334
00:19:36,700 --> 00:19:39,220
So we have to find the smallest elemental light inside.

335
00:19:39,610 --> 00:19:42,130
So the veil of G will start from a plus one.

336
00:19:43,330 --> 00:19:44,550
So the value of.

337
00:19:44,950 --> 00:19:46,030
So the value of J.

338
00:19:46,390 --> 00:19:47,470
We start from here.

339
00:19:47,650 --> 00:19:48,640
So this is my G.

340
00:19:50,420 --> 00:19:52,580
And Jaivin gotin last position.

341
00:19:52,670 --> 00:19:54,620
So, Jay, will you go then head?

342
00:19:58,150 --> 00:19:58,380
OK.

343
00:19:58,470 --> 00:20:03,480
So what I'm doing, I'm comparing the current value, L.G., with the smallest value.

344
00:20:04,170 --> 00:20:07,200
So we are comparing five with infinity.

345
00:20:07,620 --> 00:20:09,660
So obviously five is smaller.

346
00:20:10,020 --> 00:20:11,690
So I will update my small list.

347
00:20:12,270 --> 00:20:15,870
So now smallest becomes five.

348
00:20:16,160 --> 00:20:16,480
OK.

349
00:20:17,760 --> 00:20:19,070
Now go above J.

350
00:20:19,080 --> 00:20:19,740
Plus plus.

351
00:20:19,980 --> 00:20:21,230
OK, so J will come here.

352
00:20:22,990 --> 00:20:28,710
Now, again, compare the current value that this tree with five cents trees smaller.

353
00:20:28,990 --> 00:20:30,520
I will update the value of smallest.

354
00:20:30,590 --> 00:20:32,080
So smallest becomes three.

355
00:20:33,240 --> 00:20:36,570
Now, a J plus plus so J will reach here.

356
00:20:37,050 --> 00:20:40,800
So compare the current value with the smallest value.

357
00:20:41,350 --> 00:20:43,980
Get to this condition is this condition is false.

358
00:20:44,340 --> 00:20:44,910
Do nothing.

359
00:20:45,960 --> 00:20:48,390
Now a J will be incremented J will reach here.

360
00:20:49,890 --> 00:20:52,950
Compare the current value with the smallest value.

361
00:20:53,790 --> 00:20:56,070
So this condition is again false.

362
00:20:56,550 --> 00:20:57,750
J will reach here.

363
00:20:58,140 --> 00:20:59,810
J will becomes equals two n.

364
00:21:00,270 --> 00:21:01,230
And this loop.

365
00:21:01,950 --> 00:21:03,060
This loop will break.

366
00:21:03,750 --> 00:21:04,950
Or you should say terminate.

367
00:21:05,520 --> 00:21:06,740
This loop terminated.

368
00:21:08,430 --> 00:21:08,690
Okay.

369
00:21:09,090 --> 00:21:10,950
Now I will reach at this line.

370
00:21:11,730 --> 00:21:12,240
So if.

371
00:21:12,460 --> 00:21:13,140
If I.

372
00:21:13,560 --> 00:21:15,120
So if I was seven.

373
00:21:16,950 --> 00:21:20,350
So if HFA is greater than smallest.

374
00:21:20,530 --> 00:21:21,780
So smallest is three.

375
00:21:22,410 --> 00:21:23,560
So seven is good.

376
00:21:23,600 --> 00:21:24,120
Then three.

377
00:21:24,180 --> 00:21:24,570
Yes.

378
00:21:25,140 --> 00:21:26,700
I am accepting the values.

379
00:21:27,510 --> 00:21:27,660
OK.

380
00:21:27,750 --> 00:21:29,100
So three will come here.

381
00:21:29,760 --> 00:21:31,680
And seven will come here.

382
00:21:32,940 --> 00:21:33,090
OK.

383
00:21:33,150 --> 00:21:34,950
So my new area becomes three.

384
00:21:35,790 --> 00:21:36,330
Five.

385
00:21:36,420 --> 00:21:36,930
Three.

386
00:21:37,050 --> 00:21:37,500
Six.

387
00:21:37,980 --> 00:21:38,250
Eight.

388
00:21:38,880 --> 00:21:42,360
And smallest is seven.

389
00:21:42,900 --> 00:21:44,340
Now this is the main problem.

390
00:21:45,300 --> 00:21:47,190
You can observe the seven.

391
00:21:47,520 --> 00:21:48,300
This is seven.

392
00:21:48,600 --> 00:21:50,880
Should be so with this tree.

393
00:21:52,010 --> 00:21:58,590
OK, so instead this is swiping its value from the smallest value with the smallest value.

394
00:21:59,610 --> 00:21:59,790
OK.

395
00:21:59,850 --> 00:22:02,250
So I think you've got the logic where we are then.

396
00:22:02,250 --> 00:22:02,910
Net mistake.

397
00:22:03,970 --> 00:22:07,310
So the mistake is we are slapping LFA.

398
00:22:07,520 --> 00:22:11,260
We are slapping a fight with the smallest value.

399
00:22:12,320 --> 00:22:12,660
OK.

400
00:22:12,770 --> 00:22:14,060
And what we should have done.

401
00:22:14,450 --> 00:22:16,340
We have swept this value.

402
00:22:16,730 --> 00:22:18,020
Would this value.

403
00:22:19,330 --> 00:22:19,480
OK.

404
00:22:19,570 --> 00:22:25,010
So you can see here three appears, two times here should be seven.

405
00:22:26,620 --> 00:22:28,330
So how we can correct this mistake?

406
00:22:29,110 --> 00:22:30,550
So the logic is very simple.

407
00:22:30,700 --> 00:22:31,900
Instead of storing the value.

408
00:22:32,260 --> 00:22:33,640
So here I am storing the value.

409
00:22:33,740 --> 00:22:40,570
Three, what I will do instead of storing the value stored that index store index, for example.

410
00:22:40,600 --> 00:22:43,120
This is this is second index.

411
00:22:43,300 --> 00:22:44,560
So zero one and two.

412
00:22:45,160 --> 00:22:46,330
So this is second index.

413
00:22:46,660 --> 00:22:49,210
So instead of storing the value, stored the index.

414
00:22:50,320 --> 00:22:51,180
Store index.

415
00:22:51,220 --> 00:22:58,150
And finally, instead of slapping these two values, what I will do, I will scrap if I would eat off

416
00:22:58,330 --> 00:22:59,200
smallest.

417
00:23:02,220 --> 00:23:10,260
So my smallest variable will contain the smallest variable will store the index having smallest value.

418
00:23:10,500 --> 00:23:13,380
So index having smallest value.

419
00:23:17,890 --> 00:23:21,460
OK, so the index of three is two.

420
00:23:21,820 --> 00:23:24,950
And finally, what I will do, I will swab if I.

421
00:23:25,090 --> 00:23:27,910
That is seven with a of smallest.

422
00:23:28,150 --> 00:23:29,350
Smallest is three.

423
00:23:29,770 --> 00:23:33,820
Okay, so then these values will be swabbed, which is correct.

424
00:23:34,780 --> 00:23:37,090
OK, so what I am doing.

425
00:23:38,140 --> 00:23:40,120
So in the desk comment this whole called.

426
00:23:43,440 --> 00:23:45,780
And now we will write the characterful.

427
00:23:47,170 --> 00:23:49,150
So there will be some minor changes.

428
00:23:50,980 --> 00:23:52,420
So I will start from zero.

429
00:23:52,690 --> 00:23:56,080
No doubt I will go till second last position.

430
00:23:56,090 --> 00:24:00,400
So and minus two I plus plus.

431
00:24:01,930 --> 00:24:04,780
So I am creating a variable smallest.

432
00:24:05,320 --> 00:24:11,710
So this smallest variable will contain the index of the smallest value.

433
00:24:12,040 --> 00:24:16,130
So let's say the smallest value is present at index eye.

434
00:24:17,100 --> 00:24:17,320
OK.

435
00:24:17,950 --> 00:24:19,930
So I am saying where I am standing.

436
00:24:19,990 --> 00:24:21,640
This is the smallest value.

437
00:24:22,260 --> 00:24:24,880
So a small list is containing the index.

438
00:24:26,520 --> 00:24:30,210
Now I have to find the smallest value in the right hand side.

439
00:24:31,050 --> 00:24:36,080
So four and J equals eight plus one.

440
00:24:36,120 --> 00:24:41,590
We will start from a plus when Angie will go to Last Perdition.

441
00:24:41,640 --> 00:24:44,010
So N minus one is the last position.

442
00:24:44,650 --> 00:24:45,770
Angie, bless.

443
00:24:45,780 --> 00:24:46,200
Bless.

444
00:24:48,840 --> 00:25:01,650
So I really compare if the current value if the current value is less than my smallest value, then

445
00:25:01,650 --> 00:25:10,730
what I will do then smallest will store the index of the smallest value, which is Gaono.

446
00:25:10,920 --> 00:25:11,150
OK.

447
00:25:11,610 --> 00:25:16,620
So initially I was saying that where I'm standing, this is the smallest value.

448
00:25:16,680 --> 00:25:18,810
So smallest is containing the index.

449
00:25:19,490 --> 00:25:21,460
OK, so now I'm comparing.

450
00:25:22,050 --> 00:25:27,270
So Elsmore list Elsmore Lesterville give me that value and I'm comparing.

451
00:25:27,690 --> 00:25:32,600
So if A of G is less than Aylsworth list then I will update the value of smallest.

452
00:25:33,180 --> 00:25:38,060
So you can against here the smallest variable is storing that index.

453
00:25:39,690 --> 00:25:41,490
And then this loop is terminated.

454
00:25:42,210 --> 00:25:43,440
So when this loop will break.

455
00:25:44,160 --> 00:25:45,000
What do I have?

456
00:25:45,180 --> 00:25:48,270
I will have the index of the smallest value.

457
00:25:48,900 --> 00:25:52,620
So I just have to scrap it.

458
00:25:52,620 --> 00:25:59,930
Or if I get this current value with the smallest value that I have found out in the right hand side.

459
00:26:02,270 --> 00:26:04,140
Now, this good is correct.

460
00:26:05,430 --> 00:26:07,680
OK, so let us run our program.

461
00:26:10,780 --> 00:26:18,940
So there are five elements and the elements are seven, five, three, six and eight, so output is

462
00:26:19,870 --> 00:26:20,290
correct.

463
00:26:21,250 --> 00:26:23,930
So you can see my output is correct.

464
00:26:25,000 --> 00:26:26,620
My Ed is getting started.

465
00:26:28,060 --> 00:26:28,780
One more time.

466
00:26:29,740 --> 00:26:32,030
So a number of elements out of five and element out.

467
00:26:32,080 --> 00:26:36,040
One, two, five, four and three.

468
00:26:37,210 --> 00:26:40,060
So my output is one, two, three, four, five.

469
00:26:41,020 --> 00:26:41,680
Last time.

470
00:26:43,210 --> 00:26:48,940
So the number of elements are four and the elements are four, three, two and one, some are days.

471
00:26:49,110 --> 00:26:50,460
One, two, three and four.

472
00:26:50,560 --> 00:26:51,780
So that is getting started.

473
00:26:53,340 --> 00:26:53,530
OK.

474
00:26:54,600 --> 00:26:55,910
So where does it end our program?

475
00:26:56,370 --> 00:26:59,610
Let us right in our goal to get how it is working.

476
00:27:00,750 --> 00:27:02,340
So let us take small example.

477
00:27:02,520 --> 00:27:10,260
So suppose my array's three, two, one and four.

478
00:27:10,620 --> 00:27:11,580
So this is my area.

479
00:27:12,380 --> 00:27:12,610
OK.

480
00:27:12,920 --> 00:27:14,330
I'm taking a small example.

481
00:27:16,510 --> 00:27:19,090
I equals zero, so I is here.

482
00:27:20,850 --> 00:27:25,980
Now, I will go tell here, I will vary from this to this.

483
00:27:27,330 --> 00:27:27,750
Correct.

484
00:27:30,260 --> 00:27:31,070
So this is zero.

485
00:27:31,100 --> 00:27:31,670
This is one.

486
00:27:31,700 --> 00:27:32,300
This is two.

487
00:27:32,300 --> 00:27:33,020
And this is three.

488
00:27:33,050 --> 00:27:34,030
So these are indexes.

489
00:27:34,160 --> 00:27:34,480
OK.

490
00:27:35,350 --> 00:27:37,880
The smallest equals a so smallest.

491
00:27:39,210 --> 00:27:40,510
It was zero.

492
00:27:40,730 --> 00:27:43,510
OK, so Jay will start from a plus one.

493
00:27:43,540 --> 00:27:46,570
So here is Jay, OK.

494
00:27:46,720 --> 00:27:55,120
Now compare EOG compare to so of Jaimie's a of J equals two with a of smallest.

495
00:27:55,180 --> 00:27:56,650
So aof smallest.

496
00:27:56,920 --> 00:27:59,320
Is A of Gedo equals three.

497
00:27:59,650 --> 00:28:01,720
So I am comparing two with three.

498
00:28:02,670 --> 00:28:04,720
OK, so compare two with three.

499
00:28:04,990 --> 00:28:07,270
So two is a smaller two is smaller.

500
00:28:07,300 --> 00:28:08,610
I will update smallest.

501
00:28:09,220 --> 00:28:13,180
So the smallest now is one.

502
00:28:13,640 --> 00:28:13,830
OK.

503
00:28:13,900 --> 00:28:15,580
So smallest is one now.

504
00:28:17,520 --> 00:28:18,390
Incremented G.

505
00:28:18,560 --> 00:28:19,580
So, Jay, when you come here.

506
00:28:21,370 --> 00:28:26,740
Now, I have to compare the value of one with a of smallest.

507
00:28:26,830 --> 00:28:31,630
So Ale's molester's to compare one with two smallest will get ablated.

508
00:28:32,310 --> 00:28:35,110
So the smallest is no index three.

509
00:28:36,040 --> 00:28:37,720
Okay, Jay will come here.

510
00:28:39,100 --> 00:28:42,820
Compare AFGE with each of the smallest.

511
00:28:42,910 --> 00:28:43,930
So aof three.

512
00:28:45,600 --> 00:28:46,510
So it should be two.

513
00:28:47,350 --> 00:28:48,040
It will be two.

514
00:28:48,370 --> 00:28:52,930
So compare Ayodeji with each of the smallest of two.

515
00:28:53,200 --> 00:28:55,930
So afterwards, toys when so compare one with four.

516
00:28:56,410 --> 00:28:57,220
Do nothing.

517
00:28:58,030 --> 00:29:03,160
Now, this loop will terminate because while this loop will dominate because J equals.

518
00:29:03,190 --> 00:29:06,420
And so J will come here, J becomes sane.

519
00:29:06,550 --> 00:29:07,680
So this law will dominate.

520
00:29:08,080 --> 00:29:11,220
I will reach at line number 31 sarap efi.

521
00:29:11,920 --> 00:29:13,510
So if I was three.

522
00:29:14,890 --> 00:29:21,400
If I was three with a of the smallest, smallest is two and a of two is one.

523
00:29:21,980 --> 00:29:24,160
So asvab three and one.

524
00:29:24,890 --> 00:29:29,290
OK, so new and it will be one, two, three and four.

525
00:29:31,520 --> 00:29:32,500
So this is my new eddy.

526
00:29:33,410 --> 00:29:34,820
Now I will come here.

527
00:29:35,710 --> 00:29:36,420
I bless, bless.

528
00:29:36,560 --> 00:29:37,370
I will come here.

529
00:29:38,120 --> 00:29:43,620
And again, we will repeat all the operations, all the instructions, so it will get sorted.

530
00:29:45,260 --> 00:29:51,750
OK, so the main thing that I want to tell you is we will store that index.

531
00:29:52,230 --> 00:29:53,370
We will not store the value.

532
00:29:53,400 --> 00:29:56,330
So here you can see smallest equals G.

533
00:29:57,330 --> 00:29:58,680
We will not store the value.

534
00:29:58,710 --> 00:29:59,430
We will even.

535
00:29:59,490 --> 00:30:01,050
We will store the index.

536
00:30:02,270 --> 00:30:02,440
OK.

537
00:30:02,560 --> 00:30:03,730
So if I have the index.

538
00:30:04,860 --> 00:30:07,790
I can write a small list to get the value.

539
00:30:09,610 --> 00:30:11,580
So I think this elevate them is clear to you now.

540
00:30:12,360 --> 00:30:12,700
OK.

541
00:30:13,030 --> 00:30:14,140
So what do you have to do?

542
00:30:14,260 --> 00:30:15,510
So this is most OK.

543
00:30:15,910 --> 00:30:16,900
So what do you have to do?

544
00:30:17,110 --> 00:30:19,420
You have to write this code on your own.

545
00:30:20,080 --> 00:30:21,590
And you have to brighten this cold.

546
00:30:22,330 --> 00:30:22,650
OK.

547
00:30:22,930 --> 00:30:23,980
Please, please, please.

548
00:30:24,430 --> 00:30:25,330
This is my request.

549
00:30:25,690 --> 00:30:27,540
Take pen and paper and died in this cold.

550
00:30:27,960 --> 00:30:32,170
First, try to understand why this logic was why this logic was wrong.

551
00:30:33,330 --> 00:30:38,280
And then try to understand when I am storing the indexes, how this code is working.

552
00:30:39,180 --> 00:30:39,470
OK.

553
00:30:40,200 --> 00:30:43,860
So if you have any doubt regarding this elections or deliver them, feel free to ask.

554
00:30:45,180 --> 00:30:45,690
OK, guys.

555
00:30:45,750 --> 00:30:47,130
So this is it for this video.

556
00:30:47,670 --> 00:30:48,210
Thank you.
