1
00:00:01,770 --> 00:00:03,300
Hey, guys, what's up?

2
00:00:03,900 --> 00:00:07,080
So in the last video, we talked about bubbles and.

3
00:00:08,140 --> 00:00:14,510
And I told you that bubbles are take's and square number of steps to sort out Eddie.

4
00:00:15,250 --> 00:00:15,460
OK.

5
00:00:15,850 --> 00:00:22,980
So, for example, if my input is, let's say three, four, seven, one, 10.

6
00:00:23,470 --> 00:00:26,570
So if my input is this, how many number of steps it will take.

7
00:00:26,680 --> 00:00:29,050
It will take and square a number of steps.

8
00:00:30,750 --> 00:00:30,990
OK.

9
00:00:31,460 --> 00:00:38,330
So if my error is one, three, four, seven and 10.

10
00:00:39,050 --> 00:00:44,540
So if my input is this, then also it will take into a number of steps.

11
00:00:45,380 --> 00:00:45,600
OK.

12
00:00:45,890 --> 00:00:46,850
So this Eddie.

13
00:00:47,420 --> 00:00:49,040
This error is unsorted, Eddy.

14
00:00:50,470 --> 00:00:52,120
And this ad is unsorted.

15
00:00:53,500 --> 00:00:56,230
Then it is taking and screen a number of steps.

16
00:00:57,510 --> 00:00:59,930
This area is already started.

17
00:01:01,470 --> 00:01:04,260
This area is already sorted.

18
00:01:04,740 --> 00:01:11,180
Then also it is taking and square a number of steps to sort this area, which is already sorted.

19
00:01:12,020 --> 00:01:12,250
OK.

20
00:01:12,630 --> 00:01:17,400
So if I give this as input, my Bosshard will take and growing number of steps.

21
00:01:17,850 --> 00:01:23,490
If I give this as input, then also those are the sticking into a number of steps.

22
00:01:24,240 --> 00:01:27,030
So our aim is to optimize.

23
00:01:28,100 --> 00:01:30,830
Our aim is to optimize bubbles out.

24
00:01:32,980 --> 00:01:39,100
So that if the import is unsorted, it can take and a number of steps.

25
00:01:39,340 --> 00:01:44,590
But if the FDA is already sorted, it will take and steps.

26
00:01:48,630 --> 00:01:48,860
OK.

27
00:01:49,150 --> 00:01:50,620
So we want to achieve this.

28
00:01:53,420 --> 00:01:54,200
So what we want.

29
00:01:54,620 --> 00:02:01,430
We want to optimize our bubbles out so that if the given Eddie is already sorted, then it should pick

30
00:02:01,690 --> 00:02:02,510
and the steps.

31
00:02:04,230 --> 00:02:06,510
So how we can optimize our blizzard.

32
00:02:07,850 --> 00:02:09,380
So let's take an example.

33
00:02:09,530 --> 00:02:12,230
Let us try to understand with the help of an example.

34
00:02:12,880 --> 00:02:20,210
So suppose the given area is two, four, seven, eight, nine and 10.

35
00:02:21,020 --> 00:02:23,560
So the given area is already started.

36
00:02:24,600 --> 00:02:24,810
OK.

37
00:02:25,370 --> 00:02:27,110
This given area is already sorted.

38
00:02:27,140 --> 00:02:29,900
And let us implement bubbles out on it.

39
00:02:30,080 --> 00:02:30,500
So.

40
00:02:31,830 --> 00:02:34,270
Compared no slapping.

41
00:02:35,950 --> 00:02:36,240
Most.

42
00:02:37,760 --> 00:02:38,420
Compared.

43
00:02:39,200 --> 00:02:39,920
No slap.

44
00:02:42,140 --> 00:02:43,820
Compare no slap.

45
00:02:46,760 --> 00:02:48,140
Compare notes app.

46
00:02:50,510 --> 00:02:52,220
Compare no Sepp.

47
00:02:53,960 --> 00:03:00,650
That means if the given area is already sorted, then no swapping will take place.

