1
00:00:01,560 --> 00:00:02,310
Hi, everyone.

2
00:00:02,340 --> 00:00:08,170
So in the last video we implemented, these three functions get the minimum is empty and to function.

3
00:00:08,430 --> 00:00:11,430
So in this video, we will focus on insert function.

4
00:00:11,470 --> 00:00:16,030
We will try to write the code for insert function so how we can insert elements.

5
00:00:16,190 --> 00:00:17,280
Let us take an example.

6
00:00:17,290 --> 00:00:24,120
So suppose you have this minimum heap and these are the values.

7
00:00:25,140 --> 00:00:30,810
Now, suppose you want to insert an element what you will lose or you will call a function insert and

8
00:00:30,810 --> 00:00:31,820
you will pass the value.

9
00:00:31,830 --> 00:00:33,620
For example, you want to insert tool.

10
00:00:34,350 --> 00:00:36,870
So 12 will be inserted at this position.

11
00:00:38,270 --> 00:00:42,440
So let us socialize it, let us feel the values in our area.

12
00:00:42,860 --> 00:00:45,220
So this is my priority character.

13
00:00:45,710 --> 00:00:52,260
So this 10, 50, then 20, then 60, then under and then 25.

14
00:00:52,490 --> 00:00:53,330
So what will happen?

15
00:00:53,330 --> 00:00:55,330
12 will be inserted at the last point.

16
00:00:55,370 --> 00:00:58,550
So this is zero one, two, three, four, five and six.

17
00:00:58,970 --> 00:01:01,210
So 12 will be inserted at the next six.

18
00:01:01,700 --> 00:01:02,960
So let's do that first.

19
00:01:04,310 --> 00:01:05,410
So I'm using Vector.

20
00:01:05,720 --> 00:01:07,670
So first let us include Vector also.

21
00:01:16,330 --> 00:01:19,610
So I want to create a function inside so the return will be void.

22
00:01:19,630 --> 00:01:20,830
I will not done anything.

23
00:01:21,490 --> 00:01:26,260
Now this and third function will take integer as input, the element that we have to insert.

24
00:01:28,530 --> 00:01:33,900
And what we have to do so we have to ensure that the last element at the last minute, we have to ensure

25
00:01:33,900 --> 00:01:36,990
that Elastin Nixa wavefunction be accurate, pushed back.

26
00:01:37,620 --> 00:01:40,110
So this push back function is in brain function of.

27
00:01:41,930 --> 00:01:48,550
Our Victor and I have inserted the element now after inserting the element of a CBT property is correct,

28
00:01:49,110 --> 00:01:55,260
so it is complete by Nutri, so CBT is correct, but he property is invalid.

29
00:01:55,280 --> 00:01:57,320
He bought the property is not satisfied.

30
00:02:00,750 --> 00:02:07,620
So as you can see, so Glenn is actually less than 20, so what we have to do, so these are the indexes

31
00:02:07,620 --> 00:02:11,220
zero one, two, three, four, five and six.

32
00:02:11,650 --> 00:02:16,260
So instead of this writing every time, you can write indexes here also.

33
00:02:17,220 --> 00:02:18,700
So what does my child index?

34
00:02:18,720 --> 00:02:19,820
So this is in Mexico.

35
00:02:20,250 --> 00:02:21,990
So in the last video, we discussed that.

36
00:02:23,310 --> 00:02:30,150
If parent index is a, then it's left children nexus to opalescent and it's Rachell Index is actually

37
00:02:30,150 --> 00:02:30,700
duopolies.

38
00:02:31,260 --> 00:02:33,960
And if you want to go back towards your parent index.

39
00:02:34,560 --> 00:02:36,560
So in order to find out pend index.

40
00:02:36,570 --> 00:02:37,620
So this is very simple.

41
00:02:38,310 --> 00:02:43,140
Giler index minus one by two and you will be able to find out the apparent index.

42
00:02:43,170 --> 00:02:43,970
So what we have to do.

43
00:02:44,490 --> 00:02:46,950
So my child index is six.

44
00:02:46,950 --> 00:02:52,510
So this is index and what is my band index to parent index is to you can apply this formula.

45
00:02:52,510 --> 00:02:58,680
So six minus one battle band index is to then they have to do you will compare the values you will compare

