1
00:00:01,380 --> 00:00:02,009
Hi, everyone.

2
00:00:02,040 --> 00:00:05,990
So in the last videos, we discussed how we can use our own to make some priority.

3
00:00:06,630 --> 00:00:07,630
Now in this video.

4
00:00:07,650 --> 00:00:10,820
We will discuss how we can use our inbuilt minimum priority queue.

5
00:00:11,400 --> 00:00:14,340
So we will start using our built Menom prior to.

6
00:00:14,340 --> 00:00:20,510
Q So let's directly jump into court and let's see this index for creating our inbuilt minimum priority.

7
00:00:20,590 --> 00:00:29,090
Q So if I remember this is our old code, so this is actually maximum and if you in the output, if

8
00:00:29,100 --> 00:00:31,320
you will run this program, then what will be our output.

9
00:00:32,159 --> 00:00:36,450
So you can see the size of six and the topmost elements from six to seven.

10
00:00:36,450 --> 00:00:42,600
And then when we are getting each element one at a time, so the output is going to be in descending

11
00:00:42,600 --> 00:00:47,250
order first, the largest element will come, then the smaller one, then the smaller, smaller, smaller

12
00:00:47,250 --> 00:00:48,110
and the smallest.

13
00:00:48,690 --> 00:00:52,320
So our output is coming out and decreasing order because we are using maximum.

14
00:00:53,340 --> 00:00:55,630
Now let's see how we can create our minimum.

15
00:00:56,280 --> 00:00:58,530
So let's change its name to be good to.

16
00:01:00,720 --> 00:01:03,480
So now let's see this index, Susan, index is quite similar.

17
00:01:06,020 --> 00:01:12,920
So proud of you, I want to create a priority queue of integers, so integers, then you have to write.

18
00:01:14,130 --> 00:01:18,690
Retrophin digits, and then you have to rate greater.

19
00:01:20,130 --> 00:01:21,480
Indigence and.

20
00:01:22,560 --> 00:01:23,740
This is your beginning.

21
00:01:23,790 --> 00:01:29,700
So this is this index for creating minimum I know this index of minimum prior to kill is really weird,

22
00:01:30,000 --> 00:01:31,950
but we will not go into much detail.

23
00:01:32,250 --> 00:01:36,300
So we will just we will just remember this line that we have to use.

24
00:01:36,510 --> 00:01:39,890
We have to write the digits and then we have great, great advantages.

25
00:01:40,320 --> 00:01:44,410
So I will provide you note that what is the meaning of character?

26
00:01:45,210 --> 00:01:46,960
So this is the way for creating minimum.

27
00:01:47,670 --> 00:01:53,880
Now the name is Piku and I change its name to Picado, so I am pushing in priority queue.

28
00:01:54,180 --> 00:01:59,970
So the size is still six, but the topmost element is the smallest element and the smallest element

29
00:01:59,970 --> 00:02:00,900
is now one.

30
00:02:01,410 --> 00:02:07,920
So will come out first and I am wiping out the elements from the minimum priority queue Bittu.

31
00:02:08,280 --> 00:02:11,009
So this time our elements will come out and sorted.

32
00:02:11,050 --> 00:02:12,050
Amended, correct.

33
00:02:12,450 --> 00:02:14,730
So now let's try to test our called.

34
00:02:17,270 --> 00:02:24,170
So you can see this is the size is going to be some other topmost element is the smallest element and

35
00:02:24,170 --> 00:02:28,040
other elements are coming out and sorted because we are using minimum.

36
00:02:28,370 --> 00:02:32,590
So the minimum element will come out first, then the next element will come out first.

37
00:02:32,600 --> 00:02:35,970
And in this way, at the last, we have the largest element.

38
00:02:36,860 --> 00:02:38,990
So now we know how to create minimum.

39
00:02:40,070 --> 00:02:41,930
So let's just solve one more question.

40
00:02:42,380 --> 00:02:47,750
So if you remember the last question, so our last question was to find the smallest element.

41
00:02:48,680 --> 00:02:52,910
So the last question we did was to find the smallest element.

42
00:02:54,210 --> 00:02:58,660
Now, can we use minimum priority queue to find out the smallest elements?