48
00:03:00,760 --> 00:03:02,990
OK, so tapping will not be there.

49
00:03:03,600 --> 00:03:08,260
Swapping will not be there.

50
00:03:10,170 --> 00:03:12,360
OK, so we can use this property.

51
00:03:13,490 --> 00:03:14,660
OK, we will use it.

52
00:03:15,080 --> 00:03:22,550
We will use it that if the given array is already sorted, if the given Arizona sorted, then swapping

53
00:03:22,790 --> 00:03:24,350
will not be there.

54
00:03:24,860 --> 00:03:34,460
We will use this so that our sorted so that if they in part is already sorted, then bubble start big

55
00:03:34,730 --> 00:03:35,840
and steps.

56
00:03:38,420 --> 00:03:38,680
OK.

57
00:03:39,100 --> 00:03:40,210
So how we will do it?

58
00:03:41,410 --> 00:03:42,070
So let's see.

59
00:03:45,010 --> 00:03:47,710
So let's name this violence optimized verbal.

60
00:03:50,820 --> 00:03:58,380
Optimized mobile, mobile, art, Nazi P.P..

61
00:04:01,100 --> 00:04:02,140
So what I will do.

62
00:04:02,930 --> 00:04:05,140
So this was our all of it was hard.

63
00:04:05,330 --> 00:04:06,390
So we will keep it.

64
00:04:08,290 --> 00:04:09,880
And Pastor Ted.

65
00:04:11,770 --> 00:04:13,470
So what optimization we have to do?

66
00:04:15,480 --> 00:04:18,000
So this slapping, we have to optimize this.

67
00:04:18,060 --> 00:04:18,900
So what I will do?

68
00:04:19,890 --> 00:04:25,190
Let us take a variable and flag.

69
00:04:26,370 --> 00:04:29,820
So I'm taking a variable and flag, which is initially zero.

70
00:04:30,720 --> 00:04:30,990
OK.

71
00:04:31,620 --> 00:04:34,500
So I am taking our flag variable, which is initially zero.

72
00:04:34,920 --> 00:04:36,660
Now I will enter this loop.

73
00:04:37,860 --> 00:04:38,100
OK.

74
00:04:38,180 --> 00:04:46,460
So in this loop, so if there's swiping what I will do, I will change the value of a flag to one.

75
00:04:47,820 --> 00:04:55,380
OK, so that means if the input is unsorted, this condition will be true at least once, this condition

76
00:04:55,380 --> 00:04:55,990
will be true.

77
00:04:56,460 --> 00:04:58,530
And and these two lines will be executed.

78
00:04:59,430 --> 00:05:03,510
So when this for loop end, I will check the value of flag.

79
00:05:03,870 --> 00:05:09,720
So if flag is still zero, if flag is still zero.

80
00:05:10,110 --> 00:05:13,280
That means the arrays already started.

81
00:05:13,650 --> 00:05:15,390
So what you can do is break.

82
00:05:18,550 --> 00:05:22,150
So these two lanes, initially, my flag goes to zero.

83
00:05:22,510 --> 00:05:26,380
So if there is Sautter, this condition will always be false.

84
00:05:27,520 --> 00:05:27,790
OK.

85
00:05:28,130 --> 00:05:32,240
If that is a starter, this condition will always be false.

86
00:05:32,990 --> 00:05:36,650
Hence, these two lines will never be executed.

87
00:05:37,670 --> 00:05:39,500
And this for look will terminate.

88
00:05:39,800 --> 00:05:43,880
Then I am checking if the value of flag is still zero.

89
00:05:44,450 --> 00:05:46,430
That means you can right here.

90
00:05:47,090 --> 00:05:54,590
That means my error is error is already sorted.

91
00:05:56,120 --> 00:05:58,470
So what you should do is come out of the loop.

92
00:05:59,560 --> 00:05:59,810
OK.

93
00:06:00,230 --> 00:06:01,880
So come out.

94
00:06:02,690 --> 00:06:05,570
Come out of the loop.

