1
00:00:01,580 --> 00:00:02,210
Hello everyone.

2
00:00:02,210 --> 00:00:06,140
So in this video we will try to solve one more equation problem.

3
00:00:06,140 --> 00:00:09,150
So I want to calculate power.

4
00:00:09,440 --> 00:00:11,990
OK so I want to calculate extra the power.

5
00:00:12,590 --> 00:00:19,040
OK so x is any number and and is a whole number that is 0 1 2 and so on.

6
00:00:19,040 --> 00:00:22,500
Okay so suppose I want to calculate 5 to the power tree.

7
00:00:22,520 --> 00:00:26,860
So this will be 5 to 5 and 2 5 which is 125.

8
00:00:26,870 --> 00:00:27,410
Okay.

9
00:00:27,410 --> 00:00:28,940
So I want to calculate power.

10
00:00:29,000 --> 00:00:29,230
Okay.

11
00:00:29,240 --> 00:00:35,030
So what I want to do I want to I want to write the power function and I want to find extra the power.

12
00:00:35,540 --> 00:00:39,890
Okay so X is a any number and n is a whole number.

13
00:00:40,450 --> 00:00:40,660
Okay.

14
00:00:40,670 --> 00:00:42,810
So how we can solve this problem.

15
00:00:42,890 --> 00:00:45,800
So first we have to think of the recursive case.

16
00:00:45,830 --> 00:00:53,470
Okay so what is extra the power and so can we write it like this X Multiply extra the power N minus

17
00:00:53,470 --> 00:00:54,550
one.

18
00:00:54,550 --> 00:00:54,960
Okay.

19
00:00:55,090 --> 00:01:02,440
So we can write it like this extra the power and is calculate excited about N minus one and then multiply

20
00:01:02,620 --> 00:01:03,380
x.

21
00:01:03,430 --> 00:01:03,870
Okay.

22
00:01:03,940 --> 00:01:05,790
So we have two.

23
00:01:05,860 --> 00:01:10,030
So I've learned to convert bigger problem than I have to calculate the smaller problem so this will

24
00:01:10,030 --> 00:01:11,170
be our recursive case.

25
00:01:11,950 --> 00:01:12,580
Okay.

26
00:01:12,580 --> 00:01:22,240
So if I want to find x to the power n what I will do first of all I will find X to the power end minus

27
00:01:22,240 --> 00:01:26,110
one and then I will multiply x.

28
00:01:26,260 --> 00:01:26,720
Okay.

29
00:01:26,830 --> 00:01:31,490
So this is our recursive case this will be our recursive case.

30
00:01:31,570 --> 00:01:31,870
Okay.

31
00:01:32,260 --> 00:01:34,240
So what will we our base case.

32
00:01:34,240 --> 00:01:37,310
So base case is the smallest problem whose solution we already know.

33
00:01:37,630 --> 00:01:40,050
So suppose if the value of minus zero.

34
00:01:40,900 --> 00:01:45,660
If the value of any is it also that if the power is zero then the output will be 1.

35
00:01:45,670 --> 00:01:46,860
So this will be the smallest.

36
00:01:46,870 --> 00:01:48,160
This is the base case.

37
00:01:48,220 --> 00:01:54,290
You can also take one as one also base case if X did about 1 will be X only.

38
00:01:54,320 --> 00:01:59,130
Okay so it is our choice you can pick this one and you can also take this one.

39
00:01:59,260 --> 00:01:59,540
Okay.

40
00:01:59,640 --> 00:02:01,930
You can take both our choice.

41
00:02:01,930 --> 00:02:07,920
Okay so let's write the code for it.

42
00:02:07,950 --> 00:02:10,570
So what I want to do I want to calculate.

43
00:02:10,650 --> 00:02:16,630
So there that I will be in danger the name of the function is powered it will take 2 in digit.

44
00:02:17,060 --> 00:02:21,990
I want to find extra the power in now what is the base case.

45
00:02:21,990 --> 00:02:25,850
So first of all base case.

46
00:02:25,850 --> 00:02:30,990
So base case will be the smallest problem whose solution we already know.

47
00:02:31,630 --> 00:02:36,490
So the smallest problem will be if the value of any 0 because and is a whole number.

48
00:02:36,490 --> 00:02:40,090
Okay so the smallest really often will be zero only.

49
00:02:40,090 --> 00:02:41,510
So if the value of any 0.

50
00:02:41,530 --> 00:02:45,590
What I have to do I have to return 1.

51
00:02:45,670 --> 00:02:46,530
Okay.

52
00:02:46,570 --> 00:02:54,590
And now our recursive case so recursive case we already decided what we will do.