43
00:02:59,190 --> 00:03:01,610
So what I will do, the logic is very simple.

44
00:03:02,370 --> 00:03:05,760
I will push every element inside the minimum priority queue.

45
00:03:06,090 --> 00:03:07,610
So these are my total elements.

46
00:03:08,580 --> 00:03:10,440
So create a minimum priority queue.

47
00:03:11,600 --> 00:03:18,770
And push every single element inside your priority queue, so five, then six, then nine, then 12,

48
00:03:18,780 --> 00:03:21,260
then three, then 13 and then to.

49
00:03:22,380 --> 00:03:25,230
What do I want, I want the smallest elements.

50
00:03:25,620 --> 00:03:27,810
So what I will do, I will call pop function.

51
00:03:29,180 --> 00:03:29,810
Three times.

52
00:03:31,910 --> 00:03:39,020
Basically, top and bottom, top end pub function combination, so find out the top most elements of

53
00:03:39,020 --> 00:03:44,540
the topmost element is to sort of come out first and then pop the element of pop to then.

54
00:03:44,890 --> 00:03:48,170
So I have to call three times now, the second time, Bob, the smallest element.

55
00:03:48,440 --> 00:03:49,730
So three will come out first.

56
00:03:49,970 --> 00:03:50,610
And Bob.

57
00:03:50,720 --> 00:03:52,430
So he's getting Bob now.

58
00:03:52,430 --> 00:03:56,090
I will pop out five because five with the smallest element and five will be here.

59
00:03:56,420 --> 00:03:58,550
And then I have to do three times.

60
00:03:58,550 --> 00:03:59,330
So I will stop.

61
00:03:59,330 --> 00:04:00,320
And this is my game.

62
00:04:00,340 --> 00:04:01,140
Smallest element.

63
00:04:02,120 --> 00:04:08,630
Now if you will use medium priority queue, then your time complexities, same as and Logan just like

64
00:04:08,630 --> 00:04:15,640
this one, because ultimately what you are doing the size of your minimum priority is going to be when

65
00:04:16,240 --> 00:04:18,260
at first you have to insert any elements.

66
00:04:18,560 --> 00:04:23,930
So for inserting an elements, the time complexity will become analogue and then you will run the loop

67
00:04:24,140 --> 00:04:24,560
times.

68
00:04:25,940 --> 00:04:28,120
Basically you will call the append function.

69
00:04:28,130 --> 00:04:29,450
So this will become Kellogg.

70
00:04:29,450 --> 00:04:34,940
And so this will be the time complexity, if you will, use the minimum priority for solving this question.

71
00:04:37,230 --> 00:04:38,700
So let's take one more example.

72
00:04:39,150 --> 00:04:40,470
So what I'm saying is.

73
00:04:42,840 --> 00:04:49,560
So let's take this one example, it five 12, 10 zero one six nine, and the value of it is actually

74
00:04:49,740 --> 00:04:50,190
for.

75
00:04:52,100 --> 00:04:56,650
So that you can understand how we can use minimum priority code was all above question.

76
00:04:57,290 --> 00:04:58,900
So my Ed is very simple.

77
00:04:58,910 --> 00:05:00,890
This is eight, then five then.

78
00:05:00,980 --> 00:05:04,060
Well, then let's say 10, then let's say zero.

79
00:05:04,460 --> 00:05:05,270
Then let's say one.

80
00:05:05,270 --> 00:05:06,520
Then let's say six and nine.

81
00:05:06,830 --> 00:05:08,310
And what is the value of K?

82
00:05:08,360 --> 00:05:09,560
So the value of Gaisford.

83
00:05:09,740 --> 00:05:10,190
Correct.

84
00:05:11,000 --> 00:05:11,980
Now this is already.

85
00:05:12,770 --> 00:05:14,860
So what I will do, I will iterate over this.

86
00:05:16,010 --> 00:05:17,480
This is my minimum priority queue.

87
00:05:18,740 --> 00:05:23,930
I will agree or disagree and I will push every element inside my priority queue.

88
00:05:24,470 --> 00:05:24,920
Correct.

