1
00:00:02,180 --> 00:00:02,870
Hi, everyone.

2
00:00:02,900 --> 00:00:07,590
So in this video, we are going to discuss and find the diameter of a binary tree.

3
00:00:08,060 --> 00:00:09,770
So what is the meaning of diameter?

4
00:00:10,040 --> 00:00:11,060
So encircle?

5
00:00:12,040 --> 00:00:17,980
Diameter is basically the maximum distance between any two points, so similarly, in case of binary,

6
00:00:18,310 --> 00:00:21,200
diameter is the maximum distance between any two nodes.

7
00:00:21,520 --> 00:00:23,950
So let us take one example.

8
00:00:23,990 --> 00:00:29,020
So this is a binary tree and what is the distance between this node and this node?

9
00:00:29,320 --> 00:00:31,870
So count Edwyn as two and three.

10
00:00:32,060 --> 00:00:33,850
So the distance is basically three.

11
00:00:34,780 --> 00:00:41,250
And this note and this note, the circumstances, one, two, three and four, so the distances for

12
00:00:41,420 --> 00:00:47,230
but I need to find out the diameter and diameter is the maximum distance between any two roads.

13
00:00:47,680 --> 00:00:51,280
So the maximum distance will be between this node and this additional.

14
00:00:51,520 --> 00:00:55,040
So count one, two, three, four and five.

15
00:00:55,330 --> 00:00:56,520
So the answer is five.

16
00:00:56,800 --> 00:00:59,770
Now, there are many ways in which we can obtain five.

17
00:00:59,980 --> 00:01:03,600
For example, the distance within this node and this node is also five.

18
00:01:03,880 --> 00:01:07,120
The distance between this node and this node is also five.

19
00:01:07,330 --> 00:01:10,110
So there are many ways to achieve this number five.

20
00:01:10,480 --> 00:01:15,610
But since we only want to return the integer so we do not care about the number of combinations, we

21
00:01:15,610 --> 00:01:19,960
just want to return the diameter and diameters, the maximum distance between any two node.

22
00:01:19,960 --> 00:01:20,800
So for Destry.

23
00:01:21,930 --> 00:01:23,160
My output will be five.

24
00:01:24,790 --> 00:01:28,130
So how we can solve this question, so let's take one more example first.

25
00:01:28,690 --> 00:01:30,040
So if this is a binary tree.

26
00:01:33,310 --> 00:01:35,600
What is the maximum distance for this diameter?

27
00:01:35,620 --> 00:01:42,490
So one, two, three and four, so the diameter is four and we can see we can say with this diameter,

28
00:01:42,490 --> 00:01:45,070
diameter is left eight plus right height.

29
00:01:45,370 --> 00:01:46,720
So left out is two.

30
00:01:47,110 --> 00:01:48,700
And right now it is also two.

31
00:01:48,700 --> 00:01:49,880
So two plus two is four.

32
00:01:50,710 --> 00:01:52,010
So let's take one more example.

33
00:01:52,030 --> 00:01:55,510
So for this binary tree vertebrae, the diameter.

34
00:01:57,850 --> 00:02:01,190
So diameter is between this node and this node.

35
00:02:01,210 --> 00:02:03,340
So one, two, three, four and five.

36
00:02:03,490 --> 00:02:05,200
So diameter is coming out to be five.

37
00:02:05,380 --> 00:02:09,690
And what is left, right, so left out is to what is right.

38
00:02:09,949 --> 00:02:11,240
So right now it is three.

39
00:02:11,590 --> 00:02:12,910
So two plus two is five.

40
00:02:13,240 --> 00:02:15,520
So can we say that this formula is correct?

41
00:02:16,470 --> 00:02:19,980
So I think this is a good guess, but this formula is not correct.

42
00:02:20,530 --> 00:02:20,740
Why?

43
00:02:20,800 --> 00:02:21,590
It is not correct.

44
00:02:21,610 --> 00:02:22,990
So I will give you one example.

45
00:02:23,980 --> 00:02:25,560
This formula will not always work.

46
00:02:25,570 --> 00:02:27,770
It will work only in some situations.

