1
00:00:01,530 --> 00:00:03,210
Hello, everyone, welcome to this video.

2
00:00:03,240 --> 00:00:07,450
So in this session, what we do, we will solve one more problem with the help of recursion.

3
00:00:07,500 --> 00:00:10,110
OK, so the name of the problem is called digits.

4
00:00:11,330 --> 00:00:13,470
OK, so what is the problem?

5
00:00:13,550 --> 00:00:14,740
The problem is very simple.

6
00:00:14,760 --> 00:00:16,420
Suppose you will be given a number.

7
00:00:16,470 --> 00:00:22,010
Let's say the number is four zero two five and you have to tell the number of digits in the numbers

8
00:00:22,410 --> 00:00:23,430
of the jerseys for.

9
00:00:23,700 --> 00:00:26,010
OK, similarly, the number is 125.

10
00:00:26,040 --> 00:00:27,420
Number of digits is three.

11
00:00:27,570 --> 00:00:30,630
If the number is 20, the number of digits is two.

12
00:00:30,780 --> 00:00:34,680
OK, so you have to count the number of digits representing the number.

13
00:00:34,860 --> 00:00:37,320
OK, now what have to do so.

14
00:00:38,230 --> 00:00:44,020
I have to write a function count, but it will take it will take a number as input and you have to tell

15
00:00:44,230 --> 00:00:46,720
how many digits are present in this number.

16
00:00:46,720 --> 00:00:51,730
And now nowadays a constraint on the value of N so the end will be greater than or equal to one.

17
00:00:51,820 --> 00:00:55,960
OK, so the value often then what does N and will be a natural number.

18
00:00:56,770 --> 00:00:59,540
OK, so this is our constraint and is a natural number.

19
00:00:59,860 --> 00:01:06,070
OK, that means and cannot be zero and and basically cannot be less than or equal to zero and will always

20
00:01:06,070 --> 00:01:07,210
be a positive number.

21
00:01:07,300 --> 00:01:14,590
OK, so ok, so we have to calculate the number of digits present in Adam but now going to calculate

22
00:01:14,590 --> 00:01:15,430
the number of digits.

23
00:01:15,700 --> 00:01:18,460
OK, so what we will do, we will take the help of recursion.

24
00:01:18,610 --> 00:01:23,920
OK, if you remember we have already solved this problem with the help of four Lopevi Lubert here since

25
00:01:23,920 --> 00:01:26,470
we are using recursion, since we are learning recursion.

26
00:01:26,680 --> 00:01:29,060
So we'll try to solve this problem with the help of recursion.

27
00:01:29,350 --> 00:01:31,780
Now how we can solve this problem with the help of recursion.

28
00:01:32,190 --> 00:01:33,190
So what will happen?

29
00:01:33,920 --> 00:01:37,810
OK, so this is our number four zero to five.

30
00:01:38,050 --> 00:01:40,540
So what I am planning to do here is what I will do.

31
00:01:40,540 --> 00:01:41,710
I will spread this number.

32
00:01:43,190 --> 00:01:48,380
OK, I will tell that equation to solve this problem for me, so the question Winterlude occasionally

33
00:01:48,380 --> 00:01:52,460
turned me down, said three, and then what I will do, I will add plus one.

34
00:01:53,540 --> 00:01:54,830
So I will be for.

35
00:01:55,980 --> 00:02:02,960
OK, so what I will do, I will break my number and then I will tell Grigoryan, then I will tell you

36
00:02:03,300 --> 00:02:04,790
to solve this problem.

37
00:02:05,100 --> 00:02:07,640
So the question will give me three and I will add plus one.

38
00:02:07,740 --> 00:02:09,479
OK, let's take one more example.

39
00:02:09,750 --> 00:02:11,820
Suppose let's take a bigger example.

40
00:02:12,800 --> 00:02:19,640
So let's say one, two, three, four and five and six, so how many digits are there in this number?

41
00:02:19,880 --> 00:02:21,170
So there are six digits.

42
00:02:21,620 --> 00:02:24,650
OK, what I will do, I will break this number.

43
00:02:26,250 --> 00:02:32,670
And then I will tell Dacogen to solve this smaller problem for me, so the equation will return me five

