1 00:00:00,330 --> 00:00:01,710 Hi this is rings in the heart. 2 00:00:01,710 --> 00:00:08,120 And welcome to the next VUDU of functions in Cartland in this video very talk about that Theodoric functions 3 00:00:08,140 --> 00:00:09,780 in case of Cartland. 4 00:00:09,780 --> 00:00:18,720 So this function uses recursion in more optimized way than any other language such as Java or C programming 5 00:00:18,750 --> 00:00:19,950 and so on. 6 00:00:19,950 --> 00:00:21,950 Now what does the meaning of recursion. 7 00:00:22,140 --> 00:00:26,140 Recursion means calling its own function from within the function. 8 00:00:26,280 --> 00:00:31,530 That is the real call of function from inside its own function. 9 00:00:31,530 --> 00:00:37,860 Now in case of Arlan whenever we call the same function multiple number of times such as hundreds of 10 00:00:37,860 --> 00:00:44,100 thousands of time then that recursive process is actually optimized and the Cartland simply prevents 11 00:00:44,160 --> 00:00:50,760 the stack overflow exception because calling the same function recursively can simply blow up the stack 12 00:00:50,760 --> 00:00:51,310 memory. 13 00:00:51,330 --> 00:00:58,340 So in that case the Cartland simply optimize the code call the function recursively write and not try 14 00:00:58,330 --> 00:00:59,910 to find a direct function. 15 00:00:59,910 --> 00:01:03,410 We have to use the keyword of the wreck. 16 00:01:03,480 --> 00:01:09,010 Now inside the intelligent ID I would simply write my code to find the one that uses. 17 00:01:09,030 --> 00:01:14,940 Now what do you mean by the Fibonacci series is that suppose I have the number 0 and the next number 18 00:01:14,940 --> 00:01:15,850 is then. 19 00:01:15,870 --> 00:01:20,590 So the next number will be the sum of 1 and 0 that is when again. 20 00:01:20,760 --> 00:01:23,940 And the next number will be one place of an equal to. 21 00:01:24,090 --> 00:01:32,790 And then we will have two plus one such as three similarly triplets two such as five and next will be 22 00:01:33,390 --> 00:01:34,790 five blistery eight. 23 00:01:35,130 --> 00:01:41,730 And then it plays 5:13 and so on like this let's see 21 right. 24 00:01:41,900 --> 00:01:43,430 And the series goes on. 25 00:01:43,430 --> 00:01:49,310 So let us write a program to find a key cities so far that leads do find function. 26 00:01:49,490 --> 00:01:54,380 So here I have simply defined a method of good food when I can number at the end its position. 27 00:01:54,440 --> 00:01:54,930 Right. 28 00:01:55,160 --> 00:02:00,540 And here I am busting to prime readers of in be that determines the starting point of the Fibonacci 29 00:02:00,540 --> 00:02:02,080 in cities such as zero. 30 00:02:02,090 --> 00:02:07,400 And when these two values we have to give so that we can get that third number right by adding these 31 00:02:07,400 --> 00:02:08,480 two numbers. 32 00:02:08,690 --> 00:02:12,440 And now this simply returns the value or the food when I can. 33 00:02:12,530 --> 00:02:14,430 But at the end its position. 34 00:02:14,430 --> 00:02:16,130 Suppose I-PASS six. 35 00:02:16,160 --> 00:02:18,680 So the sixth number is actually eight. 36 00:02:18,830 --> 00:02:22,700 So this function will simply return it. 37 00:02:22,750 --> 00:02:23,280 Right. 38 00:02:23,390 --> 00:02:26,370 Now here I am using the big integer. 39 00:02:26,390 --> 00:02:33,080 No the purpose of using the big Indeed it is that this big integer class can hold a very large number 40 00:02:33,170 --> 00:02:34,970 or in bigger value. 41 00:02:35,150 --> 00:02:40,410 So you can call this big endangered as the big boss of the entire class. 42 00:02:40,430 --> 00:02:44,390 Right and now here I am simply writing so as condition. 43 00:02:44,570 --> 00:02:51,680 So if part is totally understandable but here in the is part you can see I'm simply calling Guert Fibonacci 44 00:02:51,680 --> 00:02:55,610 number which is actually its own method here. 45 00:02:55,610 --> 00:02:56,160 Right. 46 00:02:56,420 --> 00:03:02,580 So if there is Fargus exec you did it simply execute this method again recursively. 47 00:03:02,810 --> 00:03:06,340 So the recursion goes on like this in finite number of times. 48 00:03:06,350 --> 00:03:08,660 Suppose if this is 10000. 49 00:03:08,660 --> 00:03:12,120 So it will simply loop through 10000 times like this. 50 00:03:12,170 --> 00:03:12,930 Right. 51 00:03:12,950 --> 00:03:16,500 And now here let us solve this error by simply placing it less. 52 00:03:16,540 --> 00:03:19,940 And so simply import the biggest danger right. 53 00:03:20,130 --> 00:03:25,880 And now from inside the main method I would simply call this method so as to get the key number. 54 00:03:25,880 --> 00:03:32,360 So here this is my main method insert which I'm simply calling print Ellen get when I number and simply 55 00:03:32,360 --> 00:03:34,100 passing 5 as a barometer. 56 00:03:34,160 --> 00:03:36,360 And the starting position as 1 and 0. 57 00:03:36,380 --> 00:03:37,140 Right. 58 00:03:37,280 --> 00:03:42,830 If I add in the call right now I will get Let's see some value among these numbers represent at the 59 00:03:42,830 --> 00:03:43,820 fifth position. 60 00:03:43,820 --> 00:03:47,720 So let us note in the chord and here we get five as output. 61 00:03:47,720 --> 00:03:50,740 So their distress their defense their distress 7. 62 00:03:50,760 --> 00:03:52,050 And let's see what happens. 63 00:03:53,170 --> 00:03:54,570 And here we get 13. 64 00:03:54,580 --> 00:03:58,090 So at the seventh position we have 13 right. 65 00:03:58,150 --> 00:04:01,290 So the seventh number is we're getting 13. 66 00:04:01,450 --> 00:04:06,950 If we type here 8 then we will get Let's see 21 like that. 67 00:04:06,950 --> 00:04:09,080 So the series goes on like this. 68 00:04:09,080 --> 00:04:15,770 So as many times so work with any value that we will give here the far will be executed and the recursion 69 00:04:15,800 --> 00:04:16,580 will go on. 70 00:04:16,580 --> 00:04:22,030 That is that is it will simply call its own method again and again it finds that is correct. 71 00:04:22,070 --> 00:04:26,130 That is till this point gets executed right. 72 00:04:26,240 --> 00:04:30,460 Now suppose if I type your hundred Let's see what happens. 73 00:04:31,300 --> 00:04:34,150 So here we get a very big number value. 74 00:04:34,160 --> 00:04:35,740 That is a number. 75 00:04:35,980 --> 00:04:37,980 When I can them what are the 100 position. 76 00:04:37,990 --> 00:04:39,190 Is this one. 77 00:04:39,370 --> 00:04:48,470 Now if I type penthouse and let's see what happens. 78 00:04:48,500 --> 00:04:55,060 So here our program has crashed just because we have just ran out of the stack memory. 79 00:04:55,190 --> 00:05:00,200 So the Java Virtual Machine has simply printed out the stack overflow error. 80 00:05:00,320 --> 00:05:03,770 That is it has simply thrown out this error of stack overflow. 81 00:05:03,890 --> 00:05:06,210 So we are now out of stack memory. 82 00:05:06,440 --> 00:05:09,980 So this is a usual scenario in all the programming language. 83 00:05:10,010 --> 00:05:15,570 If you write the same code in case of Java Sea or C++ it was simply going to throw this error. 84 00:05:15,600 --> 00:05:19,900 Right but in Codlin that things are different. 85 00:05:19,910 --> 00:05:23,910 You can simply use that Theodoric keyword. 86 00:05:24,030 --> 00:05:27,080 So this function now becomes dactyl recursive. 87 00:05:27,120 --> 00:05:27,750 Right. 88 00:05:27,960 --> 00:05:28,880 And now here. 89 00:05:28,920 --> 00:05:31,700 Let us first try with hand-write number. 90 00:05:31,980 --> 00:05:35,810 So I guess our code will execute normally. 91 00:05:35,840 --> 00:05:37,490 So here we get the output right. 92 00:05:37,670 --> 00:05:45,140 But this time using their Teletech function if they use 10000 as any value then let's see what happens. 93 00:05:49,450 --> 00:05:55,720 So in the output we have very few which number what I need and this number goes on till the end. 94 00:05:55,900 --> 00:05:59,300 You cannot find the end right here because the number is too large. 95 00:06:00,030 --> 00:06:06,890 So in Scotland we have our deal direct function direct simply exit cutes the recursion internally. 96 00:06:07,170 --> 00:06:09,970 That is without affecting the stack memory. 97 00:06:10,020 --> 00:06:13,590 So without affecting the stack memory it's simply exit. 98 00:06:13,980 --> 00:06:20,940 This method recursively about 10000 number of times without affecting your application in the runtime 99 00:06:21,240 --> 00:06:22,660 by saving memory. 100 00:06:22,740 --> 00:06:23,410 Right. 101 00:06:23,520 --> 00:06:28,320 So the Gondolin provides an alternative solution for the stack overflow error. 102 00:06:28,770 --> 00:06:32,590 So this was all about the real function in case of Cartland. 103 00:06:32,910 --> 00:06:40,380 So now I guess slowly and steadily you will fall in love with Codlin because Cartland is very very powerful 104 00:06:40,500 --> 00:06:41,950 version of Java. 105 00:06:42,180 --> 00:06:44,870 Or you can see it is a future of Android. 106 00:06:44,880 --> 00:06:46,960 So thanks for watching and have a good day.