46
00:02:58,680 --> 00:03:01,110
to you will compare twenty with twelve.

47
00:03:01,500 --> 00:03:03,210
So twelve is less than 20 then.

48
00:03:03,630 --> 00:03:04,830
Do you have to do something.

49
00:03:06,310 --> 00:03:10,620
So will come here and they will come here, so we have to do something.

50
00:03:11,070 --> 00:03:12,450
So what is the challenge?

51
00:03:12,630 --> 00:03:15,650
First of all, we need to find out child index.

52
00:03:15,780 --> 00:03:19,020
So child index is actually the last element you can see.

53
00:03:20,490 --> 00:03:24,150
So the last element reinserted and how we can find out.

54
00:03:24,450 --> 00:03:26,450
So basically there are total seven elements.

55
00:03:26,820 --> 00:03:30,870
So Picador says that will give me seven minus one six.

56
00:03:31,140 --> 00:03:35,820
So Picador ties total number of elements, minus one.

57
00:03:35,820 --> 00:03:36,930
I will be able to find out.

58
00:03:38,220 --> 00:03:39,230
I will be able to find out.

59
00:03:39,270 --> 00:03:45,600
Drylands so beginner size again sizes and build function of vector and minus one.

60
00:03:46,110 --> 00:03:49,010
So in this way, I will be able to find out my challenge next.

61
00:03:49,050 --> 00:03:49,980
Now what we have to do.

62
00:03:50,730 --> 00:03:52,480
So I have to find out beyond the next.

63
00:03:52,500 --> 00:03:53,940
So what is next?

64
00:03:54,060 --> 00:03:55,660
Again, this is a very simple formula.

65
00:03:55,680 --> 00:03:56,940
We have discussed many times.

66
00:03:57,570 --> 00:03:59,610
So this is child X minus one.

67
00:04:01,280 --> 00:04:08,900
By two to now we know better next and next, so we are doing all this work because our property is not

68
00:04:08,900 --> 00:04:09,560
satisfied.

69
00:04:10,660 --> 00:04:16,480
CBT properly certified, but he probably is not satisfied, you can see, so we are doing all this work

70
00:04:16,480 --> 00:04:19,420
so that our property becomes satisfied.

71
00:04:20,540 --> 00:04:28,540
So I'm writing here he probably not satisfied CBT properly certified, so Sebelius heap not, then why

72
00:04:28,550 --> 00:04:29,150
do they have to do so?

73
00:04:29,160 --> 00:04:30,510
I have to compare those values.

74
00:04:31,190 --> 00:04:34,580
So if basically the child value.

75
00:04:35,550 --> 00:04:37,300
It's less than parenteral.

76
00:04:42,190 --> 00:04:45,400
So if the child values less than parent value, so see this example?

77
00:04:46,970 --> 00:04:53,480
So 12, 12 was actually less than 20, so if the child value is less than the parent value, then you

78
00:04:53,480 --> 00:04:54,420
have to do something.

79
00:04:54,740 --> 00:04:55,910
So let's do shopping.

80
00:04:56,450 --> 00:05:00,320
So we have inbuilt function SREP and we can pass these values.

81
00:05:02,960 --> 00:05:04,160
Charlie Index and.

82
00:05:10,770 --> 00:05:11,610
Parent Alex.

83
00:05:13,270 --> 00:05:14,830
So we have done this weapon once.

84
00:05:16,810 --> 00:05:17,760
So what is the scenario?

85
00:05:17,770 --> 00:05:25,640
So this tunnel and it's been 20, so they are now well presented and 20 is presented.

86
00:05:26,290 --> 00:05:28,240
So we should stop at this point or not.

87
00:05:29,320 --> 00:05:33,780
So we should not stop at this point because now we have to compare well with 10.

88
00:05:34,330 --> 00:05:35,900
So what is the index of to allow.

89
00:05:35,920 --> 00:05:37,180
So it is basically.

90
00:05:38,630 --> 00:05:46,430
Our new challenge is to know you can see the index of 12 is actually two, so this is my new index again.

91
00:05:46,430 --> 00:05:48,880
I will find out my pain index, which is zero.

