﻿1
00:00:00,460 --> 00:00:04,930
‫So in this video, we're going to walk through the steps for selection sort.

2
00:00:04,930 --> 00:00:08,230
‫And then in the next video we will code this.

3
00:00:08,590 --> 00:00:13,210
‫So I'll start out by bringing up our array that will represent like this.

4
00:00:13,510 --> 00:00:18,640
‫But with selection sort, we're also going to need the indexes.

5
00:00:18,640 --> 00:00:20,980
‫So I'll go ahead and bring those up.

6
00:00:21,430 --> 00:00:26,530
‫So with selection sort, we start with this first item.

7
00:00:26,980 --> 00:00:34,030
‫And what we're going to do is we're going to look for the index that contains the lowest value.

8
00:00:34,390 --> 00:00:38,020
‫So this is the only one we've looked at so far.

9
00:00:38,050 --> 00:00:43,030
‫So we're going to have a variable called Mean Index and we're going to set it to zero.

10
00:00:43,540 --> 00:00:49,420
‫So I want to emphasize that this variable does not hold the value of four.

11
00:00:49,450 --> 00:00:52,210
‫It holds the index of zero.

12
00:00:52,600 --> 00:00:59,710
‫So then what we'll have is a loop where we start with the next item and say is the value of this item

13
00:00:59,710 --> 00:01:04,240
‫less than the one at the index of zero and in this case it is.

14
00:01:04,690 --> 00:01:08,770
‫So we're going to set min index to be equal to one.

15
00:01:09,430 --> 00:01:10,900
‫Then we'll look at the next item.

16
00:01:10,900 --> 00:01:15,280
‫This one is not less than, so we won't do anything there or there.

17
00:01:15,280 --> 00:01:18,760
‫But when we get to this value, this one is lower.

18
00:01:18,760 --> 00:01:22,630
‫So we'll update min index to be equal to four.

19
00:01:23,430 --> 00:01:26,580
‫That will continue through the end of the array.

20
00:01:27,150 --> 00:01:34,020
‫And once we've finished looping through, we know that our min index is at the index of four.

21
00:01:34,530 --> 00:01:38,880
‫So now what we're going to do is take these two items and swap them.

22
00:01:39,270 --> 00:01:42,350
‫And when we do that, one is sorted.

23
00:01:42,360 --> 00:01:49,140
‫So I'll color that in grain and then we'll start the process again with the next item.

24
00:01:49,320 --> 00:01:55,290
‫We'll set an index equal to one and then we'll have a loop that loops through the rest of the array.

25
00:01:55,680 --> 00:01:59,800
‫And you can tell by looking at this that the two is the lowest item.

26
00:01:59,820 --> 00:02:01,920
‫So this is a different situation.

27
00:02:01,920 --> 00:02:03,840
‫We're not going to have a swap.

28
00:02:03,840 --> 00:02:06,270
‫And that's something we'll talk about when we code this.

29
00:02:06,270 --> 00:02:10,890
‫How do we handle the situation when we don't need to do a swap?

30
00:02:11,310 --> 00:02:14,370
‫But we are going to loop through this like this.

31
00:02:14,370 --> 00:02:21,810
‫And when we get to the end men index is equal to one and that means that item is sorted.

32
00:02:22,290 --> 00:02:29,910
‫So let's do this for the six and men index is two and I'm going to move this variable over because we're

33
00:02:29,910 --> 00:02:32,340
‫going to run out of room over there in a moment.

34
00:02:33,000 --> 00:02:34,490
‫But we compare it to the five.

35
00:02:34,500 --> 00:02:35,760
‫Now that's the lowest.

36
00:02:35,760 --> 00:02:38,790
‫Then the four, that's the lowest and the three.

37
00:02:39,420 --> 00:02:41,820
‫And now that item is the lowest.

38
00:02:42,090 --> 00:02:47,400
‫And now that we've run to the end, we know that the min index is at the index of five and we'll swap

39
00:02:47,400 --> 00:02:47,820
‫these.

40
00:02:47,820 --> 00:02:49,650
‫And now that three is sorted.

41
00:02:50,040 --> 00:02:53,010
‫So now we just have a couple more times to run through this.

42
00:02:53,010 --> 00:02:57,270
‫So we'll just take the five men indexes at the index of three.

43
00:02:57,480 --> 00:02:59,400
‫That next item is lower.

44
00:02:59,400 --> 00:03:01,740
‫So we'll update an index.

45
00:03:02,450 --> 00:03:05,540
‫And now we know men index is at the index of four.

46
00:03:05,570 --> 00:03:12,770
‫We swap these, the four is sorted and we'll do this one more time where we compare the five at the

47
00:03:12,770 --> 00:03:15,410
‫index of four to the six.

48
00:03:15,620 --> 00:03:17,450
‫And these don't need to be swapped.

49
00:03:17,450 --> 00:03:19,760
‫So these are both sorted.

50
00:03:20,410 --> 00:03:22,540
‫So we'll code this in the next video.

51
00:03:22,540 --> 00:03:29,200
‫And when we do, we'll kick off that video with an array that looks like this and then we'll write the

52
00:03:29,200 --> 00:03:30,970
‫code to sort that.

53
00:03:31,590 --> 00:03:36,180
‫But for now, that is our overview of selection sort.