44
00:02:33,180 --> 00:02:37,560
and then I will add plus one so that output will become six.

45
00:02:38,160 --> 00:02:40,700
OK, let's try on one example.

46
00:02:41,460 --> 00:02:46,410
So suppose let's say our example is four zero two five.

47
00:02:46,860 --> 00:02:49,990
OK, so the value of this, Gordana, goes to one.

48
00:02:50,010 --> 00:02:52,300
So this number qualifies for our problem.

49
00:02:52,320 --> 00:02:57,600
OK, so what I'm planning to do here is I will break this number at this part, OK?

50
00:02:57,780 --> 00:03:01,480
And I will tell you to solve this problem for me, OK?

51
00:03:01,740 --> 00:03:08,100
So I will reach four zero to number and then again, recursion.

52
00:03:08,640 --> 00:03:10,560
The problem I will call on this part.

53
00:03:11,950 --> 00:03:13,270
So I will call on 40.

54
00:03:14,240 --> 00:03:19,940
Again, we will break and we will call on this part, so I will call on for.

55
00:03:21,140 --> 00:03:24,810
Again, I will break at this part and I will call here.

56
00:03:24,830 --> 00:03:28,010
So this is zero basically, so I am calling one zero.

57
00:03:28,700 --> 00:03:30,440
So this will be our best case.

58
00:03:32,400 --> 00:03:37,080
OK, this will be our best case, so what it will be done, it will return zero.

59
00:03:38,810 --> 00:03:44,540
Now, our formula was this part of the sport, and I will add plus one.

60
00:03:44,690 --> 00:03:48,380
OK, so zero plus one.

61
00:03:48,410 --> 00:03:49,850
So I will return one here.

62
00:03:51,580 --> 00:03:57,760
OK, so the onset of this part is one, and I will add plus one, so I will return to.

63
00:03:58,760 --> 00:04:07,280
OK, so, Don, sort of this part of this part is to so and I will add plus one, so I will read entry.

64
00:04:07,700 --> 00:04:14,560
So the onset of this part the has told me that the onset of this part is three and three plus one.

65
00:04:14,780 --> 00:04:19,160
So our output will be four, which is our correct output, which is the correct output.

66
00:04:19,190 --> 00:04:19,519
OK.

67
00:04:20,820 --> 00:04:31,740
So if this isn't this whole reason, so for zero to five, if this is and now what is four zero two?

68
00:04:32,650 --> 00:04:36,020
So for 02, this is inviting.

69
00:04:37,450 --> 00:04:47,200
OK, so integer upon integer will be an integer, so four zero two five four two four zero two five

70
00:04:47,230 --> 00:04:51,250
divided by 10 will not be four zero two point five.

71
00:04:51,280 --> 00:04:52,450
It will be four zero two.

72
00:04:53,140 --> 00:04:56,080
Because we remember integer upon integer will be integer.

73
00:04:56,080 --> 00:04:58,120
OK, digital divide won't be there will be integer.

74
00:04:58,270 --> 00:05:01,500
OK, so I will write a function count.

75
00:05:02,110 --> 00:05:07,720
So this column function will take and as input what we have to do, we have to break our problem.

76
00:05:07,750 --> 00:05:12,910
So what this current function do is it will take an integer and it will tell you that number of digits

77
00:05:12,910 --> 00:05:13,660
present in.

78
00:05:13,690 --> 00:05:18,430
And so what I will do, I will give, I will call the function on.

79
00:05:18,430 --> 00:05:24,070
And by then so count will function, will give me how many digits are present in the number.

80
00:05:24,070 --> 00:05:30,550
And then basically if the value of it is four zero two five, then what I'm calling I'm calling on four

81
00:05:30,550 --> 00:05:30,980
zero two.

82
00:05:31,150 --> 00:05:35,440
So the question will tell me the number of digits current function will tell me the number of digits

83
00:05:35,440 --> 00:05:39,320
present in this is three I would have to do I have to add plus one.

84
00:05:39,790 --> 00:05:42,400
So if I will add plus one, I will get the problem.

85
00:05:42,760 --> 00:05:45,520
I will get the solution of the bigger problem rediscount often.

86
00:05:45,840 --> 00:05:48,910
OK, so this will be our recursive case.