92
00:05:49,520 --> 00:05:50,750
I will apply this formula.

93
00:05:51,080 --> 00:05:54,220
So the index is two to minus one by two.

94
00:05:54,470 --> 00:05:55,840
So it all came out to be zero.

95
00:05:55,940 --> 00:05:57,280
So bad index is zero.

96
00:05:57,290 --> 00:05:58,320
Then I will compare.

97
00:05:58,460 --> 00:06:05,450
Well, and then so I have to compare well and then again and so they can be one more scenario.

98
00:06:06,290 --> 00:06:07,480
Let us take one example.

99
00:06:07,880 --> 00:06:10,940
So suppose instead of two I want to push zero.

100
00:06:11,940 --> 00:06:13,190
So let me take one example.

101
00:06:13,190 --> 00:06:21,530
So I have this little 10, then 20 or 200, then let's say 30 or so and let's say I have 50 here.

102
00:06:22,880 --> 00:06:23,870
Let's say 150.

103
00:06:25,210 --> 00:06:29,980
And these are indexes zero, one, two, three, four and five.

104
00:06:30,460 --> 00:06:32,320
Now I want to insert an element.

105
00:06:32,650 --> 00:06:34,120
Let's say I want to insert zero.

106
00:06:35,600 --> 00:06:38,670
So I want to do a certain element and also the indexes.

107
00:06:39,320 --> 00:06:41,810
So what I will do so this is my child index.

108
00:06:41,810 --> 00:06:43,340
This is my index.

109
00:06:46,030 --> 00:06:51,340
So compare, so general index is six and recipient index.

110
00:06:51,370 --> 00:06:52,910
So, again, apply the formula.

111
00:06:53,410 --> 00:06:55,830
So this is six minus one two.

112
00:06:56,110 --> 00:06:57,440
So it will come out to be two.

113
00:06:57,580 --> 00:06:58,210
You can see.

114
00:06:59,860 --> 00:07:01,060
So again, now compare.

115
00:07:01,100 --> 00:07:04,210
So compare zero and hundred, so zero is smaller, so I will slap.

116
00:07:07,550 --> 00:07:15,800
So after stepping what will happen, the new index of zero is to show the new index of zero is to now

117
00:07:15,800 --> 00:07:18,020
we will again find out its index.

118
00:07:18,020 --> 00:07:19,410
So its index is zero.

119
00:07:19,730 --> 00:07:23,910
So apply the formula to minus one vital sorbent index in zero.

120
00:07:24,350 --> 00:07:28,160
So this is zero period index now comparing.

121
00:07:28,170 --> 00:07:29,890
So zero is actually less than 10.

122
00:07:29,900 --> 00:07:31,290
So you will have to snap again.

123
00:07:31,820 --> 00:07:33,210
So I will again do something.

124
00:07:33,680 --> 00:07:34,850
So this is actually 10.

125
00:07:35,990 --> 00:07:37,400
And this will become zero.

126
00:07:38,430 --> 00:07:41,770
So again, now this zero has an extra.

127
00:07:41,820 --> 00:07:46,480
So, again, this zero will come here and spend the next.

128
00:07:46,500 --> 00:07:49,350
So basically zero is our topmost element.

129
00:07:49,380 --> 00:07:51,480
This is the smallest index.

130
00:07:54,930 --> 00:08:00,390
And we will stop, so at this point, there is no element to compare with, so whenever the child index

131
00:08:00,540 --> 00:08:02,700
will become zero, I will stop.

132
00:08:03,930 --> 00:08:06,100
When the index will become zero, I will stop.

133
00:08:06,120 --> 00:08:11,260
So this is the first stop in coalition and the second stopping nation is actually this one.

134
00:08:12,210 --> 00:08:17,320
So here, if you will, compared to oil and then so actually ten is less than 12.

135
00:08:17,670 --> 00:08:19,320
So you do not have to do something.

136
00:08:19,800 --> 00:08:22,060
So this is my second stopping criteria.

137
00:08:22,440 --> 00:08:28,450
So if the index is good, then index values good, then index value in this case.

138
00:08:28,740 --> 00:08:29,550
So this is 12.

139
00:08:29,790 --> 00:08:31,950
So 12 is actually good than 10.

