Recursion in One Shot | Theory + Question Practice + Code | Level 1 - Easy

Sdílet
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...

Komentáře • 778

  • @moremansi81
    @moremansi81 Před měsícem +10

    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);
    }
    }

    • @paragshende3390
      @paragshende3390 Před měsícem

      what happens when we do return 1;
      ?

    • @moremansi81
      @moremansi81 Před měsícem

      @@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

    • @kishordhobale6317
      @kishordhobale6317 Před 13 dny +1

      this is simple way to calculate sum of n number which you explained.good job

  • @onkarvyavahare3327
    @onkarvyavahare3327 Před 2 lety +63

    Stack height concept you have tought was nothing anywhere generally...so thank you for such intuition.

  • @mdsarfarazalam8452
    @mdsarfarazalam8452 Před 2 lety +55

    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

  • @iqbalhossain927
    @iqbalhossain927 Před 2 lety +62

    Need this type of practice question in every topic. Hope you continue like this. And thanks for this awesome session😍

  • @onlythereal333
    @onlythereal333 Před 2 lety +38

    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 👍☺️☺️👏🙌

    • @_AAMIR_.AEP.
      @_AAMIR_.AEP. Před 23 hodinami +1

      Are you completing your college 😊

  • @rajivtripathi8403
    @rajivtripathi8403 Před 2 lety +17

    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!!!!

  • @JAGMEETHEBEST
    @JAGMEETHEBEST Před 2 lety +223

    "JEE PREP HO YA COLLEGE KI PADHAI, ONE SHOTS ARE THE BEST!!"😂😂👌

  • @minivishwakarma960
    @minivishwakarma960 Před rokem +112

    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.

  • @faisalkhan1026
    @faisalkhan1026 Před 2 lety +79

    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 !

    • @uskapyaar8852
      @uskapyaar8852 Před 2 lety +4

      Thank god you said that... I had my hands up this whole time :(

    • @lalalostyou6858
      @lalalostyou6858 Před rokem +1

      @@uskapyaar8852 😂😂😂😂

    • @ZainDiscoveries
      @ZainDiscoveries Před 11 měsíci

      czcams.com/video/qWx5ZAFkSfk/video.html

  • @adityaagarwal2324
    @adityaagarwal2324 Před 2 lety +136

    Didi, backtracking ke upar bhi dedicated playlist banaiye please

  • @komalkamani5892
    @komalkamani5892 Před 2 lety +34

    Please make whole series
    JAVA DS+ALGO 🥳

  • @xdnaitiksaraf1474
    @xdnaitiksaraf1474 Před 2 lety +3

    at 30:30
    public static int sum(int n){
    if (n==0) {
    return 0;
    }
    return n+sum(n-1);
    }
    is more convinient

  • @gulshanbindua7471
    @gulshanbindua7471 Před 2 lety +6

    Without 3 variable, you can also use

  • @sourabsen9679
    @sourabsen9679 Před 2 lety +2

    Thank you so much for explaining recursion in such simple yet detailed manner.

  • @nandk45523
    @nandk45523 Před 2 lety +98

    Aman bhaiya c++ pe practice 500 questions Ki serie banvado please 🙏🙏🙏 garib ko placement lag jayegi

    • @KaranKumar-vm2we
      @KaranKumar-vm2we Před 2 lety +10

      Babbar's 450 ques is best for placements👍

    • @nandk45523
      @nandk45523 Před 2 lety +1

      @@KaranKumar-vm2we Haan vahi solution bi chayie😅

    • @nandk45523
      @nandk45523 Před 2 lety +2

      @@KaranKumar-vm2we oh no oh no oh no no no..!

    • @The_Mitnick
      @The_Mitnick Před rokem +1

      Abe kisi ke bhi DSA sheet utha kar kar le uske baad kitne bhi solve karte beth

    • @lokadeepak7880
      @lokadeepak7880 Před 8 měsíci

      ​@@KaranKumar-vm2weBhai Java ke liye questions kaha milega...

  • @prathambharti2462
    @prathambharti2462 Před 2 lety +11

    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

  • @raunakkumarmishra1449
    @raunakkumarmishra1449 Před 2 lety +11

    This is something we can call Recursion
    Thanku Di and thanku Aman bhaiya to bring such people for us❤🔥

  • @ayushnegi675
    @ayushnegi675 Před rokem +15

    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

  • @Veds5861
    @Veds5861 Před rokem +7

    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

  • @mainak23_12
    @mainak23_12 Před 2 lety +6

    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 🙏

  • @sauravjha2933
    @sauravjha2933 Před 2 lety +7

    This is the best video on recursion. Thank you so much.

  • @abhinitashrivastava9100
    @abhinitashrivastava9100 Před 2 lety +17

    You are amazing! I am a 52 years old but i understand the concepts very well because of you. Thanks!

    • @i.khushii
      @i.khushii Před rokem +4

      52 ? And learning java ..? I mean for what ? 😅

    • @annielouise1141
      @annielouise1141 Před rokem

      @@i.khushii maybe because the institute asked her to my oops teacher was in same position

    • @ZainDiscoveries
      @ZainDiscoveries Před 11 měsíci

      czcams.com/video/qWx5ZAFkSfk/video.html

  • @techgamertej2811
    @techgamertej2811 Před 5 měsíci +36

    thoda mushkil hai

    • @prankitsharma
      @prankitsharma Před 2 měsíci +1

      🥺🥺🥺🥺🥺

    • @cp65143
      @cp65143 Před měsícem +1

      🐭🐭🐭🐭🐭

    • @mridulsd2023
      @mridulsd2023 Před měsícem +2

      Sidha recursion padhoge toh lagega hi
      Step by step basic se karo warna karo mat

    • @LETSLEARNASKILLANDGETLIFE
      @LETSLEARNASKILLANDGETLIFE Před měsícem

      Same

    • @royalX555
      @royalX555 Před 6 dny +2

      ​@@mridulsd2023ye depend krta h
      Me is sal hi college jaunga to thoda mushkil lag rha h mene Kiya h basic se pura fir bhi 😢

  • @abdullahnawaz6396
    @abdullahnawaz6396 Před rokem +1

    really informative...the way you are teaching to students its quite commendable .hats off

  • @vishvjeet1551
    @vishvjeet1551 Před 6 měsíci +2

    factorial vala question sum of n natural numbers se bhi ho jayega bus sum=1 kardo and + ki jgeh * kardo

  • @smilemania5102
    @smilemania5102 Před 2 lety +6

    Now quality comes

  • @user-tl8sq4mz7d
    @user-tl8sq4mz7d Před 10 měsíci

    Very Helpful
    Thank you so much for explaining recursion in such a simple yet detailed manner.

  • @abhi.1289
    @abhi.1289 Před rokem +7

    Best explanation ever..
    Finally i understand recursion... 🥳🥳🥳🥳

  • @siddhantpatel01
    @siddhantpatel01 Před 2 lety +9

    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

  • @rushround3595
    @rushround3595 Před 2 lety +1

    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...

  • @uskapyaar8852
    @uskapyaar8852 Před 2 lety +2

    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)

  • @santoshsinghpawar9015

    You are one of the best online teacher. Thank you for making such videos.

  • @haidertest1809
    @haidertest1809 Před rokem +1

    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
    }

  • @sumitghosh5025
    @sumitghosh5025 Před 2 lety +1

    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.

  • @adnanrafique4785
    @adnanrafique4785 Před 2 lety

    I have learned first time , I have to build a great understanding of recursion thank u very much and also keep it up,

  • @nilavabishnu
    @nilavabishnu Před 2 lety +3

    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?

  • @lalitvats9803
    @lalitvats9803 Před rokem +3

    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 ❤❤❤

  • @salahiansofficial424
    @salahiansofficial424 Před 2 lety +3

    Thanks for this amazing explanation on recursion

  • @sohamtanpathak9067
    @sohamtanpathak9067 Před rokem

    Perfectly explained each question, last question was mind blowing!

  • @ahmadrasheed2598
    @ahmadrasheed2598 Před rokem +13

    I usually don't comment on videos but I have to say the explanation is mind-blowing
    I cannot thank you in words🥰

  • @sandeshvora
    @sandeshvora Před 2 lety +1

    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...

  • @venkateshjacke7238
    @venkateshjacke7238 Před 6 měsíci +1

    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

  • @pwian2362
    @pwian2362 Před měsícem +2

    mughe toh yeh easy level bhi samajhne mein dikkat horhi haiii🙁

  • @ishika05843
    @ishika05843 Před rokem

    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

  • @gaurigupta5129
    @gaurigupta5129 Před 2 lety +4

    Great explanation! Best lecture of recursion on you tube.

  • @YashPatel-hd3hc
    @YashPatel-hd3hc Před rokem

    your teaching skills touch every one's mind every time

  • @kishordhobale6317
    @kishordhobale6317 Před 13 dny

    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

  • @tanmaybhalerao8872
    @tanmaybhalerao8872 Před 2 lety

    most amazing video ever watched about recursion all concept gets cleared thanks bhaiya and didi.

  • @vishvjeet1551
    @vishvjeet1551 Před 6 měsíci +3

    di ek linux one shot lekar aao. it will many students

  • @daemon690
    @daemon690 Před 2 lety +6

    We need python course

  • @VaibhavKKM
    @VaibhavKKM Před rokem +1

    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));

    }

    }

  • @Gamer_0057
    @Gamer_0057 Před 2 lety

    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);
    }
    }

    • @SIR.abinash
      @SIR.abinash Před 2 lety

      Han but jyada lagega though yhan ye itna jyada nhai hai but take a big no. For consideration.

  • @ArjunSharma-gp6hy
    @ArjunSharma-gp6hy Před 2 lety +34

    Yes we need a dedicated playlist on backtracking topic 👍

  • @monikanagar2792
    @monikanagar2792 Před 2 lety

    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?

  • @abhijitmondal9203
    @abhijitmondal9203 Před 2 lety +3

    Awesome teaching style. Great illustrations. Keep it up. 👍🤘🙂

  • @mrlalit0552
    @mrlalit0552 Před 2 lety +5

    Thank you so much, mam it's too good 👍 learning 📕 platform

  • @The_TechX
    @The_TechX Před rokem +1

    I didn't understand the last problem, how it works...

  • @khushigupta2206
    @khushigupta2206 Před rokem +2

    You have explained one of the complex topic in a very smooth way. Very Thankful🥰

  • @manalitawar5327
    @manalitawar5327 Před rokem +1

    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).

  • @akashmondal3952
    @akashmondal3952 Před 4 měsíci

    31:06 instead of sum+=i we can do (i==n+1) and then print sum then return.

  • @be_rajeevkumar
    @be_rajeevkumar Před rokem

    Kitna aacha samjaya h apne didi.
    Thankyou so much to making a good start in recursion.

  • @devansh_4u
    @devansh_4u Před rokem +1

    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);
    }
    }

  • @ahadullahmujahid4515
    @ahadullahmujahid4515 Před 7 měsíci

    Amazing content. Everything is explained in a very easy to understand way. Thanks alot

  • @ShivaniSingh-ij9pl
    @ShivaniSingh-ij9pl Před 2 lety

    It was detailed and well explained video which cleared all my doubts

  • @siddhantpatel01
    @siddhantpatel01 Před 2 lety +6

    finally java + DSA 🥰🥰🥰

  • @gaurangtyagi9262
    @gaurangtyagi9262 Před 2 lety

    thanks di..for such a brief and excellent explanation!!keep it up

  • @YawarAbass
    @YawarAbass Před 2 lety +4

    Waiting for this video from lot of time. Thanks 🤗

  • @rupankarpal2902
    @rupankarpal2902 Před 2 lety +2

    Amazing lecture mam. thank you 🙏🙏

  • @vishnureddy5060
    @vishnureddy5060 Před 2 lety +6

    Hello sister we need more videos like this java.... Thank you for your previous videos

  • @dhruvjoshi4192
    @dhruvjoshi4192 Před 2 lety +3

    Thank youu dii..bas aise hi continue rkhna ab please 🥺❤️

  • @sanjanakatala4311
    @sanjanakatala4311 Před 2 lety +12

    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

  • @HarshSingh-fk5mc
    @HarshSingh-fk5mc Před 2 lety +3

    Bhaiya kaha se start karu samjh hi ni aa raha ki kaha se padhu ..

    • @brutalsharma5194
      @brutalsharma5194 Před 2 lety

      czcams.com/play/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ.html

  • @mohitverma8721
    @mohitverma8721 Před 9 měsíci

    Thanks mam ,this video really helped me to understand the recursion . Explanation is superb.

  • @rajeshkumarchaudhary8525

    i am trying to understand recursion from many resources but finally understand now.thanks

  • @salahiansofficial424
    @salahiansofficial424 Před 2 lety +18

    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.

    • @mrbob2148
      @mrbob2148 Před 2 lety +1

      ++

    • @Shubh.Shorts.
      @Shubh.Shorts. Před rokem

      @@mrbob2148czcams.com/play/PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q.html

  • @karansawant5121
    @karansawant5121 Před 10 měsíci

    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.

  • @UnitedIndia397
    @UnitedIndia397 Před 2 lety

    great appreciation for your hardwork!!

  • @user-hn5lj7fe6k
    @user-hn5lj7fe6k Před 2 lety

    Bhagwan apka bhala kre... recursion ko detail se smjhane ke liye apka bahut bahut dhanyawad..

  • @ji6442
    @ji6442 Před 2 lety +1

    Didi aapka contents PHYSICS WALLAH ke tarah hai...... High quality content of explaining, thank you didi....

  • @user-zz1em3rc7b
    @user-zz1em3rc7b Před rokem

    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.

  • @tcod66pankajmandal43
    @tcod66pankajmandal43 Před 3 měsíci

    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!

  • @studybright9273
    @studybright9273 Před 2 lety +4

    Microsoft wali didi Zindabad 🇮🇳🇮🇳

  • @mouli6086
    @mouli6086 Před rokem

    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.)

  • @abignyareddymadireddy2434

    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);
    }
    }

  • @arunabhachatterjee9979
    @arunabhachatterjee9979 Před 10 měsíci

    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

  • @NeerajKumar-bl4pr
    @NeerajKumar-bl4pr Před 2 lety

    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);

  • @lakshitjangid3096
    @lakshitjangid3096 Před 2 lety +21

    Please make the Python Course with DSA just like the C++ course. It will be very helpful 🤞

    • @atharvak1503
      @atharvak1503 Před 2 lety +5

      I also want python course with DSA

    • @harshalbadgujar944
      @harshalbadgujar944 Před 2 lety +4

      Yes absolutely we want python dsa

    • @sameriakhankhan1046
      @sameriakhankhan1046 Před 2 lety +2

      DSA concept is same everywhere but in languages writing of code is different.

    • @clubsign36
      @clubsign36 Před 2 lety +1

      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

    • @clubsign36
      @clubsign36 Před 2 lety

      @@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

  • @VijayJain-ls9du
    @VijayJain-ls9du Před rokem

    You are Best Teacher Ever..main to aapka all time wala Fan ho gaya...now Recursion is Clear...

  • @vikalp.pandey
    @vikalp.pandey Před rokem +1

    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);
    }
    }

  • @arshadimam3420
    @arshadimam3420 Před 2 lety +4

    Probabily the best teacher in the world for computer science student.

  • @theswarajnegi
    @theswarajnegi Před 2 lety

    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?

  • @te-a-64-vivekyadav87
    @te-a-64-vivekyadav87 Před rokem

    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

  • @Youtube-Falcon
    @Youtube-Falcon Před 2 lety +1

    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

    • @hemamadala1868
      @hemamadala1868 Před 4 měsíci

      same doubt, if u got to know the answer please explain to me

  • @technicalspider2547
    @technicalspider2547 Před 2 lety +2

    Slowly aur easily padhaya hai awesome 😀

  • @adisaxena4359
    @adisaxena4359 Před rokem +1

    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?

  • @technicaladda7841
    @technicaladda7841 Před rokem +1

    Lots of love to your lactures seriously now I am able to learn recursion otherwise I was thinking recursion is not my type 😂

  • @vikrantkambli9265
    @vikrantkambli9265 Před rokem

    the explanation is very simple .thank you so so much for this videos .

  • @kakshabaravijeeneet
    @kakshabaravijeeneet Před 2 lety +3

    Bestest Video On Recursion ❤

  • @mehakarora3977
    @mehakarora3977 Před rokem +1

    Ma'am plz explain this:-- humne to math. Pow use nhi kiya to calcpower kese output dera hai??

  • @kharakkunwar5046
    @kharakkunwar5046 Před 2 lety

    I'm learning python but after watching this session all debut cleared. related to the same topic. thanks