87
00:05:50,680 --> 00:05:54,650
OK, and our best guess is if the value of any zero, I have to return zero.

88
00:05:55,000 --> 00:06:01,960
OK, now one thing that you may get confused is if the value of any zero, why we are not returning

89
00:06:01,960 --> 00:06:04,210
when we are not returning one here.

90
00:06:04,210 --> 00:06:09,160
Because initially I told you that the value of Fennville bigger than our to one.

91
00:06:09,790 --> 00:06:11,890
So this is basically invalid input.

92
00:06:12,010 --> 00:06:13,670
OK, this will be invalid.

93
00:06:13,690 --> 00:06:15,370
That's why I'm returning zero here.

94
00:06:16,700 --> 00:06:23,120
OK, so let's write the code and then we will draw this diagram again, so what they're done by Britain,

95
00:06:23,130 --> 00:06:26,440
they will be integer, OK, because I've got it done.

96
00:06:26,460 --> 00:06:27,830
How many digits are present?

97
00:06:28,400 --> 00:06:30,530
So let's write a function count.

98
00:06:30,890 --> 00:06:35,750
It will take a number and and we have to find how many digits are present in the number and.

99
00:06:36,760 --> 00:06:37,810
So best case will be.

100
00:06:40,350 --> 00:06:45,020
So this is our base case, and this case is very simple, if the value of any zero.

101
00:06:45,900 --> 00:06:47,550
So how many digits are present?

102
00:06:47,910 --> 00:06:49,200
Zero digits at present?

103
00:06:49,770 --> 00:06:53,190
OK, because this is invalid input then.

104
00:06:54,380 --> 00:06:55,910
Again, recursive case.

105
00:06:58,700 --> 00:07:00,890
So recursive case, small output.

106
00:07:02,260 --> 00:07:06,160
Small answer, so small answer is if you want to calculate.

107
00:07:07,060 --> 00:07:13,780
Number of digits and then calculate the number of digits and then Martin, OK, and then the calculation

108
00:07:13,780 --> 00:07:14,140
part.

109
00:07:17,340 --> 00:07:23,520
So calculation part is very simple, after calculating this moylan's that I have to add plus one and

110
00:07:23,580 --> 00:07:26,030
done and let's test our function.

111
00:07:26,310 --> 00:07:28,560
So I'm calling this function count.

112
00:07:30,270 --> 00:07:31,410
For let's see.

113
00:07:33,730 --> 00:07:35,170
Seven, eight, two zero.

114
00:07:35,420 --> 00:07:37,990
OK, I'm calling this function for seven eight two zero.

115
00:07:39,450 --> 00:07:43,110
Now, let's run our file so our picture before there are four digits.

116
00:07:43,180 --> 00:07:43,470
OK.

117
00:07:46,670 --> 00:07:51,800
So I would protest for several quarters, working fine now after getting the code with the help of BMI,

118
00:07:51,850 --> 00:07:54,050
but what we will do, we will try to do that.

119
00:07:54,050 --> 00:07:58,700
And our goal basically, we will try to draw the diagram so that we can have a better understanding.

120
00:07:58,730 --> 00:07:59,060
OK.

121
00:08:00,200 --> 00:08:05,870
So seven to zero, the value of seven, eight to zero, so seven, eight to zero.

122
00:08:07,610 --> 00:08:14,570
OK, so this is not close to zero, seven to zero is not close to zero, so line number 10, I will

123
00:08:14,570 --> 00:08:19,280
call on and by Martin, so I will call on seven eight to.

124
00:08:21,300 --> 00:08:24,820
Then again, I will come at this line.

125
00:08:24,840 --> 00:08:30,810
So basically 72 zero is waiting in line number 10, 72 is waiting out line number 10, then I will call

126
00:08:30,810 --> 00:08:32,820
on 78 again.

127
00:08:32,820 --> 00:08:34,280
I will call on this function.

128
00:08:34,289 --> 00:08:35,750
So it will be a red line number.

129
00:08:35,760 --> 00:08:37,590
Then it will call on seven.

130
00:08:37,890 --> 00:08:39,390
Seven is not close to zero.

131
00:08:40,020 --> 00:08:41,750
This also very hard line number 10.