89
00:05:25,130 --> 00:05:28,240
So all these elements will be pushed inside my priority.

90
00:05:28,730 --> 00:05:29,770
So let's change the name.

91
00:05:29,780 --> 00:05:30,960
So this is my priority.

92
00:05:30,980 --> 00:05:31,850
You correct.

93
00:05:33,010 --> 00:05:34,300
Now, what I will do, I will.

94
00:05:35,430 --> 00:05:40,300
Run the loop four times and I will call the function top and then I will call the function pop.

95
00:05:40,950 --> 00:05:44,690
So this is priority queue, so the minimum element will come out first.

96
00:05:44,700 --> 00:05:45,980
So zero is the minimum element.

97
00:05:46,140 --> 00:05:48,250
So top pop zero.

98
00:05:48,600 --> 00:05:50,010
Now, when is the minimum element?

99
00:05:50,190 --> 00:05:51,240
Pop and pop?

100
00:05:52,440 --> 00:05:57,350
What is the minimum now, five, stop and pop, what is the minimum element now?

101
00:05:57,390 --> 00:06:01,100
I think it is six sort of benchtop and now I will stop.

102
00:06:01,110 --> 00:06:02,080
So this is my answer.

103
00:06:02,100 --> 00:06:03,330
Zero one five six.

104
00:06:04,720 --> 00:06:10,690
Correct, so I can use medium priority queue and the complexities of first, we have to insert all the

105
00:06:10,690 --> 00:06:11,860
elements into the priority queue.

106
00:06:12,220 --> 00:06:14,310
So time, complexity, there are an element.

107
00:06:14,370 --> 00:06:22,240
So when loop so and login and then we have to pop out key elements so key and the to produce login so

108
00:06:22,240 --> 00:06:24,220
caillaux and login plus login.

109
00:06:24,640 --> 00:06:25,060
Correct.

110
00:06:25,060 --> 00:06:31,300
And the space is going to be big off and because the protocol will contain N elements.

111
00:06:31,670 --> 00:06:36,970
So obviously the maximum practical approach for solving this question was the best approach.

112
00:06:37,990 --> 00:06:44,350
And this approach is not even better than discarding one, so starting approach was better than this

113
00:06:44,350 --> 00:06:46,340
one, starting was better.

114
00:06:46,990 --> 00:06:53,380
So but we are not discussing about time, complexity, and we are just trying to use in particular,

115
00:06:53,380 --> 00:06:56,650
we're just trying to learn how we can use inbuilt protection.

116
00:06:57,250 --> 00:06:58,540
So let's write the code.

117
00:07:02,760 --> 00:07:04,980
So this was the call for the smallest element.

118
00:07:05,010 --> 00:07:07,800
Now, what I want to do, I will create a minimum priority.

119
00:07:08,610 --> 00:07:10,380
So let's just come in and out everything.

120
00:07:11,460 --> 00:07:14,580
OK, so let's get one more function.

121
00:07:15,690 --> 00:07:17,250
So wait, so let's namer to.

122
00:07:22,680 --> 00:07:31,260
So guess my list again, it will take it is and but it will take the size and it will take a very bulky.

123
00:07:35,380 --> 00:07:39,850
Then they have to do so, we have to create a minimum priority, given the syntax, basically you have

124
00:07:39,850 --> 00:07:40,930
to remember this index.

125
00:07:42,240 --> 00:07:45,300
So proud of indigence, then you have to read.

126
00:07:46,230 --> 00:07:53,760
Vector of integers, then you have to rate greater of integers and please, there's no need to go in

127
00:07:53,760 --> 00:07:57,230
detail, you just remember that this is how we create I impractical.

128
00:07:58,080 --> 00:08:00,750
So this is a minimum heap, correct.

129
00:08:00,780 --> 00:08:02,400
Now, the approach is very simple.

130
00:08:02,920 --> 00:08:05,580
Push every element inside your main priority queue.

131
00:08:06,000 --> 00:08:07,350
So I equals zero.

132
00:08:08,970 --> 00:08:16,340
Equals zero, i.e. less than a plus plus they're going to push every single element, every single element

133
00:08:16,340 --> 00:08:22,150
into my priority given to Alfy, I am pushing every element and then I will pop out key elements.