140
00:08:32,309 --> 00:08:33,299
So you can stop.

141
00:08:34,390 --> 00:08:36,730
So we have to stop in great ideas first.

142
00:08:37,900 --> 00:08:43,030
I will reach at the topmost element, root element, and second, if the child value becomes bigger

143
00:08:43,030 --> 00:08:48,100
than the parent value, so we are doing all this work to satisfy our property.

144
00:08:49,700 --> 00:08:55,490
We are doing all this work to satisfy our property, our complete binary tree property has already been

145
00:08:55,490 --> 00:08:56,120
satisfied.

146
00:08:56,840 --> 00:08:57,400
Simple.

147
00:08:57,770 --> 00:08:58,910
So let's do this.

148
00:09:02,190 --> 00:09:04,140
So we have to do this work repeatedly.

149
00:09:06,310 --> 00:09:11,590
But they have to do so for us to stop criteria's so vile child index.

150
00:09:13,100 --> 00:09:14,090
Is a good zero.

151
00:09:31,780 --> 00:09:34,990
So I am finding out the challenge index, so while juggling decks is good.

152
00:09:35,440 --> 00:09:38,600
Find out the parent index, compare those two values.

153
00:09:38,620 --> 00:09:47,200
So if the value is smaller, you can swipe and your next index now your child index will become parent

154
00:09:47,200 --> 00:09:47,620
index.

155
00:09:48,580 --> 00:09:52,940
In the part, what you can do, you can break so there's no need to continue.

156
00:09:53,560 --> 00:09:54,880
You can simply break.

157
00:09:57,290 --> 00:10:00,190
So I think this court should work fine, so let us take an example.

158
00:10:03,400 --> 00:10:12,220
So let's say this is my hip then then it's a 20, so I have to here and then let's say I have 40, 50

159
00:10:12,220 --> 00:10:13,050
and 60.

160
00:10:14,050 --> 00:10:15,280
So this is my hip.

161
00:10:15,640 --> 00:10:17,740
And now I want to insert an element.

162
00:10:17,740 --> 00:10:19,480
Let's say I want to insert 25.

163
00:10:20,800 --> 00:10:26,390
So these are my indexes, zero, one, two, three, four and five.

164
00:10:26,590 --> 00:10:28,720
So if you want what you can do, so you can.

165
00:10:29,790 --> 00:10:33,150
Create a vector and you can push and you can write all these elements here.

166
00:10:38,100 --> 00:10:44,700
But writing a indexes on the values, so this is a much shorter way to explain things, so I want to

167
00:10:44,700 --> 00:10:48,060
insert an element, 25 to 25 will be decided at this position.

168
00:10:49,060 --> 00:10:50,500
At Index six.

169
00:10:51,740 --> 00:10:58,630
So what is my child index so big your size sizes seven, so there are seven elements minus one, so

170
00:10:58,700 --> 00:11:00,190
jelly index is actually six.

171
00:11:00,350 --> 00:11:02,400
This one, the child index is six.

172
00:11:03,020 --> 00:11:05,760
Now wait till next is good than zero six zero zero.

173
00:11:05,780 --> 00:11:07,130
Find out the parent index.

174
00:11:07,370 --> 00:11:09,970
So parent index is actually do so.

175
00:11:09,980 --> 00:11:12,920
Parent Index is two now compares.

176
00:11:12,920 --> 00:11:16,520
A child's index is less than an index of 25 is less than 30 years.

177
00:11:17,090 --> 00:11:19,070
Do the shopping part then.

178
00:11:20,480 --> 00:11:26,780
I will come here and they will come here, so self-deception, so the new child index is actually parent

179
00:11:26,780 --> 00:11:27,200
index.

180
00:11:27,210 --> 00:11:28,380
So what is the index?

181
00:11:28,400 --> 00:11:28,760
It is.

182
00:11:29,330 --> 00:11:33,500
So, yes, the new index is two and then we will go above.

183
00:11:33,710 --> 00:11:35,390
So child index is actually two.

184
00:11:35,390 --> 00:11:37,050
So two is bigger than zero.

185
00:11:37,070 --> 00:11:38,270
Yes, it is true.

186
00:11:38,810 --> 00:11:43,100
Then we will do so if I now depend inexpedient indexes zero.