132
00:08:41,789 --> 00:08:43,140
So it will call on zero.

133
00:08:43,799 --> 00:08:46,410
OK, and by then so seven by ten will be zero.

134
00:08:47,100 --> 00:08:51,610
So if the value of any zero, I'm returning zero, so I will return zero.

135
00:08:52,110 --> 00:08:54,460
So seven was waiting at line number 10.

136
00:08:54,780 --> 00:08:56,220
So after the number 10.

137
00:08:56,230 --> 00:08:57,360
Smolan Plus one.

138
00:08:57,510 --> 00:09:00,720
OK, so the simple answer was zero.

139
00:09:00,900 --> 00:09:02,100
So what seven will done.

140
00:09:02,460 --> 00:09:05,100
Small answered plus one so it will return one.

141
00:09:05,820 --> 00:09:09,120
Now here the value of small answer is one again.

142
00:09:09,120 --> 00:09:12,120
I have to return Small said plus one.

143
00:09:12,870 --> 00:09:13,980
So I will return to.

144
00:09:15,430 --> 00:09:22,630
So the value of small answer is to save the residents moralizer plus one, so and three, then I have

145
00:09:22,630 --> 00:09:24,310
to return small Lanser plus one.

146
00:09:24,580 --> 00:09:26,640
So I had a of small answer is three.

147
00:09:26,890 --> 00:09:29,050
So I have to return three plus one, which is four.

148
00:09:29,430 --> 00:09:32,900
OK, so four is our answer for seven to zero.

149
00:09:33,070 --> 00:09:42,520
OK, so I have seven to zero then I big this number I, I call the recursion on this part of the equation.

150
00:09:43,370 --> 00:09:47,740
So this is 72 I big this number recursion.

151
00:09:47,740 --> 00:09:49,270
I call the recursion on this part.

152
00:09:49,640 --> 00:09:50,910
So this is seven.

153
00:09:50,920 --> 00:09:52,750
Did I break this number.

154
00:09:52,990 --> 00:09:54,760
Recursion will call on this part.

155
00:09:56,490 --> 00:10:03,000
I break this, no occasion will call on this part, so it will be zero zero zero zero from here and

156
00:10:03,000 --> 00:10:07,620
zero plus one, so I will return one one plus one.

157
00:10:07,830 --> 00:10:10,610
So I will return to two plus one.

158
00:10:10,740 --> 00:10:13,790
I will return three three plus one.

159
00:10:13,800 --> 00:10:14,820
I will return four.

160
00:10:15,300 --> 00:10:18,650
OK, so in short, you can understand it like this way.

161
00:10:20,070 --> 00:10:23,220
I want to calculate the number of digits present in this part.

162
00:10:23,520 --> 00:10:25,230
Besant in the numbers seven to zero.

163
00:10:25,530 --> 00:10:30,930
I will break the number because it is big, the number big the bigger problem and a smaller problem.

164
00:10:31,710 --> 00:10:33,990
And I am calling it a collision on this part.

165
00:10:34,380 --> 00:10:36,590
So the equation will tell me you do not.

166
00:10:36,600 --> 00:10:41,190
We have to assume, OK, I told you we have to assume so we have to assume that the equation will tell

167
00:10:41,190 --> 00:10:42,810
me the answer of this part is three.

168
00:10:43,450 --> 00:10:46,740
OK, now you don't have to think how the answer is.

169
00:10:46,740 --> 00:10:49,560
Three, assume that the equation will give me the answer.

170
00:10:49,560 --> 00:10:51,870
Three, so the question gives me the answer three.

171
00:10:52,260 --> 00:10:54,030
And then I will add plus one.

172
00:10:54,990 --> 00:10:56,950
So three plus one and the answer is four.

173
00:10:57,330 --> 00:11:02,940
OK, so I'm assuming here that and then going function will give me the value.

174
00:11:04,030 --> 00:11:08,080
Give me the answer for this part, so the answer for this, but will come out to be three and then I

175
00:11:08,080 --> 00:11:12,590
am returning three plus one, which is for OK, so I hope you understood the gold.

176
00:11:13,290 --> 00:11:15,400
OK, the problem was very, very simple.

177
00:11:15,760 --> 00:11:17,200
OK, thank you.