134
00:08:22,700 --> 00:08:26,060
So pop key elements and these key elements.

135
00:08:27,280 --> 00:08:30,670
Will be the smallest elements because this is minimum hip.

136
00:08:31,680 --> 00:08:33,870
So I have to run the loop times, so.

137
00:08:35,110 --> 00:08:40,090
I equals one I less than what equals gay and I placeless.

138
00:08:42,549 --> 00:08:45,460
Scout, Bacolod Top.

139
00:08:48,830 --> 00:08:50,060
And Bechard artpop.

140
00:08:53,000 --> 00:08:59,340
And we know the output is going out before this area is five Trenta, but the output will come out unsorted,

141
00:08:59,650 --> 00:09:02,270
so the output will be two, three and five, correct?

142
00:09:08,130 --> 00:09:08,820
So you can see.

143
00:09:09,950 --> 00:09:14,900
Earlier, I was using Makhzoumi, so my output was just the reverse of this five, three and two, but

144
00:09:14,900 --> 00:09:18,140
here I am using minimum heap, so the output is two, three and five.

145
00:09:18,410 --> 00:09:22,440
So two, three and five at the three smallest element present in this given area.

146
00:09:23,090 --> 00:09:26,120
So that's how we can use minimum hyp.

147
00:09:28,260 --> 00:09:34,980
So I think I have discussed the time, complexity, all sorts of decisions and log in and this is key

148
00:09:34,990 --> 00:09:36,690
log and correct.

149
00:09:38,370 --> 00:09:40,920
Now, this question was to find.

150
00:09:42,240 --> 00:09:49,650
So this question was to find the smallest element, so let's say the maximum priority queue was giving

151
00:09:49,650 --> 00:09:51,930
me the best time in space complexity.

152
00:09:52,200 --> 00:09:54,930
Now, if the question is to find the just element.

153
00:09:56,560 --> 00:10:03,850
If the question is to find the killer element, so it is very obvious that the minimum help will give

154
00:10:03,850 --> 00:10:07,810
me the maximum, the minimum, it will give me the best time and space complexity.

155
00:10:08,740 --> 00:10:11,070
I am repeating myself in this question.

156
00:10:11,080 --> 00:10:12,910
We have to find the smallest element.

157
00:10:13,150 --> 00:10:17,620
So that's why the employer was giving me the best approach, because I will maintain the size.

158
00:10:17,980 --> 00:10:18,910
The size will be key.

159
00:10:19,360 --> 00:10:22,600
If the question is this one, then I will lose my employer.

160
00:10:22,730 --> 00:10:25,540
You and I will maintain the size of an employer to Kyuki.

161
00:10:27,160 --> 00:10:32,860
Now in this question also, so, for example, the question is just if we want to use Mixin prior to

162
00:10:32,860 --> 00:10:34,690
you, you can definitely use what you will do.

163
00:10:34,960 --> 00:10:36,700
You will push every single element.

164
00:10:37,570 --> 00:10:42,220
So you will push every single element inside your priority queue.

165
00:10:42,340 --> 00:10:49,860
So time, complexity and Logan and then what you have to do so we won't get so I will pop out key elements.

166
00:10:49,870 --> 00:10:52,090
So these key elements will be the largest element.

167
00:10:52,090 --> 00:10:54,220
So Kellogg, Kellogg and.

168
00:10:55,520 --> 00:11:00,350
Simple so in this question, if you will choose to make simpler, to do everything will just become

169
00:11:00,350 --> 00:11:00,810
a perceived.

170
00:11:01,790 --> 00:11:07,970
So simpler to dismiss time, complexity and I mean practical will give me and longer time complexity.

171
00:11:09,600 --> 00:11:16,260
Now, there is one more way to insert elements into your priority queue, so first tell me, how much

172
00:11:16,260 --> 00:11:17,940
is the time complexity for this call?

173
00:11:18,810 --> 00:11:22,320
What I am doing so I am creating a minimum priority queue.

174
00:11:23,960 --> 00:11:30,490
And then I am reading over the air and I am inserting elements into my priority given by one element