47
00:02:28,510 --> 00:02:29,800
So if this is Maitri.

48
00:02:35,540 --> 00:02:36,770
So for this Pinetree.

49
00:02:37,930 --> 00:02:41,830
What is left out, right, right, right, right is one.

50
00:02:43,010 --> 00:02:50,630
And left is one, two, three and four, so four plus one is five, so according to this formula, my

51
00:02:50,630 --> 00:02:51,740
diameter should be five.

52
00:02:53,290 --> 00:02:55,480
But let's see whether that's correct or not.

53
00:02:55,510 --> 00:02:59,480
So I think it is not distance between this note and this note.

54
00:02:59,500 --> 00:03:02,790
So one, two, three, four, five and six.

55
00:03:03,160 --> 00:03:05,760
So the correct answer is basically this.

56
00:03:06,160 --> 00:03:10,440
So in this problem, in case of this binary tree, this one is not correct.

57
00:03:10,690 --> 00:03:12,040
So this is a very good guess.

58
00:03:12,700 --> 00:03:14,280
But this is not correct.

59
00:03:15,360 --> 00:03:17,880
This is not the correct way of finding the diameter.

60
00:03:18,150 --> 00:03:24,870
So in this case, the diameter is not passing through, the diameter is not passing through the route.

61
00:03:24,870 --> 00:03:28,310
And I never said in the question that diameter must pass through root.

62
00:03:28,950 --> 00:03:32,590
So it is not necessary that diameter must pass through root.

63
00:03:33,540 --> 00:03:35,520
So what are the situations that we can have?

64
00:03:35,550 --> 00:03:37,450
So there are three situations, according to me.

65
00:03:38,250 --> 00:03:43,350
So first one is basically how we will utilize our tree so we will regulate our tree like this.

66
00:03:46,660 --> 00:03:52,280
Now, one situation is the first note lies in the left, the second northerlies in the right supply.

67
00:03:52,540 --> 00:03:55,360
So in this case, our answer is correct.

68
00:03:55,390 --> 00:03:57,650
So diameter will be left eight plus right out.

69
00:03:58,180 --> 00:04:05,320
Now, if both the nodes lie in the left Sabry so if both an old line, the leaves are so right it doesn't

70
00:04:05,320 --> 00:04:06,040
have any effect.

71
00:04:06,280 --> 00:04:09,250
So in this case my answer will be left diameter.

72
00:04:09,400 --> 00:04:15,490
So left diameter is the diameter of the whole tree, so diameter will be the diameter of the hole.

73
00:04:15,700 --> 00:04:22,930
So this is whole the diameter because both the nodes lying in the left and right subtree has no effect.

74
00:04:23,320 --> 00:04:29,560
Now if both the nodes are present in the right subtree, so in this case, my answer will be the right

75
00:04:29,560 --> 00:04:35,320
diameter because diameter does not have any effect, because the left tree does not have any effect.

76
00:04:35,590 --> 00:04:39,100
So in this case, the right diameter will be the whole tree diameter.

77
00:04:40,000 --> 00:04:41,030
There are two situations.

78
00:04:41,060 --> 00:04:44,230
So first one is basically our tree will be like this.

79
00:04:46,310 --> 00:04:47,750
So if this is Maitri.

80
00:04:49,140 --> 00:04:51,690
Then the second situation, military can be like this.

81
00:04:56,400 --> 00:04:59,700
And in the third situation, my dream can be like this.

82
00:05:05,650 --> 00:05:11,990
So for this kind of free for distri, my answer is basically left out, plus right out.

83
00:05:12,250 --> 00:05:13,450
So basically this thing.

84
00:05:14,510 --> 00:05:15,870
Left, right, right, right.

85
00:05:15,980 --> 00:05:23,870
So this will be the time for this kind of tree, my answer will be the left diameter monster will be

86
00:05:23,870 --> 00:05:25,790
the diameter for this tree.

87
00:05:25,940 --> 00:05:28,430
My answer will be the right diameter.

88
00:05:30,720 --> 00:05:31,770
So what we need to do.

89
00:05:32,900 --> 00:05:34,490
So we'll find out all this value.