53
00:02:54,700 --> 00:02:56,720
I will call on and minus 1.

54
00:02:56,740 --> 00:02:57,050
Okay.

55
00:02:57,070 --> 00:02:58,390
So our small output.

56
00:02:58,660 --> 00:03:09,450
Okay so the small output it will be I want to find extra the power in minus one.

57
00:03:09,630 --> 00:03:10,530
So add this line.

58
00:03:10,530 --> 00:03:12,850
We have extra about N minus one.

59
00:03:13,290 --> 00:03:20,180
Now after we have extra the power and minus one we have to do other conclusion part so what is our conclusion

60
00:03:20,190 --> 00:03:30,110
but basically I will return X Multiply small output Okay and let's call let's test our function.

61
00:03:30,150 --> 00:03:34,540
Suppose I want to find 5 to the power tree.

62
00:03:34,620 --> 00:03:39,600
Okay so five cube so five cube will be 125 okay.

63
00:03:39,830 --> 00:03:46,860
So let's say our file so our output is 125 solver code is working fine.

64
00:03:46,870 --> 00:03:50,460
Okay now we will write in our code after writing the code.

65
00:03:50,860 --> 00:03:51,950
So we think and learn.

66
00:03:52,000 --> 00:03:54,040
We think only in terms of PMI.

67
00:03:54,040 --> 00:03:56,500
And then after writing the code what do we do.

68
00:03:56,530 --> 00:03:57,600
We will dial in our code.

69
00:03:57,610 --> 00:03:58,590
We will make the diagram.

70
00:03:59,590 --> 00:04:00,050
Okay.

71
00:04:00,190 --> 00:04:02,720
So I want to find 5 2 about three.

72
00:04:02,740 --> 00:04:07,030
So what will happen this is 5 and this is 3 okay.

73
00:04:07,090 --> 00:04:12,150
So the value of x is not changing only the value of end is changing so I am writing only 3 here.

74
00:04:12,190 --> 00:04:18,050
Okay so this is 3 so 3 is not close to zero.

75
00:04:18,050 --> 00:04:22,840
So I will come at this line so and minus when we are calling 1 and minus 1.

76
00:04:22,850 --> 00:04:25,910
If you want you can also write 5 or so okay so 5.

77
00:04:25,910 --> 00:04:26,840
Commentary.

78
00:04:26,840 --> 00:04:29,010
Now this is 5 comma 2.

79
00:04:29,080 --> 00:04:32,030
Again we will call on 5 comma 1.

80
00:04:32,070 --> 00:04:35,280
Now we will call on 5 comma 0.

81
00:04:35,280 --> 00:04:36,270
Okay.

82
00:04:36,270 --> 00:04:40,950
If the value of end is it overtime returning I am returning 1 so this will return 1.

83
00:04:40,950 --> 00:04:47,520
Okay so our small output this is 1 then I am returning X Multiply small output so the value of x is

84
00:04:47,550 --> 00:04:50,220
5 so 5 multiply 1.

85
00:04:50,400 --> 00:04:51,910
So this will be 5.

86
00:04:51,990 --> 00:04:59,830
So our small output is 5 then I am returning X Multiply small output so 5 multiply 5.

87
00:05:00,060 --> 00:05:02,200
So I will return 25.

88
00:05:02,220 --> 00:05:09,670
So our small output is 25 then I am returning X Multiply small output so 5 multiplied 25.

89
00:05:09,930 --> 00:05:15,720
So it will return when 25 and 5 cube is 125 so I will our it is working fine.

90
00:05:15,760 --> 00:05:19,480
Okay so this will be their diagram okay.

91
00:05:19,680 --> 00:05:25,050
So I hope by this time we know the procedure first we have to write the code and after writing the code

92
00:05:25,710 --> 00:05:26,430
and when.

93
00:05:26,430 --> 00:05:29,730
And while we are writing the code will think only in terms of PMI.

94
00:05:29,730 --> 00:05:31,700
After writing the code we will draw this diagram.

95
00:05:31,710 --> 00:05:34,510
Okay too so that we can understand it better be.

96
00:05:34,590 --> 00:05:43,650
Okay so this is our code so base case our small output which is really recursive case and then our calculation

97
00:05:43,650 --> 00:05:44,220
part.

98
00:05:44,220 --> 00:05:48,990
So this is how this code is working this is how we calculate power function this is how we can read

99
00:05:48,990 --> 00:05:50,070
about using recursion.

100
00:05:50,460 --> 00:05:50,960
Okay.

101
00:05:51,120 --> 00:05:51,510
Thank you.