175
00:11:30,500 --> 00:11:33,170
of time, complexities of time, complexities and Logan.

176
00:11:34,760 --> 00:11:39,900
Just remember, this time, complexities and Logan, now there is one more way to insert elements into

177
00:11:39,900 --> 00:11:40,700
your priority queue.

178
00:11:42,290 --> 00:11:47,600
So instead of writing, so let's copy this one now, I just need the first line.

179
00:11:56,250 --> 00:12:01,230
So the above code was inserting the elements time, complexity was analog and.

180
00:12:02,530 --> 00:12:04,930
Now, if you will insert the element in this, we.

181
00:12:07,420 --> 00:12:08,980
Acoma, Apison.

182
00:12:11,720 --> 00:12:15,170
So now the time complexities go off and.

183
00:12:19,210 --> 00:12:22,270
Maritime complex, it is big often, so let's test our record.

184
00:12:24,260 --> 00:12:27,080
So, see, our report is correct, two, three and five.

185
00:12:28,580 --> 00:12:29,930
Our goal is working fine.

186
00:12:33,700 --> 00:12:39,280
So if you will insert the elements in this way, one by one, I'm inserting the elements one by one.

187
00:12:39,550 --> 00:12:42,040
So there are time complexities going to be and Logan.

188
00:12:43,930 --> 00:12:46,490
So what is the difference between this method and this matter?

189
00:12:46,510 --> 00:12:52,560
The workers say they are just inserting the elements inside your priority queue, but what is the difference?

190
00:12:52,960 --> 00:12:56,970
So in this approach, what we are doing, we are taking elements one by one.

191
00:12:57,340 --> 00:12:59,260
Elements are coming one by one.

192
00:13:00,280 --> 00:13:06,520
But in this way, what we did, we provided just Holyday Edwards, we provided all the elements at once,

193
00:13:06,790 --> 00:13:08,950
so that's why the time complexity decreases.

194
00:13:08,950 --> 00:13:14,530
So here the time complexities Magoffin and the time, complexities and Log-in similarly.

195
00:13:14,530 --> 00:13:20,140
If so, if you want to insert vector, for example, instead of ETTY, if we're using vectors of what

196
00:13:20,140 --> 00:13:22,240
we will write, we will write vector dot begin.

197
00:13:23,090 --> 00:13:27,190
Basically, we have to give the first and the last address to begin and end.

198
00:13:29,580 --> 00:13:36,030
Instead of writing a plans and just like in these sorting function, sort my person or you can write

199
00:13:36,050 --> 00:13:39,540
Saat we begin Victor not we begin my view.

200
00:13:40,380 --> 00:13:45,410
So there is no need to go into much detail by the time complexities is often probably.

201
00:13:45,450 --> 00:13:50,250
I will just create one video to explain to you by the time complexities big.

202
00:13:50,530 --> 00:13:57,650
And so for now you can just remember that if you look at it prior to you using this matter, perhaps

203
00:13:57,660 --> 00:14:03,390
the whole idea was then the time complexity for inserting the elements as big often and then wasted

204
00:14:03,390 --> 00:14:04,230
time complexity.

205
00:14:04,230 --> 00:14:09,060
If the elements are coming one by one, then the then your time complexities and log-in.

206
00:14:10,470 --> 00:14:12,420
So just remember this time complexity.

207
00:14:12,420 --> 00:14:16,110
I will just probably create one more video explaining why it is so.

208
00:14:18,360 --> 00:14:21,860
OK, so this is how you can use minimum priority.

209
00:14:21,910 --> 00:14:23,730
You just remember this index.

210
00:14:25,430 --> 00:14:26,540
Everything will work fine.

211
00:14:27,460 --> 00:14:29,090
So what is this trained teacher?

212
00:14:29,120 --> 00:14:36,340
So what I will do, I will upload some notes and you can at those notes, but frankly telling you there's

213
00:14:36,340 --> 00:14:38,700
no need to go into detail why this is so.

214
00:14:39,040 --> 00:14:41,090
Just remember the syntax and do the work.

215
00:14:41,110 --> 00:14:41,830
Nothing much.

216
00:14:43,050 --> 00:14:45,010
So I will see you in the next one by.