90
00:05:34,520 --> 00:05:40,010
So this is our first option, this is our second option and this is our third option and our answer

91
00:05:40,010 --> 00:05:42,680
will be the maximum of the three options.

92
00:05:42,680 --> 00:05:49,370
So make them our first option, second option and third option, simple and how we can find out the

93
00:05:49,610 --> 00:05:52,970
diameter we will colocation for finding out the diameter.

94
00:05:53,210 --> 00:05:56,750
Similarly, we will call the for finding out the right diameter.

95
00:05:56,750 --> 00:05:58,360
And that will be my answer.

96
00:05:58,370 --> 00:05:58,880
Simple.

97
00:05:59,720 --> 00:06:07,100
So this question is basically present only it could find the diameter of a binary tree and now let us

98
00:06:07,310 --> 00:06:09,190
compute the cord for this function.

99
00:06:09,200 --> 00:06:10,580
So we are taking root as input.

100
00:06:13,050 --> 00:06:17,270
First of all, we need to discuss about the best case, so what is the best case if the route is.

101
00:06:20,410 --> 00:06:26,770
So if rotational, what is their diameter, diameter will be zero, simple maximum distance between

102
00:06:26,770 --> 00:06:31,340
any two nodes and in my tree I don't have any node, so diameter will be zero.

103
00:06:31,870 --> 00:06:34,510
So our first option is basically.

104
00:06:35,990 --> 00:06:38,000
This one, left, right, plus retied.

105
00:06:39,730 --> 00:06:41,710
So left out, right, right.

106
00:06:43,360 --> 00:06:45,550
So I will write the code for this hate function.

107
00:06:46,210 --> 00:06:48,010
I will give the left subtree.

108
00:06:49,590 --> 00:06:50,490
And I will give.

109
00:06:52,470 --> 00:06:53,310
The right subtree.

110
00:06:54,470 --> 00:06:57,090
So I will write the code for this function, how to function.

111
00:06:57,320 --> 00:06:59,150
So our first option is very simple.

112
00:06:59,570 --> 00:07:03,710
Left, right plus right now our second option is.

113
00:07:05,060 --> 00:07:08,900
I was separate option is left Daym and third option is right diameter.

114
00:07:11,820 --> 00:07:13,050
So our option to.

115
00:07:16,550 --> 00:07:19,580
It's basically Dimitrov by Nutri.

116
00:07:21,040 --> 00:07:22,930
And we will give it left subtree.

117
00:07:26,990 --> 00:07:28,550
And our third option is.

118
00:07:32,400 --> 00:07:35,130
The right diameter, so we'll call this function.

119
00:07:38,680 --> 00:07:39,820
And we will give it.

120
00:07:41,220 --> 00:07:42,120
The right subtree.

121
00:07:43,610 --> 00:07:44,840
And now what we need to do.

122
00:07:46,020 --> 00:07:52,590
So we need to lay the Maximov first option, second option and third option, so we have inbuilt max

123
00:07:52,590 --> 00:07:53,780
function, so we will use it.

124
00:07:54,000 --> 00:07:55,920
So Maximov.

125
00:07:55,920 --> 00:07:58,480
N.B. This is how it works.

126
00:07:58,500 --> 00:08:01,320
It will take two things as it put to argument as input.

127
00:08:01,530 --> 00:08:03,820
And I want to take the input of two things.

128
00:08:03,820 --> 00:08:07,360
So I will write like this mix of a mix of BNC.

129
00:08:08,400 --> 00:08:11,340
So this is how we can take the maximum of three things.

130
00:08:12,650 --> 00:08:13,760
So let's write the code.

131
00:08:14,670 --> 00:08:15,600
So I will return.

132
00:08:16,760 --> 00:08:17,720
The maximum of.

133
00:08:19,340 --> 00:08:20,090
Option one.

134
00:08:22,860 --> 00:08:28,770
Mix of option two and three, option two and option three.

135
00:08:30,240 --> 00:08:35,460
So the only thing left is basically to write the code for this function, so let's write the code.

