Recursion in One Shot | Theory + Question Practice + Code | Level 1 - Easy
Vložit
- čas přidán 31. 08. 2021
- Link to the Notes of Class: drive.google.com/file/d/1dM-V...
Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++...
Telegram: t.me/apnikakshaofficial
Instagram: / dhattarwalaman
My CZcams Gear 😉: docs.google.com/document/d/1p...
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);
}
}
what happens when we do return 1;
?
@@paragshende3390 when there is a function call (new stack frame) with n==1 then 1 is returned back to stack frame from where this call is made
this is simple way to calculate sum of n number which you explained.good job
Stack height concept you have tought was nothing anywhere generally...so thank you for such intuition.
Fibonacci series: 47:56
Power calculation : 1:00:13
Power calculation in optimized way : 1:12:00 ( log n) its code is : 1:22:40
czcams.com/play/PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q.html
Vaiii 46:56
czcams.com/video/qWx5ZAFkSfk/video.html
Thnx buddy
Need this type of practice question in every topic. Hope you continue like this. And thanks for this awesome session😍
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 👍☺️☺️👏🙌
Are you completing your college 😊
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!!!!
"JEE PREP HO YA COLLEGE KI PADHAI, ONE SHOTS ARE THE BEST!!"😂😂👌
How it's taking n as power ?? Like there is math.pow to that we can use power how this happen here??
😂😂
Wah wah wah wah
😂😂😂😂
@@just.indianstuff7537 yeah I also didn't understand this .how this is possible??
You guys are creating such a valuable content and providing it for free, also motivating us to be better in our fields, hats off to Aman and Shraddha.
VARANASI SARALA PUUKU MUNDADHI
Very valuable feedback for them
czcams.com/video/qWx5ZAFkSfk/video.html
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 !
Thank god you said that... I had my hands up this whole time :(
@@uskapyaar8852 😂😂😂😂
czcams.com/video/qWx5ZAFkSfk/video.html
Didi, backtracking ke upar bhi dedicated playlist banaiye please
we want marathon on backtracking 🔥🔥🥰🥰
Yes
Need a complete course on java like the c++ complete series
Which college
@@prshark84 apna college
Please make whole series
JAVA DS+ALGO 🥳
khush to bhut hoge ab tum
at 30:30
public static int sum(int n){
if (n==0) {
return 0;
}
return n+sum(n-1);
}
is more convinient
Without 3 variable, you can also use
Thank you so much for explaining recursion in such simple yet detailed manner.
Aman bhaiya c++ pe practice 500 questions Ki serie banvado please 🙏🙏🙏 garib ko placement lag jayegi
Babbar's 450 ques is best for placements👍
@@KaranKumar-vm2we Haan vahi solution bi chayie😅
@@KaranKumar-vm2we oh no oh no oh no no no..!
Abe kisi ke bhi DSA sheet utha kar kar le uske baad kitne bhi solve karte beth
@@KaranKumar-vm2weBhai Java ke liye questions kaha milega...
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
This is something we can call Recursion
Thanku Di and thanku Aman bhaiya to bring such people for us❤🔥
i can't explain how easily i was able to understand recursion in this video with time complexity,
thanks a lot to you ma'am
czcams.com/video/qWx5ZAFkSfk/video.html
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
Didi please🤓 kindly make a 💢complete "Java Programming+DSA" course😎,I am not able to understand the C++ course, please it's an humble request 🙏
This is the best video on recursion. Thank you so much.
You are amazing! I am a 52 years old but i understand the concepts very well because of you. Thanks!
52 ? And learning java ..? I mean for what ? 😅
@@i.khushii maybe because the institute asked her to my oops teacher was in same position
czcams.com/video/qWx5ZAFkSfk/video.html
thoda mushkil hai
🥺🥺🥺🥺🥺
🐭🐭🐭🐭🐭
Sidha recursion padhoge toh lagega hi
Step by step basic se karo warna karo mat
Same
@@mridulsd2023ye depend krta h
Me is sal hi college jaunga to thoda mushkil lag rha h mene Kiya h basic se pura fir bhi 😢
really informative...the way you are teaching to students its quite commendable .hats off
factorial vala question sum of n natural numbers se bhi ho jayega bus sum=1 kardo and + ki jgeh * kardo
Now quality comes
Very Helpful
Thank you so much for explaining recursion in such a simple yet detailed manner.
Best explanation ever..
Finally i understand recursion... 🥳🥳🥳🥳
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
In the last problem, in the even part, it should be if(n==1) return x; Otherwise coz of the n==0 we get x^0=1 then x^1 will be equal to 1 and so on...
I think if we take base condition in question of x^n (stack height = n) as if n = 1 return x; then we can achieve exact stack height of (n)
You are one of the best online teacher. Thank you for making such videos.
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
}
maam your way of explanation is such a awesome .....alll my doubts getting cleared from your lectures.....really thanks alot maam for such quality content.
I have learned first time , I have to build a great understanding of recursion thank u very much and also keep it up,
for the question : print x^n (!st one)...how is the power happing in calcpower(x,n-1)....is it being used as math.pow?
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 ❤❤❤
Thanks for this amazing explanation on recursion
Perfectly explained each question, last question was mind blowing!
I usually don't comment on videos but I have to say the explanation is mind-blowing
I cannot thank you in words🥰
In last and second last problem we can change first base case to... If(n==1) return x;... So that no of levels and value of n remains same...
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
mughe toh yeh easy level bhi samajhne mein dikkat horhi haiii🙁
Thank you didi for this tutorial,you really calm me down by saying that it's ok to get intimidated by questions like these ,take your time and understand it
Great explanation! Best lecture of recursion on you tube.
VARANASI SARALA PUUKU MUNDADHI
your teaching skills touch every one's mind every time
for find factorial we can use return n * fact(n-1)
base condition if(n == 0) return 1 ;
this is simple way to print factorial
most amazing video ever watched about recursion all concept gets cleared thanks bhaiya and didi.
di ek linux one shot lekar aao. it will many students
We need python course
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));
}
}
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);
}
}
Han but jyada lagega though yhan ye itna jyada nhai hai but take a big no. For consideration.
Yes we need a dedicated playlist on backtracking topic 👍
@masskie star this video is not available, but why?🙄
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?
Awesome teaching style. Great illustrations. Keep it up. 👍🤘🙂
czcams.com/video/qWx5ZAFkSfk/video.html
Thank you so much, mam it's too good 👍 learning 📕 platform
I didn't understand the last problem, how it works...
You have explained one of the complex topic in a very smooth way. Very Thankful🥰
czcams.com/video/qWx5ZAFkSfk/video.html
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).
VARANASI SARALA PUUKU MUNDADHI
31:06 instead of sum+=i we can do (i==n+1) and then print sum then return.
Kitna aacha samjaya h apne didi.
Thankyou so much to making a good start in recursion.
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);
}
}
Amazing content. Everything is explained in a very easy to understand way. Thanks alot
It was detailed and well explained video which cleared all my doubts
finally java + DSA 🥰🥰🥰
thanks di..for such a brief and excellent explanation!!keep it up
Waiting for this video from lot of time. Thanks 🤗
Amazing lecture mam. thank you 🙏🙏
Hello sister we need more videos like this java.... Thank you for your previous videos
Thank youu dii..bas aise hi continue rkhna ab please 🥺❤️
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
VARANASI SARALA PUUKU MUNDADHI
✨✨
czcams.com/video/qWx5ZAFkSfk/video.html
Bhaiya kaha se start karu samjh hi ni aa raha ki kaha se padhu ..
czcams.com/play/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ.html
Thanks mam ,this video really helped me to understand the recursion . Explanation is superb.
i am trying to understand recursion from many resources but finally understand now.thanks
Please make a series of java, we would be really thankful to you cause the way you are explaining things it's just too easy to get you.
++
@@mrbob2148czcams.com/play/PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q.html
Can someone help me on how in last example these two recursive function calls are executing in the same stack?
like when it is odd number calcPower(x,n-1)*calcPower(x,n-1)*x then how they are using same stack for execution ? we are calling them twice then how?
please guide me on this.
great appreciation for your hardwork!!
Bhagwan apka bhala kre... recursion ko detail se smjhane ke liye apka bahut bahut dhanyawad..
Didi aapka contents PHYSICS WALLAH ke tarah hai...... High quality content of explaining, thank you didi....
I have some doubt on stack level of log^n to calculate power of x^n. Whenever any function called from the program it will take one stack place in stack memory right then how it's reducing the level of stack to log^n from x^n. could you please provide one resource for functions stored in stack memory.
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!
Microsoft wali didi Zindabad 🇮🇳🇮🇳
why doesn't the sys.out(i) printed initially when the method was calling after increasing the value of i
instead, printed after the value of the sum printed ? (in the question - print sum of n no.)
Sum of n numbers another solution:
import java.util.*;
public class sample {
public static int sum(int n) {
if (n == 0) {
return 0;
}
return n + sum(n - 1);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int res = sum(n);
System.out.println(res);
}
}
calculate power another method easy :
class test{
public static void main(String[] args) {
power(2, 3, 1);
}
public static void power(int a, int n, int c){
if(n
The first code example of recursion is not working in Intellij Idea.....
Print statement in the void printnum function is showing unreachable statement.
Code--
public static void printnum (int n) {
(n == 0);{
return;
}
System.out.println(n); // It is showing unreachable statement
printnum(n-1);
}
public static void main(String[] args) { int m = 5;
printnum(m);
Please make the Python Course with DSA just like the C++ course. It will be very helpful 🤞
I also want python course with DSA
Yes absolutely we want python dsa
DSA concept is same everywhere but in languages writing of code is different.
dsa is same for all langauge infact it is not for one langauge ...concept same hai just acc to lanaguage chize change krni hoti hai
@@atharvak1503 dsa is same for all langauge infact it is not for one langauge ...concept same hai just acc to lanaguage chize change krni hoti hai
You are Best Teacher Ever..main to aapka all time wala Fan ho gaya...now Recursion is Clear...
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);
}
}
Probabily the best teacher in the world for computer science student.
*probably
When we pass x and n-1, how the the recursive function know to perform x^n-1 and not some other operation on it?
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
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
same doubt, if u got to know the answer please explain to me
Slowly aur easily padhaya hai awesome 😀
I have a doubt
how can we write "return" only? is it not wrong in eclipse ? or instead of return , return 0 or return 1 can't be written?
Lots of love to your lactures seriously now I am able to learn recursion otherwise I was thinking recursion is not my type 😂
the explanation is very simple .thank you so so much for this videos .
Bestest Video On Recursion ❤
Ma'am plz explain this:-- humne to math. Pow use nhi kiya to calcpower kese output dera hai??
I'm learning python but after watching this session all debut cleared. related to the same topic. thanks