187
00:11:43,490 --> 00:11:47,000
Then compare child value with different values or 25.

188
00:11:47,020 --> 00:11:48,120
That is actually good.

189
00:11:48,120 --> 00:11:48,610
Then 10.

190
00:11:49,070 --> 00:11:50,720
Now we will reach the l'esprit.

191
00:11:51,660 --> 00:11:53,810
Twenty five is basically guerdon ten.

192
00:11:54,170 --> 00:11:59,810
So I will reach the Elzbieta and I will break so I will come out of the slope and twenty five has been

193
00:11:59,810 --> 00:12:00,410
inserted.

194
00:12:00,800 --> 00:12:02,390
And in this area if you can see.

195
00:12:02,630 --> 00:12:03,530
So this 30.

196
00:12:04,930 --> 00:12:10,140
And I inserted 25 that are gender and wife has been stabbed, so 25 is had Antabuse here.

197
00:12:10,900 --> 00:12:12,280
So that is how this is working.

198
00:12:14,950 --> 00:12:18,760
Now, let's take one more example to understand this question to never.

199
00:12:19,630 --> 00:12:21,610
So this time, let's take this example.

200
00:12:21,620 --> 00:12:28,480
So when there are three, then let's say I have four, then five, and then we lose six.

201
00:12:28,970 --> 00:12:30,910
So these are the indexes of the vector.

202
00:12:30,910 --> 00:12:35,030
So zero, one, two, three, four and five.

203
00:12:35,620 --> 00:12:40,480
Now I want to insert an element zero or let's say I want to insert an element minus one.

204
00:12:41,140 --> 00:12:46,810
So what happens minus one will be inserted at this position and its index is six.

205
00:12:47,050 --> 00:12:47,620
Simple.

206
00:12:48,910 --> 00:12:49,590
So what do we do?

207
00:12:49,600 --> 00:12:53,830
So Child Next came out to be six Viljoen, next is a good than zero.

208
00:12:53,990 --> 00:12:55,580
Six is actually greater than zero.

209
00:12:55,870 --> 00:13:01,510
Find out the next two parent indexes to then compare the child value with the parent value.

210
00:13:01,510 --> 00:13:03,330
So minus one is less than three.

211
00:13:03,520 --> 00:13:05,610
You will do something so trivial.

212
00:13:05,620 --> 00:13:08,340
Come here and my next one will come here.

213
00:13:08,620 --> 00:13:10,660
Then you are updating your child index.

214
00:13:10,660 --> 00:13:12,040
So which is parent index.

215
00:13:12,400 --> 00:13:16,570
Parent index was two, so the index of minus one is actually two now.

216
00:13:17,290 --> 00:13:25,900
So again, Gile index is two, so you will find no dependent expert index will came out to be zero again.

217
00:13:25,900 --> 00:13:29,260
You will do the comparison to compare minus one and one.

218
00:13:29,470 --> 00:13:31,990
So minus one is smaller, you will lose something.

219
00:13:32,200 --> 00:13:35,200
So minus one will come here and one will come here.

220
00:13:36,200 --> 00:13:41,600
Then you will upgrade your child index with the pandemic Sabella index next zero, you can see behind

221
00:13:41,640 --> 00:13:42,430
the next zero.

222
00:13:42,830 --> 00:13:45,300
So your child index now becomes a zero.

223
00:13:45,560 --> 00:13:48,410
Again, you will go at the top and this time this condition.

224
00:13:48,410 --> 00:13:56,000
So the condition inside develop will become false because the child index is zero now, and that's how

225
00:13:56,000 --> 00:13:59,870
we will be able to insert minus one adult's right position.

226
00:14:00,590 --> 00:14:07,120
So our monetary properties were satisfied at this point only, but we have to satisfy the property.

227
00:14:07,130 --> 00:14:09,200
So that's why I have to write this much code.

228
00:14:09,890 --> 00:14:10,440
Simple.

229
00:14:11,180 --> 00:14:15,050
So in the next video, we will write the Code four, remove minimum function.

230
00:14:16,330 --> 00:14:17,530
I will see you in the next one.

231
00:14:17,670 --> 00:14:18,090
Bye bye.