136
00:08:39,400 --> 00:08:42,299
Will teacher, then the function is height.

137
00:08:43,730 --> 00:08:46,190
So this will take root and put.

138
00:08:48,320 --> 00:08:50,240
And redecide, so if.

139
00:08:51,360 --> 00:08:52,140
Rotational.

140
00:08:55,000 --> 00:09:04,120
My height is zero, if true, does not exist Diatta zero, otherwise the height will be one plus maximum

141
00:09:04,120 --> 00:09:05,650
of left and right out.

142
00:09:06,600 --> 00:09:09,750
One plus maximum of left out.

143
00:09:11,840 --> 00:09:13,220
And right, right.

144
00:09:18,120 --> 00:09:22,160
So, yes, I think our gold will rock solid right now, and then we will submit.

145
00:09:24,270 --> 00:09:25,450
Now, there are some rhetorical.

146
00:09:28,970 --> 00:09:35,090
So basically, our goal is working and now we will discuss the time, complexity for our solution,

147
00:09:35,100 --> 00:09:36,290
relative time, complexity.

148
00:09:36,530 --> 00:09:40,250
So first, let us discuss about the time, complexity of the function.

149
00:09:41,150 --> 00:09:43,130
So let's discuss about the to function.

150
00:09:43,490 --> 00:09:44,480
So what we are doing.

151
00:09:45,540 --> 00:09:49,560
We are calling it a collision on the left and on the right separately, so this is Natalie.

152
00:09:53,210 --> 00:09:57,740
So I will call it function for the left subtree, I will call it function for the right.

153
00:09:58,400 --> 00:10:04,400
So basically we are going to each and every node and for each node we are doing a constant amount of

154
00:10:04,400 --> 00:10:04,630
work.

155
00:10:04,940 --> 00:10:06,600
So for each node we are doing.

156
00:10:06,920 --> 00:10:10,110
So this constant amount of work, one plus.

157
00:10:10,550 --> 00:10:12,550
So this is also the constant amount of work.

158
00:10:12,560 --> 00:10:16,790
So we are going through each and every node and for each and what we are doing, constant amount of

159
00:10:16,790 --> 00:10:17,030
work.

160
00:10:17,300 --> 00:10:20,060
So that time complexity for how it function is big often.

161
00:10:21,490 --> 00:10:25,730
Now, let's try to find out the time, complexity of this function diameter function.

162
00:10:26,860 --> 00:10:28,180
So, again, what we are doing.

163
00:10:28,390 --> 00:10:30,400
So this is Maitri.

164
00:10:33,800 --> 00:10:35,930
So we are calling their diameter function on the left.

165
00:10:36,110 --> 00:10:37,750
We are calling diameter function on the right.

166
00:10:38,300 --> 00:10:40,710
So I am calling diameter a function for the left subtree.

167
00:10:40,760 --> 00:10:43,040
I am calling diameter function for the right subtree.

168
00:10:43,400 --> 00:10:48,620
So we are going to each and every node and let's see at each and how much amount of work we are doing.

169
00:10:49,100 --> 00:10:55,910
So this is constraint, the amount of work and then we are calling the function for every node, we

170
00:10:55,910 --> 00:11:00,110
are calling the function for every node and this is the constant amount of work.

171
00:11:00,920 --> 00:11:04,130
So basically for each node, I'm calling the function.

172
00:11:04,430 --> 00:11:08,030
So now let's try to find out the complexity of this function.

173
00:11:08,270 --> 00:11:11,600
So basically three can be of two types.

174
00:11:11,930 --> 00:11:15,150
So first three can be balanced.

175
00:11:15,170 --> 00:11:17,410
So this is an example of a balanced tree.

176
00:11:17,660 --> 00:11:21,470
The number of nodes in the left and the right are they both are the same.

177
00:11:22,130 --> 00:11:25,880
So I'm standing here at the root node and then what I'm doing.

178
00:11:26,120 --> 00:11:29,000
So for each node, I'm calling the function.

179
00:11:29,960 --> 00:11:35,240
So if there are any node, so for each and what I am calling the function so.

180
00:11:36,290 --> 00:11:39,940
Gay and minus one, or we can simply write it again.

