Recursion in One Shot | Theory + Question Practice + Code | Level 1 - Easy
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2025
- 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 TH-cam Gear 😉: docs.google.co...
at 30:30
public static int sum(int n){
if (n==0) {
return 0;
}
return n+sum(n-1);
}
is more convinient
yuo maine bhi esai kia
No chooping? Nahi ki?
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 😊
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
th-cam.com/play/PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q.html
Vaiii 46:56
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
Thnx buddy
Stack height concept you have tought was nothing anywhere generally...so thank you for such intuition.
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
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
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!!!!
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
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.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
Need this type of practice question in every topic. Hope you continue like this. And thanks for this awesome session😍
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 😂😂😂😂
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
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));
}
Bhagwan apka bhala kre... recursion ko detail se smjhane ke liye apka bahut bahut dhanyawad..
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 can't explain how easily i was able to understand recursion in this video with time complexity,
thanks a lot to you ma'am
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
Best explanation ever..
Finally i understand recursion... 🥳🥳🥳🥳
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
1:21:32 here when alpha is 4 then hight of stack is 3 not equal to alpha
Slowly aur easily padhaya hai awesome 😀
Probabily the best teacher in the world for computer science student.
*probably
"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 are Best Teacher Ever..main to aapka all time wala Fan ho gaya...now Recursion is Clear...
This is the best video on recursion. Thank you so much.
Hello guys! I am from Pakistan. I am learning java from this channel and she is one of the best teachers on TH-cam . The way she explains it is exceptional. I found this channel very valuable
love from India bro
Pakistani not allowed get lost 🤬
Hate from india bro🔪
I usually don't comment on videos but I have to say the explanation is mind-blowing
I cannot thank you in words🥰
This is something we can call Recursion
Thanku Di and thanku Aman bhaiya to bring such people for us❤🔥
Didi aapka contents PHYSICS WALLAH ke tarah hai...... High quality content of explaining, thank you didi....
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
Yes you are right. I also did the same
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 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 ❤❤❤
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
Without 3 variable, you can also use
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
Bestest Video On Recursion ❤
1:24:00
mam is code me ek issue hai, n (power of x) ki base condition set nhi kari, jo condition set h wo h " n==0" which is never going to possible.
solve is liye hua becuase you had an Odd number as Input.
just add one line
if(n==1){
return x;
}
31:06 instead of sum+=i we can do (i==n+1) and then print sum then return.
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.
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...
31:30 why so complicated, try this one...
import java.util.Scanner;
public class Main {
public static Scanner sc;
public static void printSum(int n, int sum){
if(n== 0){
System.out.println(sum);
return;
}
sum += n;
printSum(n-1,sum);
}
public static void main(String[] args) {
sc = new Scanner(System.in);
int n = sc.nextInt();
printSum(n, 0);
}
}
43:30 again why so complicated....
import java.util.Scanner;
public class Main {
public static Scanner sc;
public static void printFact(int n, int mul){
if(n== 0){
System.out.println(mul);
return;
}
mul *= n;
printFact(n-1,mul);
}
public static void main(String[] args) {
sc = new Scanner(System.in);
int n = sc.nextInt();
printFact(n, 1);
}
}
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
Kitna aacha samjaya h apne didi.
Thankyou so much to making a good start in recursion.
Madam your way of explaining is awesome
Thank youu dii..bas aise hi continue rkhna ab please 🥺❤️
Hello sister we need more videos like this java.... Thank you for your previous videos
Great explanation! Best lecture of recursion on you tube.
VARANASI SARALA PUUKU MUNDADHI
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));
}
}
Yes we need a dedicated playlist on backtracking topic 👍
@masskie star this video is not available, but why?🙄
You have explained one of the complex topic in a very smooth way. Very Thankful🥰
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
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...❤❤❤
The best part is you know shraddha didi hindi + English dono me hi explain kar deti hai toh smjh me bohot ache se aa jata hai 😊
public static int SumOfN(int n) {
if (n == 0)
return 0;
return n += SumOfN(n - 1);
}
public static int sum(int n){
if(n==0)
return 0;
else
return n+sum(n-1);
}
Better Time Complexity and Space Complexity
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);
}
i can gaurantee that this the best video on recursion
Another way to print factorial
public static void printFactorial(int n,int f){
if(n == 1){
System.out.println(f);
return ;
}
f *= n;
printFactorial(n-1,f);
}
public static void main(String[] args) {
printFactorial(5,1);
}
Lots of love to your lactures seriously now I am able to learn recursion otherwise I was thinking recursion is not my type 😂
Waiting for this video from lot of time. Thanks 🤗
We can also print the sum of numbers like this =>
void PrintNNaturalNumbers(int num , int sum){
if(num==0){
Console.WriteLine(sum);
return;
}
sum+=num ;
PrintNNaturalNumbers(num-1,sum);
}
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);
}
}
At 40:10
public class Main{
public static void printfact(int x , int fact) {
if(x == 0 || x== 1){
System.out.println(fact);
return ;
}
fact *= x ;
printfact(x-1 , fact);
}
public static void main(String[] args){
int x = 5 ;
int fact = 1 ;
printfact(x,fact);
}
}
bht complex krra hai faltu me tu bhay issko
Thank you, mam very good explanation.
Execellent vedio! Best 👍💯 of I've ever seen
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
Didi aaap bhot badiya padhti ho ❤️...
Concept arram se clear ho jate hai
Best lecturer in the world for me didi🙏♥️
best video i ever show of recursion
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.
++
@@mrbob2148th-cam.com/play/PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q.html
You are one of the best online teacher. Thank you for making such videos.
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!
44:00
public class recursion4FACTORIAL {
public static int intnumbers(int n){
if(n==1){
return 1;
}
return n*intnumbers(n-1);
}
public static void main (String args[]){
//int n = 5;
System.out.print("input");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(intnumbers(n));
}
} easier way try it
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);
}
}
public static void Print(int i, int n, int sum){
if(i==n || n==0)
{
sum=sum*i;
System.out.println(sum);
return;
}
sum=sum*i;
Print(i+1,n,sum);
//System.out.println(i);
}
Can this be also a substitute to the factorial program at 40:55?
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
You guys are doing brilliant work.Love from Pakistan💖💖💖💖💖
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
Thank you so much for explaining recursion in such simple yet detailed manner.
Thank you so much, mam it's too good 👍 learning 📕 platform
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);
}
}
thanks a lot i am from germany doing my software engineering degree you really help me lot thank you very much
I have learned first time , I have to build a great understanding of recursion thank u very much and also keep it up,
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)
i am trying to understand recursion from many resources but finally understand now.thanks
Thank you easy method to understand mam
Didi please make complete java series
Your teaching style is amazing
This is a part of the complete java series...
VARANASI SARALA PUUKU MUNDADHI
काबिले तारीफ दीदी 🙏🙏🙏🙏🙏
You are great 😎
amazing way of learning in youtube 😊
Very Helpful
Thank you so much for explaining recursion in such a simple yet detailed manner.
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?
Now my Recursion Concept clear your teaching way Awesome mam ....
ThankYou Shradha deedi.😊
Awesome teaching style. Great illustrations. Keep it up. 👍🤘🙂
th-cam.com/video/qWx5ZAFkSfk/w-d-xo.html
Fibonacci
public class main {
public static int fib(int n){
if (n
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
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
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..
👌🏻👌🏻 mja aa gya video dekh ke
27:40 points
39:38 parameters work base
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?
Perfectly explained each question, last question was mind blowing!
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
You are greatest teacher..❣️
Sach me