WEBVTT 00:00.180 --> 00:03.600 In this video we will learn about Barbour sought in more specifically. 00:03.600 --> 00:08.090 We will analyze how this whole group walks into what is the philosophy behind sort of dictionary. 00:08.130 --> 00:15.140 For example if you have 5 4 9 and 6 after the bubble sort you will have 4 5 6 and 9. 00:22.230 --> 00:26.750 First of all we have a naray with 5 numbers 1 4 0 8 12. 00:26.940 --> 00:31.620 We need to sort of decide a descending corridor of these means that define the larie should be well 00:31.700 --> 00:33.200 eight for one and 0. 00:33.330 --> 00:37.300 So how can we know that there are numerous ways that you can shorten narey. 00:37.350 --> 00:41.790 One of the best ways to create a solution and develop you know a good way of thinking is to pause the 00:41.790 --> 00:43.720 video in stride doing when the wheel. 00:43.760 --> 00:48.910 I know that you didn't go to Google and find an already paid for code in Python that can do your job. 00:48.930 --> 00:53.820 However you are here to learn and develop your skills in just trusted use already created called. 00:53.820 --> 00:59.520 You will not gain experience stories your call bookie I call that you already tried the first loop because 00:59.520 --> 01:02.500 as variables to find the minimum number in the whole. 01:02.500 --> 01:07.410 Ari the owl got me straight forward in every step of the program compares towards us and numbers even 01:07.440 --> 01:09.790 the first one is more loaded than the second. 01:09.810 --> 01:10.950 They need to swap. 01:11.010 --> 01:12.810 In other words they will team's position. 01:12.880 --> 01:14.610 Let's assume that we have an Nardy. 01:14.730 --> 01:20.000 Only two numbers the number 5 in the first position in the number 8 in the second position. 01:20.010 --> 01:24.240 In this case we will swap them because 5 is smaller than 8. 01:24.240 --> 01:30.160 The goal here is to bring this smallest number in the end of the day ending this case. 01:30.180 --> 01:32.320 We succeeded that in we made these out. 01:32.330 --> 01:39.650 In any cynic order first aid and then 5 Let us know now that we have not a we fit in numbers 7 1 in 01:39.650 --> 01:45.220 9 for sure we can bet the first two numbers 7 is bigger than 1 so we will not seen anything. 01:45.240 --> 01:50.260 Then we compared a one into nine because we want to compare all of the ads as in numbers. 01:50.280 --> 01:56.160 One is smaller than 9 so we will retain their position after this while we cover 7 9 and 1. 01:56.190 --> 01:58.730 As you can see here we started to have a bit there. 01:58.730 --> 02:01.120 Three but it is not in descending cawdor yet. 02:01.140 --> 02:04.120 Lets try to use the same algorithm in theory again. 02:04.140 --> 02:09.910 7 is smaller than 9 so we will swap them in 7 is bigger than 1 so we will not do anything. 02:09.950 --> 02:10.510 OK. 02:10.620 --> 02:14.980 As you can see here the final results are correct for the analysis of this problem we make. 02:14.990 --> 02:20.300 I need this theory set to process that we started from very small and easy to handle examples in that 02:20.300 --> 02:23.350 we move on to the bigger and more difficult ones. 02:23.440 --> 02:25.890 Any member of his method in the use it in the future. 02:26.040 --> 02:27.150 Finally we will try it. 02:27.150 --> 02:30.550 We can now say with four numbers dont live yet even. 02:30.610 --> 02:35.900 The key is that you feel confident for the algorithm because we've also analyze the actual code we cover 02:35.940 --> 02:43.290 the number 5 1 9 and while in the beginning we will compare the first two numbers into 5 is bigger than 02:43.290 --> 02:45.410 1 so we will have not seen anything. 02:45.510 --> 02:47.300 Then one is monard of a 9. 02:47.340 --> 02:49.860 So we will swab them and get these results. 02:49.860 --> 02:55.770 Again one is one of the well so we will swap up again as you can see here of this smaller a number of 02:55.770 --> 02:58.510 the RG is already placed in the position. 02:58.530 --> 03:00.180 Then we use this same Margaret. 03:00.240 --> 03:03.800 Again we will take 5 with nine and we will get the results. 03:03.810 --> 03:06.590 9 5 12 and 1 in 5. 03:06.590 --> 03:07.260 These are different. 03:07.270 --> 03:12.600 Well so when you get these results finally 5 is bigger than 1 so we will not change them. 03:12.690 --> 03:16.780 As you can see here we have the two smallest numbers in the last positions. 03:16.800 --> 03:20.580 If we use the algorithm one more time then 9 is more advanced. 03:20.580 --> 03:23.270 Well then we will get it out again. 03:23.270 --> 03:28.470 It is no use if we do the last two comparisons because they are the smallest numbers in the idea. 03:28.500 --> 03:33.990 So from this problems we not designing neighbouring mules can fill as no is in the right place. 03:33.990 --> 03:35.220 Indeed we are not saints. 03:35.220 --> 03:38.820 First one is in the right place then 5 and finally 9. 03:38.820 --> 03:41.240 Sure the first time we will is kind of the four numbers. 03:41.250 --> 03:47.260 Then the second time we will scan the first three numbers and then we can only get to. 03:47.280 --> 03:50.580 This is an optimization that is feeding in this particular problem. 03:50.610 --> 03:52.400 So how can we build the Saari. 03:52.440 --> 03:57.420 Of course the problem is language but it is not important due to the fact that the idea of the owl God 03:57.600 --> 04:04.320 is the same in any language from the previous example you can identify that for a nardi with 14 numbers. 04:04.320 --> 04:06.020 We make three loops then four. 04:06.050 --> 04:09.570 Then we think damba we make tools and so on. 04:09.660 --> 04:16.290 So we will use the for laub for I in that ain't zero comma N minus one because n is the number of the 04:16.300 --> 04:16.970 addy. 04:17.040 --> 04:18.280 Every dime we make. 04:18.300 --> 04:22.480 N minus one looks we need a one more loop that makes a comparison. 04:22.490 --> 04:27.270 This is love compared to the first with this on the circle with the third until 1. 04:27.360 --> 04:31.960 So the command line is 40 in the range zero minus one. 04:31.980 --> 04:35.930 We learn the lesson a moment why this in mind as one in finally inside the loop. 04:35.930 --> 04:37.150 We will make the comparison. 04:37.190 --> 04:40.600 If added day is eliz then add a table as one. 04:40.620 --> 04:46.530 We will swap them as you can see here we use the tables as shown in the Z plus 1 indefinably so we dont 04:46.530 --> 04:51.780 want to go out of the boundaries in that that is what we use in mind as one to follow up because the 04:51.780 --> 04:54.650 final position is in minus one plus one. 04:54.690 --> 04:55.520 And this is equal to. 04:55.560 --> 04:58.410 And of course these are gaurdian we work very effectively. 04:58.440 --> 05:03.560 But if we want to make one more optimization we can eliminate the last point of the day. 05:03.600 --> 05:08.550 In neighbouring use can't we have previously analyzed that Confed for the numbers. 05:08.550 --> 05:14.230 Then we compare three numbers because the fourth number is the smallest so we can state. 05:14.250 --> 05:16.610 Then we compared two numbers and so on. 05:16.680 --> 05:19.640 So if you change the second look and tried for it. 05:19.740 --> 05:21.280 That ain't zero come up. 05:21.460 --> 05:22.930 Minus one minus. 05:22.930 --> 05:26.150 I.e. the first time I is equal to zero. 05:26.200 --> 05:27.810 So we discount the call Larry. 05:27.820 --> 05:33.970 Then it is equal to 1 so we will iskander call three except the last position and so on the following 05:33.970 --> 05:35.270 initialize the RG. 05:35.380 --> 05:37.990 Then we need the length of these Hardi. 05:38.020 --> 05:40.270 Now we would create the first four low. 05:40.300 --> 05:44.310 So for a C in the St.. 05:45.070 --> 05:46.850 Zero call Mark N.. 05:46.860 --> 05:49.080 Mine was 1 in the colon. 05:49.080 --> 05:51.640 We already talked about that in the analysis. 05:51.660 --> 05:56.030 We only allowed to do in minus one loeb's in a little short of the RG. 05:56.160 --> 06:01.650 Then we need one more readable for him in the Aints. 06:01.940 --> 06:06.170 There's zero comma N minus T minus one. 06:06.180 --> 06:09.610 Again we don't have odds that in the analysis in this what part. 06:12.480 --> 06:19.680 Well when you use the first swab that would lend them this sequel to harem. 06:20.540 --> 06:21.540 Hi. 06:22.010 --> 06:27.700 The sequel to our day plus one today. 06:27.890 --> 06:31.260 Plus these sequels sequel them up. 06:33.060 --> 06:35.320 And finally we can put in the results. 06:37.210 --> 06:38.730 Everything seems correct. 06:38.740 --> 06:39.820 We use these. 06:39.920 --> 06:42.070 And the output is indice in court.