95
00:06:06,330 --> 00:06:06,510
OK.

96
00:06:06,590 --> 00:06:08,390
So what this big showdown will do.

97
00:06:08,900 --> 00:06:11,600
So this brave statement will break this outlook.

98
00:06:12,170 --> 00:06:12,460
OK.

99
00:06:12,830 --> 00:06:15,260
So this was closing and this was opening.

100
00:06:15,590 --> 00:06:18,560
So this big statement will break this loop.

101
00:06:18,920 --> 00:06:20,110
I will come out of this loop.

102
00:06:20,630 --> 00:06:23,000
And this is where my function end.

103
00:06:23,590 --> 00:06:23,910
OK.

104
00:06:24,650 --> 00:06:26,120
So this is all that we have to do.

105
00:06:27,190 --> 00:06:29,320
Now, this is called Optimized Mobile SART.

106
00:06:30,840 --> 00:06:31,110
OK.

107
00:06:31,470 --> 00:06:34,380
It will take and the steps, vital big steps.

108
00:06:36,230 --> 00:06:38,090
So my flag is zero.

109
00:06:39,290 --> 00:06:42,260
So let's say that elements are one, two and three.

110
00:06:42,770 --> 00:06:44,180
So I will check GMG.

111
00:06:44,270 --> 00:06:45,560
Listen, compare.

112
00:06:46,070 --> 00:06:46,790
No slapping.

113
00:06:47,060 --> 00:06:47,630
Compare.

114
00:06:47,810 --> 00:06:48,520
No slapping.

115
00:06:48,920 --> 00:06:51,710
So I will reach at this lame flag is still zero.

116
00:06:52,040 --> 00:06:53,990
So flag is still zero.

117
00:06:54,290 --> 00:06:54,740
Break.

118
00:06:54,950 --> 00:06:55,970
Come out of this loop.

119
00:06:56,660 --> 00:06:57,740
Come out of this loop.

120
00:06:58,100 --> 00:06:59,960
So how many number of steps it took?

121
00:07:01,300 --> 00:07:07,550
As May a number of times as this loop is running, so this loop is running and times.

122
00:07:09,620 --> 00:07:09,820
OK.

123
00:07:09,880 --> 00:07:14,780
It is actually raining and minus two times or minus one times, but it doesn't matter.

124
00:07:15,810 --> 00:07:16,040
OK.

125
00:07:16,370 --> 00:07:18,560
These questions, one, two, three.

126
00:07:18,840 --> 00:07:19,610
There doesn't matter.

127
00:07:19,640 --> 00:07:21,510
We always report our answer in terms of.

128
00:07:21,560 --> 00:07:24,820
And so this loop is earning end times.

129
00:07:25,130 --> 00:07:29,360
So this optimised verbal sort will take and steps.

130
00:07:29,450 --> 00:07:30,980
If that is already sorted.

131
00:07:32,030 --> 00:07:32,240
OK.

132
00:07:32,330 --> 00:07:35,510
So the main logic was just to use a variable flag.

133
00:07:36,290 --> 00:07:39,050
If there's a stepping, that means that is unsorted.

134
00:07:40,170 --> 00:07:45,690
Let me say, there is unsorted and the value of flag will change, the value of flag will become one.

135
00:07:46,940 --> 00:07:48,600
And this condition will become false.

136
00:07:49,220 --> 00:07:50,990
So Blake will not be executed.

137
00:07:51,620 --> 00:07:53,810
OK, so this was the whole logic.

138
00:07:55,810 --> 00:07:56,050
OK.

139
00:07:56,370 --> 00:08:02,850
So if you have any doubt regarding the optimized bubble sort or regarding the Mozart art, you can ask

140
00:08:02,850 --> 00:08:03,790
me, OK.

141
00:08:03,870 --> 00:08:04,740
Feel free to ask.

142
00:08:05,100 --> 00:08:06,460
So this isn't for this video.

143
00:08:06,840 --> 00:08:07,400
Thank you.