181
00:11:41,260 --> 00:11:44,770
Plus, we are doing some constant amount of work for each a..

182
00:11:44,920 --> 00:11:50,830
OK, so this constant so we can remove it and then what we are doing, so we are calling the function.

183
00:11:51,860 --> 00:11:55,490
For delectably and for the rights Sabry, so two times.

184
00:11:57,450 --> 00:12:06,150
And by do OK, now we have seen this, so we have seen this somewhere, so this is exactly like.

185
00:12:06,870 --> 00:12:07,590
So this is.

186
00:12:08,590 --> 00:12:10,210
Exactly like Mozart.

187
00:12:10,480 --> 00:12:14,500
So what is your time, complexity, so time complexity is and Logan.

188
00:12:17,210 --> 00:12:21,110
Now, another kind of tree that we can have is basically this kind of tree.

189
00:12:23,930 --> 00:12:27,770
Now, let's try to find out the complexity of this function for this type of.

190
00:12:29,060 --> 00:12:34,820
So initially we are standing here at the root node, then I am calling.

191
00:12:34,850 --> 00:12:36,350
So this is constrained amount of work.

192
00:12:36,360 --> 00:12:38,990
So let's try to their number of nodes is.

193
00:12:38,990 --> 00:12:45,290
And so this constant amount of work or we can remove it since it is constant, then we are calling the

194
00:12:45,290 --> 00:12:45,880
hate function.

195
00:12:45,890 --> 00:12:49,070
So left simply does not exist and the right subtree.

196
00:12:49,250 --> 00:12:52,580
So how many number of nodes are present and minus one node.

197
00:12:52,970 --> 00:13:00,560
So I am Complexo and minus one time complexities and minus one in tookey simple Hyett function time.

198
00:13:00,560 --> 00:13:05,240
Complexity was linear if you remember so and minus K and then what we are doing.

199
00:13:05,450 --> 00:13:07,710
So we are calling the function on the left subtree.

200
00:13:07,760 --> 00:13:09,440
We are calling the function the right subtree.

201
00:13:09,590 --> 00:13:14,460
So left are Presnell and the rights are pre how many notes are there and minus one nodes are there.

202
00:13:14,840 --> 00:13:17,030
So this is the Rickerson deletion.

203
00:13:18,900 --> 00:13:20,340
So this is direct resolution.

204
00:13:20,790 --> 00:13:25,310
Now, what would be the time, complexity, so how we can solve this?

205
00:13:25,470 --> 00:13:27,530
So let's take the example of the bubblehead.

206
00:13:28,020 --> 00:13:29,100
So in the world sort.

207
00:13:31,860 --> 00:13:37,380
What we do, so we compare the elements and we still have them, then we compared the elements and we

208
00:13:37,380 --> 00:13:39,800
swab, we compared the element and we'll swab.

209
00:13:39,960 --> 00:13:41,400
So after one iteration.

210
00:13:42,560 --> 00:13:45,120
The largest element will represent at last.

211
00:13:45,680 --> 00:13:52,040
So after midnight, that means after End-Time big oftentime, the largest element will be present at

212
00:13:52,040 --> 00:13:52,350
last.

213
00:13:53,030 --> 00:13:59,840
So we have to do this same thing for and minus one element we have done once.

214
00:14:00,500 --> 00:14:02,740
And it cost me big oftentime.

215
00:14:02,990 --> 00:14:05,970
I have to do the same thing for the remaining and minus one element.

216
00:14:06,260 --> 00:14:07,820
So what is the solution?

217
00:14:08,780 --> 00:14:12,290
So for one element, you did big oftentime.

218
00:14:13,290 --> 00:14:18,330
And we need to do the same thing for nd minus one element also so and minus one.

219
00:14:20,770 --> 00:14:24,440
So now you can compare so and minus one it took, it seems.

220
00:14:24,460 --> 00:14:26,750
And so the reconciliation is the same.

221
00:14:26,770 --> 00:14:29,190
And what is your time complexity for the short term?

222
00:14:29,200 --> 00:14:30,730
Complexity is and square.

