1 00:00:01,490 --> 00:00:02,190 Hello, everyone. 2 00:00:02,210 --> 00:00:08,450 So in this video, we will try to solve one more recursion problem, so I want to calculate power. 3 00:00:09,280 --> 00:00:16,910 OK, so I want to calculate X to the power and OK, so X is any number and and is a whole number. 4 00:00:16,910 --> 00:00:18,920 That is zero one, two and so on. 5 00:00:18,980 --> 00:00:22,490 OK, so suppose I want to calculate five to the power three. 6 00:00:22,500 --> 00:00:26,480 So this will be five to five and to five which is 125. 7 00:00:26,760 --> 00:00:28,940 OK, so I want to calculate power. 8 00:00:28,970 --> 00:00:34,340 OK, so what I want to do, I want to, I want to write a power function and I want to find X to the 9 00:00:34,340 --> 00:00:39,890 power and OK so X is any number and N is a whole number. 10 00:00:40,340 --> 00:00:42,400 OK, so how we can solve this problem. 11 00:00:42,830 --> 00:00:45,810 So first we have to think of the recursive case. 12 00:00:45,830 --> 00:00:46,430 OK, so. 13 00:00:47,590 --> 00:00:53,710 What is extra the power and so can we write it like this x multiply the power and minus one. 14 00:00:54,430 --> 00:01:01,810 OK, so we can write it like this, extra the power and is calculate extra power and minus one and then 15 00:01:01,810 --> 00:01:02,920 multiply X. 16 00:01:03,320 --> 00:01:05,230 OK, so we have to. 17 00:01:05,860 --> 00:01:09,550 So I want to calculate the bigger problem than I have to calculate the smaller problem. 18 00:01:09,560 --> 00:01:11,170 So this will be our recursive case. 19 00:01:11,890 --> 00:01:12,970 OK, so. 20 00:01:14,140 --> 00:01:22,510 If I want to find extra power in what I will do, first of all, I will find extra power and minus one 21 00:01:23,200 --> 00:01:25,210 and then I will multiply. 22 00:01:26,160 --> 00:01:28,860 OK, so this is our recursive case. 23 00:01:28,870 --> 00:01:30,730 This will be our recursive case. 24 00:01:31,450 --> 00:01:33,880 OK, so what will be our base case? 25 00:01:34,150 --> 00:01:35,980 So base case is the smallest problem. 26 00:01:35,980 --> 00:01:37,250 Whose solution we already know. 27 00:01:37,550 --> 00:01:44,770 So suppose if the value of any zero, if the value of any is also that if the power is eroding the output 28 00:01:44,770 --> 00:01:45,240 will be one. 29 00:01:45,640 --> 00:01:46,850 So this will be the smallest. 30 00:01:46,870 --> 00:01:47,850 This is the best case. 31 00:01:48,130 --> 00:01:50,020 You can also take one as one. 32 00:01:50,020 --> 00:01:54,130 Also be asked if xda Power-One will be X only. 33 00:01:54,320 --> 00:01:55,890 OK, so it is our choice. 34 00:01:55,900 --> 00:01:59,330 You can take this one and you can also take this one, OK. 35 00:01:59,480 --> 00:02:01,600 Or you can take both our choice. 36 00:02:01,840 --> 00:02:04,240 OK, so let's write the code for it. 37 00:02:07,860 --> 00:02:13,920 So what I want to do, I want to calculate, so I will be under the name of the function is powered. 38 00:02:15,020 --> 00:02:16,570 It will take 20 years. 39 00:02:16,970 --> 00:02:18,980 I want to find extra power in. 40 00:02:20,670 --> 00:02:23,010 Now, what is the best case, so first of all. 41 00:02:25,130 --> 00:02:26,300 Bakkies, so. 42 00:02:27,820 --> 00:02:33,430 Best case will be the smallest problem or solution we already know, so the smallest problem will be 43 00:02:33,460 --> 00:02:36,100 if the value of any zero because it is a whole number. 44 00:02:36,370 --> 00:02:39,450 OK, so the smallest often will visit only. 45 00:02:40,030 --> 00:02:45,160 So if the value of any zero, what I have to do, I have to return one. 46 00:02:45,560 --> 00:02:48,910 OK, and now our recursive case. 47 00:02:50,950 --> 00:02:53,780 So recursive case, we already decided what we will do. 48 00:02:54,610 --> 00:02:56,240 I will go alone and minus one. 49 00:02:56,590 --> 00:02:58,360 OK, so I have a small output. 50 00:02:58,570 --> 00:03:00,370 OK, so a small. 51 00:03:02,150 --> 00:03:04,280 Output, it will be. 52 00:03:05,280 --> 00:03:14,100 I want to find extra power in my istván, so at this line we have extra power and minus one now after 53 00:03:14,100 --> 00:03:17,310 we have extra power and minus one, we have to do our calculation part. 54 00:03:19,010 --> 00:03:24,350 So what is our calculation, but basically I will return X, multiply small output. 55 00:03:25,560 --> 00:03:29,370 OK, and let's call let's test our function. 56 00:03:30,090 --> 00:03:34,140 Suppose I want to find five to the power three. 57 00:03:34,480 --> 00:03:38,040 OK, so five cube, so five cube will be 125. 58 00:03:38,930 --> 00:03:41,420 OK, so let's turn our file. 59 00:03:43,780 --> 00:03:46,810 So our output is 125, so our goal is working fine. 60 00:03:46,840 --> 00:03:49,980 OK, now we will try to our goal after writing the code. 61 00:03:50,800 --> 00:03:56,110 So we think we think only in terms of PMI and then after writing the code what we do. 62 00:03:56,470 --> 00:03:57,580 We looked at another quote. 63 00:03:57,580 --> 00:03:58,610 We will make the diagram. 64 00:03:59,500 --> 00:04:02,310 OK, so I want to find five to about three. 65 00:04:02,680 --> 00:04:03,550 So what will happen? 66 00:04:03,550 --> 00:04:05,260 This is five and this is three. 67 00:04:06,400 --> 00:04:10,480 OK, so the value of X is not changing, only the value of it is changing. 68 00:04:10,480 --> 00:04:11,980 So I am writing a letter here. 69 00:04:12,160 --> 00:04:15,400 OK, so this is three. 70 00:04:16,399 --> 00:04:22,340 So three is not close to zero, so I will come at this lane so and minus when we are calling one and 71 00:04:22,340 --> 00:04:23,300 minus one if you want. 72 00:04:23,330 --> 00:04:26,400 You can also write five also Kaso five commentary. 73 00:04:26,750 --> 00:04:28,200 Now this is five Camarda. 74 00:04:28,880 --> 00:04:30,950 Again, we will call on five Gormogon. 75 00:04:31,980 --> 00:04:38,940 Now we will call on five zero, OK, if the value of an asset over time returning, I'm returning one, 76 00:04:38,940 --> 00:04:40,050 so this will return one. 77 00:04:40,850 --> 00:04:46,560 OK, so our small output decision then I am returning X multiplier, small output. 78 00:04:46,560 --> 00:04:47,920 So the value of X is five. 79 00:04:48,180 --> 00:04:49,850 So five multiply one. 80 00:04:50,310 --> 00:04:51,700 So this will be five. 81 00:04:51,930 --> 00:04:54,530 So our small output is five. 82 00:04:55,380 --> 00:04:57,240 Then I am returning X multiplier. 83 00:04:57,240 --> 00:04:57,930 Small output. 84 00:04:57,960 --> 00:04:59,570 So five multiply five. 85 00:05:00,000 --> 00:05:02,200 So I will return twenty five. 86 00:05:02,230 --> 00:05:07,280 So our small output is 25 then I am returning X multiplier small output. 87 00:05:07,320 --> 00:05:08,860 So five multiplied. 88 00:05:08,880 --> 00:05:09,480 Twenty five. 89 00:05:09,870 --> 00:05:14,420 So it will return one twenty five and five cube is 125. 90 00:05:14,430 --> 00:05:15,690 So I will call this working fine. 91 00:05:15,720 --> 00:05:17,190 OK, so this will be the diagram. 92 00:05:18,780 --> 00:05:24,600 OK, so I hope by this time we know the procedure, first we have to write the code and after writing 93 00:05:24,600 --> 00:05:29,640 the code and when and while we are writing the code, will think only in terms of PMI. 94 00:05:29,640 --> 00:05:34,280 After writing the code, we will draw this diagram OK, too, so that we can understand it better. 95 00:05:34,530 --> 00:05:36,780 OK, so this is our code. 96 00:05:37,740 --> 00:05:43,920 So best case of a small output, which be the recursive case and then our calculation part. 97 00:05:44,160 --> 00:05:45,950 So this is how this code is working. 98 00:05:45,960 --> 00:05:47,730 This is how we calculate power function. 99 00:05:48,090 --> 00:05:50,100 This is how we can read about using recursion. 100 00:05:50,370 --> 00:05:51,540 OK, thank you.