Link to the Notes of Class: drive.google.c... Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++... Telegram: t.me/apnikaksh... Instagram: / dhattarwalaman My RU-vid Gear 😉: docs.google.co...
Really great tutorial i really stuck in recursion but when you teach with very basic questions i really understood it well with what happens in background coding how recursion works 👍☺️☺️👏🙌
This is hands down the most comprehensive lecture for me ! Thank you for making such a high quality, lucid and brilliant explanation video on RECURSION, Your channel is Subscribed right away !
1:24:04 below code works perfectly fine for both even and odd number, no need of using if else condition(if I'm wrong then run this code without condition) public static int optimisedFunc(int n, int power){ if(power == 1) return 1; return (n * optimisedFunc(n, power/2) * optimisedFunc(n, power/2)); }
For sum of n natural numbers, i guess correct way with recursion is.. public class Recursion { public static int printSum(int n) { if(n==1) { return 1; } return n + printSum(n-1); } public static void main(String[] args) { int n = printSum(5); System.out.println(n); } }
Great Great great Job!!!!. Actually Recursion is the toughest logic to implement and the way you teach specially coding in which u need to develop the thought process along with the problems.....you did it so well.....and in very simple way...... I have seen lot of videos on you tube but it is the BEST ONE !!!!great Contribution to community!!! Keep up the good work!!!!
I didn't know Java language but still learning this video because C++ playlist has good content but not for beginainers But it is need more video like this on ds algo
just use ternary operator n == 1 || n == 0 ? return 1 : n * factorial(n-1) ; 2 lines of code in just one line using ternary Thanks mam to make recursion easy to understand
Thank you so much all team members of aman bhiya aman bhiya you are doing really really really great work . when i wached apna college then i feel I'm graduating form Apna college institute of engineering and technology
Another method for factorial using Recursion; static void fnc2(int n, int sum){ if(n == 0){ // BASE CASE System.out.println(sum); return; } sum *= n; // ACTION fnc2((n-1), sum); // sum will not change for each recursive step }
I am in Coding Ninja Coding boot camp, but they teach like, only doing there job. For understand the fundamentals and concepts, I always prefer Apn college. Very Easy explanation ❤❤❤
public static int printSum(int n){ if(n ==0){ return 0; } else{ return n+ printSum(n-1); } public static void main(String args [ ] ){ int n =5; int ans = printSum(n); syso(ans); } An easy and better code for printing sum of n numbers using recursion
Hi shardha in function calpower we dont require to chk the condition for x since we are not editing it also the height of the stck can be reduced by adding a basecase of if(n==1) return x; so the height will be n-2 here pls correct if anything wrong Thankyou
Last question is so dengerious..Didi🙂dimag nehni chalapaya us type ke question par...but rest of the question are easy to catch...thanks for sharing this type of difficulty label class...❤❤❤
Another method to find factorial(similar to sum of n numbers.) public class fact { public static void factNumber(int n, int fact){ if (n == 0) { fact *= (n+1); System.out.println(fact); return; } fact *= n; factNumber(n-1, fact); } public static void main(String[] args){ factNumber(5, 1); } }
ma'am can we print the numbers from 1 to 5 by using this code public class recursion1 { public static void printNum(int n) { if(n==0){ return; } printNum(n-1); System.out.println(n); return; } public static void main(String[] args) { int n=5; printNum(n); } }
Hi Shraddha, I think the time complexity for the last question to calculate x^n is O(n) instead of O(logn) beacuse we are calling calcPower twice in the return statement. If we store the value of calcPower after calling it once in temporary variable and multiple with itself and return this will help in the time complexity reduce to O(logn).
53:57 We can also do this if we dont want to do anything in the main class - public class fibonacci { public static void main(String[] args) { int z = 5; int a = 0; int b = 1; int c = 0; calcFibonacci(a, b, c, z); } public static void calcFibonacci(int a,int b,int c,int z){ if(z==0){ return; } c = a+b; System.out.print(a); System.out.print(b); System.out.print(c); a = b+c; b = c+a; calcFibonacci(a, b, c, --z); } }
In x^n question can we do it this way: public class recursionOne { public static void pow(int pro, int x, int n) { if (n==0) { System.out.println(pro); return; } pro*=x; pow(pro, x, n-1); } public static void main(String[] args) { pow(1, 1, 0); } }
Easiest code for Sum of n Natural No:- class jjsr{ public static int sum(int n){ if(n==0){ return 0; } return n + sum(n-1); } public static void main(String[] args) { int n=10; System.out.println(sum(n)); } }
In last question Calculate power: calcPower(x,n/2) was called twice, this can be optimised by storing the value in a variable. Overall very good video. Thankyou!
thank you so much shraddha. finally beacuse of you i could understand functions and recursions in a very interesting and an easy manner. one small request-if you could make a series like java for various individual topics for python,it will be a great great help
Hello guys! I am from Pakistan. I am learning java from this channel and she is one of the best teachers on RU-vid . The way she explains it is exceptional. I found this channel very valuable
I guess there is one issues in the stack height log(n) problem For each call to printPower, if 𝑛 is not zero, the function makes two recursive calls to printPower(x, n / 2). This results in an exponential number of calls and a stack height proportional to 𝑛, since each call spawns two more calls without reducing the problem size sufficiently. To achieve a stack height of log(𝑛), you should make only one recursive call in each step and use the result to compute the final power. public class powerWithStackHeightLogN { public static int printPower(int x, int n) { if (n == 0) { return 1; } int halfPower = printPower(x, n / 2); if (n % 2 == 0) { return halfPower * halfPower; } else { return x * halfPower * halfPower; } } Please have a look into this....
In the last question it was very tough to understand and i couldn't find anyone who can dry run this and explains 1. how calcpower (x , n/2) is able to return a value while what to do in function isn't defined 2. What if n==1 , bcoz it isn't the base condition . So if anybody who is stucked in there reply your question here . And many many thanks to Microsoft wali didi for exposing us to such types which aren't available in such a easy language
your teaching is FAB . I will join college this year and i am looking forward to watch your videos through my whole journey. Thank you for this amazing playlist didi..
public class Recursion { public static void printfact(int i, int n , int fact){ if(i==n){ fact *=i; System.out.println(fact); return ; } fact *= i; printfact(i+1,n,fact); } public static void main(String args[]){ printfact(1,6,1); } }
fibonachi series uptil n numbers public class Main{ public static void fiboSeries(int a,int b,int n){ if(n==0){ return; } int c=a+b; a=b; b=c; System.out.println(c); fiboSeries(a, b, n-1); } public static void main(String args[]){ int a=0; int b=1; int n=5; System.out.println(a); System.out.println(b); fiboSeries(a, b, n-2); } }
public static int printSum(int n , int m){ if(n ==m){ return m; } else{ return n+ printSum(n-1 , m); } } public static void main(String args [ ] ){ int n =5; // 3+4+5 = 12 int m = 3; // print sum from 3 to 5 int ans = printSum(n , m); syso(ans); } To print sum of number between m to n by recursion method
factorial ke liye i did this. public static void Factorial( int n, int fac){ if(n==0){ System.out.println(fac); return; } fac = fac*n; Factorial(n-1, fac); }
You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K. How to solve this problem using recursion?