223
00:14:31,570 --> 00:14:35,690
So for this type of tree, the time complexity is and square.

224
00:14:37,210 --> 00:14:38,670
So let's write everything again.

225
00:14:40,440 --> 00:14:42,790
So we can have two kinds of free.

226
00:14:43,080 --> 00:14:47,340
So this is the first one, which is the balanced number of free number of nodes in the left, Sabry

227
00:14:47,640 --> 00:14:50,060
is equal to the number of nodes and the right subtree.

228
00:14:50,400 --> 00:14:52,850
And this is another kind of reach that we can have.

229
00:14:53,190 --> 00:15:00,030
So for Destry, the time, complexities and log-in, for distri, the time, complexities and Scribd.

230
00:15:01,350 --> 00:15:07,460
So what is the correct term complexity, so our role is we will report the worst case time complexity.

231
00:15:07,470 --> 00:15:13,870
So ideally we should say the time, complexities and square, because this is the worst case, time,

232
00:15:13,890 --> 00:15:14,520
complexity.

233
00:15:15,030 --> 00:15:20,720
But we will not write our answers and square because if we see for this kind of three.

234
00:15:21,820 --> 00:15:27,940
We can do the calculation and we can find out the height is basically log often where any number of

235
00:15:27,940 --> 00:15:29,890
nodes log often.

236
00:15:30,040 --> 00:15:34,210
And for this tree, there is no need to do any calculation for finding out the height.

237
00:15:34,360 --> 00:15:36,490
Height is simply the number of nodes present.

238
00:15:38,210 --> 00:15:40,100
So what is the time, complexity?

239
00:15:40,900 --> 00:15:47,360
Time is basically in multiply the height, Logan is basically the height for this type of reform.

240
00:15:47,360 --> 00:15:47,970
Balestra.

241
00:15:48,380 --> 00:15:54,710
So here the time complexities, number of nodes multiply by eight and here the time complexities and

242
00:15:54,890 --> 00:15:57,410
multiply by height and how it is and.

243
00:15:58,510 --> 00:16:05,620
So my correct term complexity is basically big off number of nodes multiplied by hate.

244
00:16:06,100 --> 00:16:11,920
So this is the correct time complexity that we will report number of nodes multiplied by HAID.

245
00:16:13,510 --> 00:16:19,060
So what we want to do so in the next we do, we want to remove this, we want to decrease our time,

246
00:16:19,060 --> 00:16:25,240
complexity, and by the time complexity is high, let's try to analyze why the time complexity for this

247
00:16:25,240 --> 00:16:25,990
function is high.

248
00:16:26,830 --> 00:16:28,090
So let's take one example.

249
00:16:29,690 --> 00:16:31,370
So if this is Maitri.

250
00:16:33,700 --> 00:16:34,900
One, two, three and four.

251
00:16:36,830 --> 00:16:44,000
So I am standing at this node, so what I will do, I will say find out for the left does not exist.

252
00:16:44,150 --> 00:16:47,870
So finally, hired for the right one will call on to give me the right.

253
00:16:48,200 --> 00:16:53,690
So I want to find the out of when no one will ask her to give me the hate.

254
00:16:54,230 --> 00:16:58,160
So we will find out ASAP and it will return the answer.

255
00:16:58,610 --> 00:16:59,130
Simple.

256
00:16:59,480 --> 00:17:02,020
So now option two so left does not exist.

257
00:17:02,030 --> 00:17:07,440
So option three daym so haven, give me your diameter.

258
00:17:07,700 --> 00:17:14,520
So when will call on two and in two we are again we will again call the hate function so four two two

259
00:17:14,540 --> 00:17:15,619
will ask for it again.

260
00:17:15,890 --> 00:17:21,230
So see when I am calling this function for two then two will call hate again.

261
00:17:21,260 --> 00:17:22,579
We will again ask for hate.

262
00:17:23,390 --> 00:17:27,349
So you can see we are doing repetition of the same work.

263
00:17:27,349 --> 00:17:29,660
We are doing the same work multiple times.

