Types of Recursion (Part 1) | Direct & Indirect Recursion

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • C Programming: Types of Recursion in C Language.
    Topics discussed:
    1) Direct recursion.
    2) Example of direct recursion.
    3) Indirect recursion.
    4) Example of indirect recursion.
    C Programming Lectures: goo.gl/7Eh2SS
    Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
    Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
    Contribute: www.nesoacademy...
    Memberships: bit.ly/2U7YSPI
    Books: www.nesoacademy...
    Website ► www.nesoacademy...
    Forum ► forum.nesoacade...
    Facebook ► goo.gl/Nt0PmB
    Twitter ► / nesoacademy
    Music:
    Axol x Alex Skrindo - You [NCS Release]
    #CProgrammingByNeso #CProgramming #Recursion

КОМЕНТАРІ • 154

  • @AJewFR0
    @AJewFR0 5 років тому +97

    This is high quality for a UA-cam channel on CS. Great Job from the US.

  • @saifulislamsarfaraz
    @saifulislamsarfaraz 5 років тому +81

    one day there will be billions of viewers in your tutorial

    • @sarfaraz6582
      @sarfaraz6582 5 років тому +7

      it should be but people ain't too much interested in studying unlikely they are busy unnecessary drama..

    • @Dnsx_plus
      @Dnsx_plus 4 роки тому

      @@sarfaraz6582 You got a girlfriend?

    • @fortnitelove8129
      @fortnitelove8129 4 роки тому +4

      Don't waste time in bf or gf or any other human being, invest only on YOU

    • @Dnsx_plus
      @Dnsx_plus 4 роки тому

      @@fortnitelove8129 yeah forreal

    • @hetaeramancer
      @hetaeramancer 3 роки тому +2

      not really billions, but several millions!

  • @HosBarGamers
    @HosBarGamers 3 роки тому +25

    I have never found such a channel that is so good at explaining CS stuff. Great job.

  • @aradhanasoni6616
    @aradhanasoni6616 4 роки тому +31

    I've never seen any sir as you explain about C language.
    You're the God of C. Love you sir 😍

  • @MrTomro
    @MrTomro 5 років тому +29

    Amazing, I like the stack diagram, helps u visualize the whole process

  • @sanjaykarthicks1226
    @sanjaykarthicks1226 3 роки тому +12

    I really like NESO ACADEMY ❤️
    It's really effective for me while preparing for my C paper in sem2
    Thank you so much sir for your lectures

  • @surbhitamrakar1638
    @surbhitamrakar1638 4 роки тому +5

    Thank you so much sir for this series.I found recursion very hard before I watched your lectures..but now I am comfortable with recursion. Thanks alott.

  • @piyushji2312
    @piyushji2312 4 роки тому +16

    One of the best online playlist to learn recursion . Sir please if you could make a series on backtracking and dynamic programming as well. _/\_

  • @enjoylearning210
    @enjoylearning210 3 роки тому +4

    Background music at last really motivates me 😊😊 and indulge myself in that thought ..I have achieved something , it's just becoz of ur awesome video series ...really best 👍 . Not so long and not so short , perfect one

  • @matematleta492
    @matematleta492 10 днів тому

    Best explanation of this material on YT. Thank you!

  • @name-iq7on
    @name-iq7on 9 місяців тому

    Bro where were you this whole timeeeeee,,, is your words are magic or what ,, why am getting your explantion straight in my brain ,,, seriously bro u made my thinking better ,,, where so many were eating my brain, also i m in love with your explanation, the way u r explaning is incredible.

  • @yusraabdullah8261
    @yusraabdullah8261 Рік тому +1

    Now I subscribe your channel for giving us a beautiful example of indirect recursion..... Very beautifully explained...... Now my concepts are clear ❤️Thanks sir..... You deserve millions likes.... And you'll get soon

  • @mani_vk_29
    @mani_vk_29 4 роки тому +6

    Answer for homework problem is 15. Thank you

  • @Adityasharma-oe8zp
    @Adityasharma-oe8zp 3 роки тому +1

    I've done the same question like this
    Int a=1;
    Void main()
    {
    Void fun(int);
    If (a>10)
    Return;
    If(a%2!=0)
    Printf(" %d",a+1);
    Else
    fun(a);
    a++;
    main();
    }
    void fun(int b)
    {
    printf(" %d",b-1);
    a++;
    main();
    }

    • @hetaeramancer
      @hetaeramancer 3 роки тому +1

      what's the output?

    • @Adityasharma-oe8zp
      @Adityasharma-oe8zp 3 роки тому

      @@hetaeramancer output is same as in the question.... I've tested it after that i posted it

  • @anchalagrawal4332
    @anchalagrawal4332 4 роки тому +2

    Sir you explained it very well . nobody can explain like this 👌👌👌👌

  • @pariminagalakshmi5517
    @pariminagalakshmi5517 3 роки тому +1

    sir,thank you soo much ....
    these videos are very helpful for many students like me..
    once again thank you soo much sir...

  • @batsmanist
    @batsmanist Рік тому

    Thank you for this class. It opened my mind to a hard task I was doing.

  • @accessdenied9393
    @accessdenied9393 3 роки тому +2

    Example in same factorial function indirectly:
    [Fact() can calc the factorial of at least 20 and -20, if you calc fact(21) or fact(-21), this will exceeds the range of long integers, and thus you ended up with wrong results]
    long Fact(int a)
    {
    if (a > 0)
    return posFact(a);
    else if (a < 0)
    return negFact(a);
    else
    return 1;
    }
    long posFact(int a)
    {
    if(a == 1)
    return a;
    else
    return a * Fact(a-1);
    }
    long negFact(int a)
    {
    if(a == -1)
    return a;
    else
    return -a * Fact(a+1);
    }

  • @kushalava007
    @kushalava007 3 роки тому +4

    in the user defined functions, we wrote If statement and we related values of n and 10.
    here, what does n mean???
    there is no definition of n in any of the functions.
    in global scope (if compiles goes out) n value is "1".
    how each function call remembers the value of "n"??

  • @bruhmetsaiharnet6595
    @bruhmetsaiharnet6595 3 роки тому +2

    Thank you,God bless you

  • @mipa3868
    @mipa3868 2 роки тому

    wow..amazing
    sir at 5:04...in cases like these ...will post increment operator not be a problem?

  • @juliuskamara1348
    @juliuskamara1348 2 роки тому

    Thank you very much. Do we still return statement for void return type?

  • @binoyabraham4559
    @binoyabraham4559 4 роки тому +1

    in this program we should return (n) right ?becoz i learned that only a variable which is declared in a function ......only that function can access to it ...if u want to access in other function u have to return it na

    • @swarajchoudhary1862
      @swarajchoudhary1862 3 роки тому

      Over Here how after decreament in even function the n value increases by 2 ?????

  • @rileshkhatri1209
    @rileshkhatri1209 2 роки тому +1

    Since we are using tail recursion here with void function we don't really need the return statement.We will still get the same output even without a return statement

  • @kesavae9552
    @kesavae9552 3 роки тому +2

    Mission accomplished, respect++

  • @Hell2026
    @Hell2026 3 роки тому

    You are an outstanding explanation sir but what you have written is that syntax or example? Please give me reply sir

  • @MorrowSind
    @MorrowSind 5 років тому +4

    Nice and very well explained.

  • @sasikumartangala5001
    @sasikumartangala5001 5 років тому +3

    Sir for this programme we need to write the even and odd logics right

    • @nitinadarsh
      @nitinadarsh 4 роки тому +1

      No
      He just initialised the variable with n = 1, and after that it falls in the odd function and we increment the value and send it to even function. So no need to write logic for odd and even.

    • @educationalonly5941
      @educationalonly5941 3 роки тому

      No ,here we have declared no. From 1(kept in odd fun.) sequentialy no. is incriminating in function itself. Then Obviously the next no is of even type and next odd and so on .

  • @knSharooq
    @knSharooq 4 роки тому

    is it necessary to use return; ??? if it is not used then also result will be same right??

  • @namastebhai855
    @namastebhai855 3 роки тому +1

    Then what is significance of writing "return 0" in main function?

  • @kshyamkumarreddy4916
    @kshyamkumarreddy4916 3 роки тому +3

    In the void functions, why u typed return?

  • @fasasiwasiu7533
    @fasasiwasiu7533 2 роки тому

    In video 76(How to write Recursive Functions) you mentioned that if block only should contain Base Case, while else block should contain Recursive Procedure. But in this video, your if block contains Recursive Procedure, while your else block contains Base case.
    Please can you explain what happened here, thanks

    • @juliuskamara1348
      @juliuskamara1348 2 роки тому +1

      I think hence the base case is been define, doesn't matter whether in an if or while.

  • @nikhilguleria4313
    @nikhilguleria4313 2 роки тому

    it's wonderfull explanation

  • @eve7722
    @eve7722 2 роки тому

    Hello when we return value why void came instead of that int may be come

  • @TehreemAyesha
    @TehreemAyesha 4 роки тому +1

    What would have happened if there was pre increment in place of post increment?

  • @tomcruise6618
    @tomcruise6618 4 роки тому +1

    Sir why is void used before function??

  • @shashank6803
    @shashank6803 5 років тому +2

    By direct Recursion it looks like
    public class Print {
    public static int calculate(int n)
    {
    if(n>10)
    {
    return 0 ;
    }
    if(n%2==0)//even
    {
    System.out.print(n-1+" ") ;
    return calculate(n+1);
    }else{
    System.out.print((n+1)+" ");
    return calculate(n+1);
    }
    }
    public static void main(String[] args)
    {
    int n=1 ;
    calculate(n);
    }
    }

  • @zeshanmushtaq5295
    @zeshanmushtaq5295 5 років тому +6

    Love from Pakistan thanks too much sir g

  • @manoharsinghrawat1859
    @manoharsinghrawat1859 2 роки тому +1

    Very awesome lectures 👌

  • @sujoymollick1239
    @sujoymollick1239 3 роки тому +1

    Amazing. Go on.

  • @sayyedaaman5719
    @sayyedaaman5719 2 роки тому

    Amazing video thank you for explain it

  • @raktimagupta9605
    @raktimagupta9605 7 місяців тому

    your voice >>>

  • @arghyasaha8370
    @arghyasaha8370 8 місяців тому

    Great explanation❤

  • @anirudh4692
    @anirudh4692 3 роки тому

    that's neat and clear...gud job

  • @mohandask1328
    @mohandask1328 2 роки тому +1

    if we are not using recursion, the same output can be get by.......
    int fun(int n);
    int main()
    {
    int i;
    for(i=1;i

    • @basavaraj9590
      @basavaraj9590 Рік тому

      This one is which problem Bhai.. print o/p upto from 1 to 10 numbers

  • @rizwanriaz7595
    @rizwanriaz7595 5 років тому +2

    Excellent

  • @ameykulkarni8165
    @ameykulkarni8165 2 роки тому

    are those types applicable in java?

  • @nityanandrai5341
    @nityanandrai5341 5 років тому +2

    a very simple code for above question
    #include
    using namespace std;
    void fun(int n)
    {
    if(n==0)
    {
    return;
    }
    fun(n-1);
    if(n%2==0)
    cout

  • @sahil_singhai
    @sahil_singhai 2 роки тому

    Why we have declared int n =1; in a global variable or not as an inside main function?

    • @cuteonigiri1671
      @cuteonigiri1671 Рік тому

      because if not, it will only be available in main function. unless u use call by reference(pointer).

  • @iluvyunie
    @iluvyunie 4 роки тому +3

    Wow. This is really helpful

  • @venkythesmart440
    @venkythesmart440 4 роки тому

    so many member doubts this. Please reply me. Stack flowed only last in first out. This program not follow that. Return function how it is works. This I am not felt this recursion program

  • @الكليةالتقنيةالهندسيةفيميسان

    how to transfer (n) between odd and even ??? odd()>>>even()!!! how each function call remembers the value of "n"??

  • @-HarishkumarG
    @-HarishkumarG 3 роки тому

    you are the best

  • @daverussell4052
    @daverussell4052 3 роки тому +1

    you basicly dont need the return because void functions is a non-return functions

  • @tanishajaiswal7559
    @tanishajaiswal7559 3 роки тому

    You made it seem so easy

  • @compangit1524
    @compangit1524 Рік тому

    Comment for myself: 1st step is find the recursive flow, 2nd step is find the base case. The base case is the case that doesn't need to call the function itself again.

  • @Vinay_singh01
    @Vinay_singh01 5 років тому +3

    GOOD sir

  • @cheery3469
    @cheery3469 5 місяців тому

    Omg...where i was... thnk u

  • @educationalonly5941
    @educationalonly5941 3 роки тому

    how the return; works?
    Pls. Explain..

  • @HelloWorld40408
    @HelloWorld40408 Рік тому

    Thank You sir

  • @anurani548
    @anurani548 5 років тому

    Very nice explanation

  • @marvelshorts2.o337
    @marvelshorts2.o337 Рік тому

    suprab expalnation sir

  • @SanjeevKumar-wt9bs
    @SanjeevKumar-wt9bs 4 роки тому +2

    sir,please solve indirect recursion question, gate 2017

  • @rohanghosh9700
    @rohanghosh9700 5 років тому +1

    Sir ouput should show in opposite order because it was in stack

  • @chandanpurbey1058
    @chandanpurbey1058 5 років тому +1

    Well explained.

  • @FarhanAli-gd2qv
    @FarhanAli-gd2qv 3 роки тому

    What if we do not write return; statement in even and odd function. I didn't write it in my program and I didn't got any type of error. Program executed properly. What if we do not use it or is it necessary to use, if yes then why?

    • @bablu1921
      @bablu1921 3 роки тому

      Because we're using a void data type so it doesn't expect anything in return

    • @FarhanAli-gd2qv
      @FarhanAli-gd2qv 3 роки тому

      @@bablu1921 I know that but what about int return_type in function header. I have typed int in function header and didn't typed return statement inside function at the last and didn't got any error in the program. According to rules function must return an integer value if int is written in the function header.

    • @bablu1921
      @bablu1921 3 роки тому

      @@FarhanAli-gd2qv probably your compiler is smart lol
      Well then I can't say

    • @FarhanAli-gd2qv
      @FarhanAli-gd2qv 3 роки тому

      @@bablu1921 you can try it too in the visual studio code.

    • @FarhanAli-gd2qv
      @FarhanAli-gd2qv 3 роки тому

      @@bablu1921 I searched about this issue over stack overflow, over there a user said "it's ur choice whether you want to put it or not". But I need the reason. Why program is not generating any error ?

  • @sajadulislamdipu1954
    @sajadulislamdipu1954 4 роки тому +1

    Thanks sir
    ❤❤❤

  • @bsaikumarreddy1413
    @bsaikumarreddy1413 5 років тому +2

    Please upload video fastly sir
    It’s a kind request

  • @sabreenparween9696
    @sabreenparween9696 4 роки тому

    Really osm concept😍

  • @vallimaylvalliappan9489
    @vallimaylvalliappan9489 2 місяці тому

    isnt it dynamic scoping then?

  • @anoliverma4907
    @anoliverma4907 2 роки тому

    Why is only odd function called in the main function? Why Even function is not called?

  • @indianmusic1770
    @indianmusic1770 3 роки тому +1

    Why do you not execute the code

  • @CostaKazistov
    @CostaKazistov 4 роки тому

    Is it the same as Trampoline function?

  • @M4LICIOUS
    @M4LICIOUS 2 роки тому +6

    You sure WAP is 'write a program"?,lol🙃

    • @johnychinese
      @johnychinese Рік тому +1

      I came looking for this comment 😂

  • @harshvardhananand8795
    @harshvardhananand8795 5 років тому

    Nicely explained

  • @pranaybiswas6971
    @pranaybiswas6971 5 років тому +1

    But how does the compiler know that which is odd number and which is even ??

    • @georgiilkov9915
      @georgiilkov9915 3 роки тому

      A bit late here but we start with 1 which we as humans know is odd. So we make it call odd() first.The number after an odd number is an even one. After an even number follows an odd one. And so on until we reach 11

    • @jeevaalok1467
      @jeevaalok1467 3 роки тому

      compiler knows some inbuilt functions ig

  • @udbhavvikramsingh3449
    @udbhavvikramsingh3449 3 роки тому

    Can we write even (n++) instead even ( )
    And not write n++

  • @codemonster8240
    @codemonster8240 3 роки тому

    realy helpfull

  • @sudhanshuranjan7629
    @sudhanshuranjan7629 5 років тому +1

    By what date should we expect next lectures?

  • @sumitchettri8399
    @sumitchettri8399 4 роки тому

    if we are already incrementing the value of n in the printf function then why are we incrementing it again??

    • @FarhanAli-gd2qv
      @FarhanAli-gd2qv 3 роки тому

      incrementation of n variable in both functions are necessary.

    • @FarhanAli-gd2qv
      @FarhanAli-gd2qv 3 роки тому

      Dry run your program then you will get to know.

  • @sahilsaxena8374
    @sahilsaxena8374 5 років тому +1

    Void odd()
    It's return how it is possible
    Void means it's doesn't return???

    • @bantuthakur9959
      @bantuthakur9959 5 років тому +1

      Hey odd and even function not return any value, it only print on its own function but doesn't return any value.

    • @sahilsaxena8374
      @sahilsaxena8374 5 років тому

      Why we write return statement??

    • @bantuthakur9959
      @bantuthakur9959 5 років тому

      @@sahilsaxena8374 to return some value to the function

    • @rishabh7011
      @rishabh7011 4 роки тому +1

      @@sahilsaxena8374 to stop the execution of that function and return to previous function

    • @HarshaVardhan-kt5uu
      @HarshaVardhan-kt5uu 3 роки тому

      Nice question 👍

  • @b.himanshu2654
    @b.himanshu2654 4 роки тому

    Superb

  • @Karan-wv9zn
    @Karan-wv9zn 5 років тому +1

    Respect....

  • @true4189
    @true4189 4 роки тому

    Thank u

  • @jonasasare5775
    @jonasasare5775 3 роки тому

    We are returning an integer to the main fun but why is the data type of odd fun and even fun void

  • @CSEEswarGuptha
    @CSEEswarGuptha 4 роки тому

    In function defination why we are using void odd,void even

  • @omarboug681
    @omarboug681 3 роки тому

    is my code right to ?
    it worked by the way
    int fact( int n )
    {
    if( n % 2 == 0 )
    {
    return n - 1 ;
    }
    else
    {
    return n + 1 ;
    }
    }
    int main()
    {
    int n = 1 ;
    for( n = 1 ; n

  • @kostavsheoran1530
    @kostavsheoran1530 5 років тому

    i tried to make a program for this without watching the whole video byusing for loop and it ran successfully , how to know which program is better, yours or mine?

    • @_shubham_kumar
      @_shubham_kumar 4 роки тому +1

      By calculating time and space complexity.

  • @ReflectingOurselves
    @ReflectingOurselves 3 роки тому

    #include
    int i;
    int main()
    {
    for(i=1;i

  • @compangit1524
    @compangit1524 Рік тому

    Comment for myself: Indirect Recursion happens, when the recursion doesn't only happen on the function body alone of the function caller.

  • @geekyskill4156
    @geekyskill4156 2 роки тому

    sir it is not working it programe goes to infinity

  • @mdkaiserali6830
    @mdkaiserali6830 4 роки тому

    awesome

  • @jayaprakashl8592
    @jayaprakashl8592 Рік тому

    in the even function, the if condition and the return statement are useless.

  • @b3nythomas284
    @b3nythomas284 9 місяців тому

    I wish i thought of WAP as write a program...

  • @ritikshrivastava9442
    @ritikshrivastava9442 4 роки тому +1

    If somebody wants to know the same program without indirect recursion 👇
    int main()
    {
    for(int i = 1; i

  • @manavjain3930
    @manavjain3930 5 років тому

    Man jae sir

  • @asha0523
    @asha0523 5 років тому

    Mast

  • @johnychinese
    @johnychinese Рік тому +1

    WAP == Write a program
    Everybody knows that 😂

  • @Kartik001arts
    @Kartik001arts 2 роки тому

    Code don't get executed properly
    Output is not what is revealed in video

  • @zawzawwin2918
    @zawzawwin2918 4 роки тому

    Hello Sir I got wrong ouput