Category
š
LearningTranscript
00:00Hello everyone, today I am going to explain bubble sort, how to arrange values which are
00:09there inside the array in numerical sorted order.
00:14Let us first understand with this diagram, what is the methodology of bubble sorting
00:23take place.
00:25Here if you see there are four iteration, this is the first iteration, this is the second
00:30iteration, this is the third one and the fourth and at the last we get the result.
00:37The values are inside the array in random order, I have shown the array in a vertical
00:44form and the values inside it are in random order.
00:51What is the methodology, how the things work, the jth position value is going to compare
01:02with the first position value and if the jth position value is greater than first position
01:10value, then the values are going to interchange, 13 is going to the jth position and 14 is
01:18going to the first position, as the 14 is greater than 13, so 13 is at the jth and 14
01:25is the first.
01:27Then the first position value is going to compare with the second, if the condition
01:32true then interchange will take place otherwise not, 14 greater than 15, interchange will
01:40not take place, the values will remain in its own position, so 14 is at the first and
01:4715 is at second.
01:51Now we will move to further down to the second position, the second position is compared
02:01with the third position, 15 greater than 12, so the 12 is at the second position and 15
02:07is at the third and then 15 is compared to the last one, 15 greater than 11, so 15 is
02:15at the third position, sorry 11 is at the third position and 15 is at the fourth position,
02:23interchange take place.
02:26Now if you see from downside the arrangement will take place, now we have got 15 at the
02:35last index position, again the iteration will start but it will go one less than
02:45last position, 13 is compared with 14, sorry the interchange will not take place,
02:52that is not greater than 14.
02:55Then one step down, the first position is compared with 12, 14 greater than 12, yes
03:01interchange take place, 12 is above and 14 come down and 14 is compared with 11,
03:0914 greater than 11, yes again the condition is true, 11 is upside and 14 is the down
03:19and when you see here, so the arrangement is what taking place, here is 14 and here is 15.
03:29Now again it will start from jth position, jth is compared with first,
03:33yes the interchange will take place, 12 will go up and 13 will come down,
03:38then 13 is compared with 11, 13 greater than 11, yes the interchange will take place,
03:44the swapping will take place, 11 will go to the first position
03:48and 13 will come to the second position.
03:52So in this way the arrangement will take place, at last the jth position value is compared with
03:58the first one, yes interchange will take place and at last we will get the result.
04:08So first of all the four iteration take place in the iteration one,
04:12then one less than, then three iteration, then two and then one and we will get the final result.
04:19So I am going to make the program in my next class.
04:22Thanks for today.