264
00:17:31,860 --> 00:17:38,670
So number of calls for two will increase, similarly, there will be more calls for this note, there

265
00:17:38,670 --> 00:17:40,560
will be much more call for this.

266
00:17:41,220 --> 00:17:48,480
So the time complexity is big off and multiply by eight by the time complexity is more because we are

267
00:17:48,480 --> 00:17:50,820
doing the same work many times.

268
00:17:52,700 --> 00:17:56,160
And that is the reason, so how we can improve our time complexity.

269
00:17:57,200 --> 00:17:58,070
So what we will do?

270
00:18:00,490 --> 00:18:01,360
If this is.

271
00:18:02,640 --> 00:18:09,480
Mitry So I will ask her to give me the heightened diameter at once.

272
00:18:10,680 --> 00:18:13,320
So to Willetton, height and diameter at once.

273
00:18:14,420 --> 00:18:20,630
OK, we will not call multiple time, so here what we are doing, first of all, I am asking so if this

274
00:18:20,630 --> 00:18:21,110
is the three.

275
00:18:23,310 --> 00:18:32,520
So for one, for one, I want to find out the hate for when I find out the hate, so I want you to give

276
00:18:32,520 --> 00:18:33,050
me the hate.

277
00:18:33,390 --> 00:18:35,620
So when will call on two for finding out the hate?

278
00:18:35,830 --> 00:18:41,610
So when I am the function of two, so two will again call on three hate, three give mediate or two

279
00:18:41,640 --> 00:18:43,410
will call on three to give it tight.

280
00:18:45,570 --> 00:18:50,790
Now, when you want to find out the diameter of one, so you want to find out the diameter of one,

281
00:18:51,000 --> 00:18:57,000
so one will call on to here to give given a diameter, we will again call for finding out the height.

282
00:18:57,080 --> 00:18:58,140
So we will again.

283
00:18:58,150 --> 00:19:04,200
So we are again finding out the height and for finding out who will again call on three and three will

284
00:19:04,200 --> 00:19:04,960
return the height.

285
00:19:05,370 --> 00:19:09,810
So we are doing the same work multiple times and that's why the time complexity is more so.

286
00:19:09,810 --> 00:19:12,340
What I want to do is I'm giving you a hint.

287
00:19:12,360 --> 00:19:17,390
So what I will do so in this approach, first we are asking here to give me the height.

288
00:19:17,520 --> 00:19:21,890
So once to give the height, then I will ask again here to give me the diameter.

289
00:19:21,990 --> 00:19:24,510
First I am asking for to give me the height.

290
00:19:24,510 --> 00:19:26,820
Then I'm asking to again to give me the diameter.

291
00:19:27,090 --> 00:19:29,100
OK, so one is calling on two.

292
00:19:30,300 --> 00:19:34,710
Here to give me the height, so went to Willetton, the height, then I am again calling on to find

293
00:19:34,710 --> 00:19:35,400
the diameter.

294
00:19:35,550 --> 00:19:39,270
So that's why the repetition of work will be there and then to Willetton, the diameter.

295
00:19:39,540 --> 00:19:42,510
So what I want to do is I will call in such a way.

296
00:19:43,020 --> 00:19:48,060
So I will call like this here to give me the height and diameter at once.

297
00:19:48,240 --> 00:19:49,710
So too will do the calculation.

298
00:19:49,710 --> 00:19:51,330
Only one, only once.

299
00:19:51,510 --> 00:19:55,440
And to Willerton both values and height and diameter both.

300
00:19:57,080 --> 00:20:03,650
So that's how we'll be able to solve this question and less time complexity so correctly, our time

301
00:20:03,650 --> 00:20:05,920
complexities and multiply by each.

302
00:20:06,140 --> 00:20:09,610
So we want to remove we want to decrease our time complexity.

303
00:20:09,620 --> 00:20:13,200
And this is the way that we will reduce our time complexity.

304
00:20:13,430 --> 00:20:16,740
So in the next we do we will discuss about it and we will also write the code.

305
00:20:17,060 --> 00:20:18,350
So this is it from this video.

306
00:20:18,350 --> 00:20:19,550
I will see you in the next one.

