Recursion (Solved Problem 1)

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ม.ค. 2025

ความคิดเห็น • 149

  • @Hiyori___
    @Hiyori___ 4 ปีที่แล้ว +45

    the tree makes sense but I cannot possibly understand the concept behind it. I'll come back to this when I'll have better knowledge

  • @ojaskumar2355
    @ojaskumar2355 3 ปีที่แล้ว +18

    This que is so looking so interesting... For now I didn't get the concept... Will definitely return to this que after getting some more concept about recursion 🙂

  • @nikhilanand984
    @nikhilanand984 4 ปีที่แล้ว +21

    coming back in this question is really confusing. please explain more clearly and easily. I am really looking forward to it.

  • @phani2739
    @phani2739 4 ปีที่แล้ว +42

    Now I understood how the gate questions be.

    • @hetaeramancer
      @hetaeramancer 3 ปีที่แล้ว

      What does GATE mean?

    • @phani2739
      @phani2739 3 ปีที่แล้ว +3

      @@hetaeramancer The Graduate Aptitude Test in Engineering (GATE) is anexamination that primarily tests the comprehensive understanding of various undergraduate subjects in engineering and science for admission into the Masters Program and Job in Public Sector Companies in India.

    • @akrzha
      @akrzha 3 ปีที่แล้ว

      @@hetaeramancer Graduate Aptitude Test in Engineering

  • @MeteorSky41
    @MeteorSky41 3 ปีที่แล้ว +4

    Guys watch it again to understand..
    And for if(n

  • @Karthik-or2fy
    @Karthik-or2fy 4 ปีที่แล้ว +28

    Confused program changed to simple program through your explanation 👌

    • @realrawt
      @realrawt ปีที่แล้ว +1

      🧢

  • @gopinathsubramani1320
    @gopinathsubramani1320 3 ปีที่แล้ว +12

    Now I understood how multiple recursion works...
    Thank you bro

  • @saswatpradhan5549
    @saswatpradhan5549 5 ปีที่แล้ว +32

    This is a very confusing problem 🙁

  • @krishpatil9609
    @krishpatil9609 4 ปีที่แล้ว +26

    After get(0) -->if(0True-->return-->
    control goes to
    *get(1)*---->> then get(n-3)=get(-2) and then if(-2True-->return to get(-2)
    And then evaluate print(n)
    ------->>>>here n=1 hence will be printed..
    Then control shifts to
    *get(2)*---->>get(2-3)=get(-1) then control will shift to if(-1>True-->>return-->get(-1)
    Then printf will get evaluated and hence will print
    n=2
    Then control shifts to
    *get(3)*--->>get(3-3)=get(0)-->>
    if(0True-->return to get(0)
    Evaluate printf
    n=3
    Now control transfers to
    *get(4)*--->>get(4-3)=get(1)-->
    if(1>False-->>Hence now
    get(n-1) will evaluate.(note:n=1 for following statements)
    -->>get(1-1)=get(0)-->>
    if(0return at get(1)-->now printf will evaluate and print n=1
    n=1
    Control will shift back to parent function i.e. get(4) hence it will print
    n=4
    Control shifts to
    *get(5)*--->>get(5-3)-->>get(2)-->
    if(2False--> get(n-1) will eval.
    Now n=2, get(n-1)=get(1)-->
    if(1False-->return to get(2)-->>get(n-1)-->get(1)
    And as get(1) evaluates printf will consider n=1
    Hence n=1 will be printed
    And control shifts to get(2) i.e.get(5-3)i.e.get(n-3)
    Hence printf will evaluate
    n=2.
    Control will shift back to parent function
    get(5)
    Hence will print n=5
    Same applicable for get(6)
    n=1
    n=2
    n=3
    n=6
    O/p:-- 123141251236
    I understood this much...still confused.
    It will be more helpful if someone can elaborate it more in deapth ..🥰

    • @aniketrohit7287
      @aniketrohit7287 2 ปีที่แล้ว +4

      thank you for sharing this i am also confused with that now it is much more clear

  • @AshishKhetwal
    @AshishKhetwal หลายเดือนก่อน

    sir the questions you provide are really interesting and I always learn something new from them! thanks!

  • @radheshyamsingh1300
    @radheshyamsingh1300 5 ปีที่แล้ว +59

    This program is really very confusing..

    • @Sake679
      @Sake679 4 ปีที่แล้ว +1

      No it ain't

    • @dannyboy3413
      @dannyboy3413 3 ปีที่แล้ว

      @@Sake679 stfu

  • @ahmed6569180
    @ahmed6569180 4 ปีที่แล้ว +8

    how is the condition is true when n=1 and if (n

    • @Sake679
      @Sake679 4 ปีที่แล้ว +1

      No if it's n

    • @bablu1921
      @bablu1921 3 ปีที่แล้ว

      Thats not how compiler will work its just takes the argument if 1 is less than 1 which in this case it's not therefore it will execute further

    • @charuarora6621
      @charuarora6621 3 ปีที่แล้ว

      and if it executes further it must not reach to get(0) part, there might be some problem with operators.

  • @riturajsharma3937
    @riturajsharma3937 2 ปีที่แล้ว +6

    These questions deserve 100.marks 😂

  • @andistheinforitbutso7513
    @andistheinforitbutso7513 3 ปีที่แล้ว +1

    Tough one nicely done ✔ 👏

  • @techodisha4836
    @techodisha4836 3 ปีที่แล้ว +3

    I have to watch for infinite times🤯😂😂

  • @gitanjalikumari9262
    @gitanjalikumari9262 4 ปีที่แล้ว +1

    Nice explanation sir...

  • @shravya8492
    @shravya8492 3 ปีที่แล้ว +5

    Though your explanation is excellent, this question is quite confusing😅. I guess I will come back again after watching some more videos.

  • @riyazahmed7907
    @riyazahmed7907 5 ปีที่แล้ว +2

    Beautiful explanation sir

  • @TEeducation
    @TEeducation 4 ปีที่แล้ว

    Awesome Explanation

  • @saipraneeth2311
    @saipraneeth2311 ปีที่แล้ว

    Sir superb explanation sir.

  • @abhaypratap9898
    @abhaypratap9898 3 ปีที่แล้ว +2

    Please suggest any book for such questions 🥺🥺🥺

  • @tejastej2762
    @tejastej2762 3 ปีที่แล้ว

    Superb explanation

  • @pratikagrawal8637
    @pratikagrawal8637 4 ปีที่แล้ว +1

    Superb... Content

  • @enjoylearning210
    @enjoylearning210 3 ปีที่แล้ว +3

    This problem is quite confusing ..I think 🤔 I need to watch it several times ...but ur way of explanation is pretty good

    • @scars707
      @scars707 3 ปีที่แล้ว

      No need to watch several times ,
      KHABY : LIFE MADE EAZY

  • @b.himanshu2654
    @b.himanshu2654 4 ปีที่แล้ว +1

    Excellent

  • @anonymousindinymous7306
    @anonymousindinymous7306 5 ปีที่แล้ว +6

    sir pls expaliN how the OUTPUT is printed :
    o/p is::: 1 2 3 1 4 1 2 5 1 2 3 6
    pls explain each one by one its really cant understand with out u!
    Thanks for above wonderful simple explanation ........

    • @akshitarora470
      @akshitarora470 4 ปีที่แล้ว +2

      the get(n-3) value goes less than 1, the base case is triggered, it says to the caller, just stop what ever you're doing and return, at this point whatever the poor function get(n-3) had as the value of n, it prints it out in the next line and that explains the output! Try and dry run it on a sheet, you will see how the calling goes.

  • @pratikneupane951
    @pratikneupane951 3 ปีที่แล้ว +3

    I didn't understand when to use gate(n-1) and when to use get(n-3) .Please help me.

    • @dipeshranadipeshrana881
      @dipeshranadipeshrana881 2 ปีที่แล้ว

      Its non tail recursive implement it's concept

    • @krishwanthkishore8299
      @krishwanthkishore8299 ปีที่แล้ว

      ​@@dipeshranadipeshrana881yo he didn't mention any concept like that, in tail recursion there is no need to keep record of past recursions

  • @eswarvankayala5606
    @eswarvankayala5606 5 ปีที่แล้ว +4

    Please any body reply me
    Why we return to get(2) after get(1)
    At 3:44 seconds in video??
    Please let me know

    • @zitrakzsingh7295
      @zitrakzsingh7295 5 ปีที่แล้ว +2

      get(1) completes get(0) and get(-2) so after that it wont call again so it will return to its parent call that is get(2)
      u can think it like the student reports to the teacher after all the work ,the teacher reports to the higher authority and so on ..

    • @tanaykamath1415
      @tanaykamath1415 5 ปีที่แล้ว

      Maybe bcoz its void!?

    • @nikhilanand984
      @nikhilanand984 4 ปีที่แล้ว +3

      I am having the same doubt. If anyone can clear it with valid concept

    • @Manuevaral
      @Manuevaral 4 ปีที่แล้ว +1

      because of this is recursion.....so compiler automatically set up as recursion body so it's going get(1) to get(2);-)

  • @nour_780
    @nour_780 ปีที่แล้ว

    Thank you

  • @kaveeshnayak4328
    @kaveeshnayak4328 5 ปีที่แล้ว

    Great explaination

  • @HelloWorld40408
    @HelloWorld40408 2 ปีที่แล้ว

    Thank you SIr

  • @manuelconte2127
    @manuelconte2127 9 หลายเดือนก่อน

    For all those who have had difficulty solving it, don't give up, try and try again; Sooner or later you will understand it, I assure you!

  • @milesli2751
    @milesli2751 ปีที่แล้ว +1

    I just wonder why we called the get() function 25 times, but when we run this code there are only 12 numbers are printed out?

    • @TruthTongue
      @TruthTongue 10 หลายเดือนก่อน

      ok so u see when we were calling the get(n-1) function, we were not able to reach the printf function. even after going to the get(n-3) function,..since the returned number were (n

  • @shahidmujawar9277
    @shahidmujawar9277 5 ปีที่แล้ว +1

    Hello, can you please make a vedio on space and time complexity in c

  • @bollyedits6030
    @bollyedits6030 4 ปีที่แล้ว +7

    If( 1< 1 ) , this condition is false so how get(0) is evaluated ?

    • @Sake679
      @Sake679 4 ปีที่แล้ว

      No it's true cause 1< 1 so we go to zero function next

    • @dekhbhai9328
      @dekhbhai9328 4 ปีที่แล้ว +1

      @@Sake679 no this is false 1

    • @MurariSingh-mw8ze
      @MurariSingh-mw8ze 4 ปีที่แล้ว +1

      @@dekhbhai9328 1 is not less than 1,1 is equal to 1
      therefore ,condition is true

    • @dekhbhai9328
      @dekhbhai9328 4 ปีที่แล้ว

      @@MurariSingh-mw8ze no bro there is clearly mention n

    • @muskansadaka9458
      @muskansadaka9458 3 ปีที่แล้ว +1

      @GAURAV MALHOTRA ya condition is false so it will not return . so get(0) will be called .
      Please think it like that :
      if(n-1)
      {
      return;
      }

  • @rtm4829
    @rtm4829 3 ปีที่แล้ว +3

    How after get(-2) it goes back to get(1) and then to get(2) ??

    • @cqwshi
      @cqwshi ปีที่แล้ว +1

      same doubt. but if you understand by now,can you please explain it?

  • @vivekojha4807
    @vivekojha4807 5 ปีที่แล้ว

    Thank you sir.

  • @radheyshreeagrawal8868
    @radheyshreeagrawal8868 2 ปีที่แล้ว +1

    this might be wrong, as when Get(1) is formed value of N is 2. and so on. sir please reply?

    • @TruthTongue
      @TruthTongue 10 หลายเดือนก่อน

      it is not 2, it is -2.

  • @harmankaur3938
    @harmankaur3938 2 ปีที่แล้ว

    Thank you :)

  • @true4189
    @true4189 4 ปีที่แล้ว

    Thank u

  • @VikashShukla07
    @VikashShukla07 3 ปีที่แล้ว +1

    Amazing question.nicely explained sir

  • @digitalgoldmine-007
    @digitalgoldmine-007 7 หลายเดือนก่อน

    could u plz make a video on how to guess the last part of recursive cuz teachers r making questions in exam which they give first part of recursive code and want us to write the other part.

  • @nikp9999
    @nikp9999 4 ปีที่แล้ว

    Nice problem.

  • @Anonymous____________A721
    @Anonymous____________A721 3 ปีที่แล้ว +1

    Can you explain with output

  • @DSAbyraj1729
    @DSAbyraj1729 3 ปีที่แล้ว

    super question

  • @bellalmahtab8220
    @bellalmahtab8220 3 ปีที่แล้ว

    Understood

  • @rohandevaki4349
    @rohandevaki4349 5 ปีที่แล้ว

    after get (5) to get(4) to so on get(1) after that it becomes get(0) and it prints o and it comes out of the function right? please reply fast sir

  • @scien-terrific7004
    @scien-terrific7004 5 ปีที่แล้ว +1

    Ans should be 35...not 25 as when (n-1)=1 ; then (n-3)= -1 , not -2 & here @nesoacademy has done a mistake by taking (n-3)=-2, plz recheck it!

  • @Sake679
    @Sake679 4 ปีที่แล้ว

    Guys 1

  • @colloidalsilver177
    @colloidalsilver177 6 ปีที่แล้ว +6

    2:52 is that part i am confused on

    • @sheentoosi9642
      @sheentoosi9642 6 ปีที่แล้ว +3

      So my understanding is that the first recursive call at the end of the sequence stops because it satisfy the "n

  • @varunpandey3172
    @varunpandey3172 3 ปีที่แล้ว

    I have a doubt that when the fun will be 1 then at that time the condition is going to get wrong bcz if (n

  • @raosahebkolgatram9293
    @raosahebkolgatram9293 3 ปีที่แล้ว

    Is this indirect recursion?

  • @meenalsolanki9286
    @meenalsolanki9286 5 ปีที่แล้ว +1

    I have a query in condition if( n

    • @vivekojha4807
      @vivekojha4807 5 ปีที่แล้ว +2

      get(1) is called because the condition says strictly less than 1. When it calls get(0), the condition gets true and it goes back to get(1).

    • @jeedikantivenkat7814
      @jeedikantivenkat7814 5 ปีที่แล้ว +2

      Guys dont get confused .
      Watch it twice
      U will get it ..

    • @Dnsx_plus
      @Dnsx_plus 4 ปีที่แล้ว

      @@jeedikantivenkat7814 thanks

    • @arjunshaik3071
      @arjunshaik3071 4 ปีที่แล้ว

      @@vivekojha4807 bro can u explain in clean manner plz

    • @vivekojha4807
      @vivekojha4807 4 ปีที่แล้ว

      @@arjunshaik3071 It's difficult to explain through text only. You need to visualize it. You may put the code in visualgo.net/en/recursion and visualize. But you should know how recursion stack works.

  • @friedrichmyers
    @friedrichmyers 5 หลายเดือนก่อน

    Am I the only one who found it easy and got the answer first try?

  • @thinq5339
    @thinq5339 3 ปีที่แล้ว

    my question is after calling get(1) in get(4) the get(1) should go back to get(2)

    • @codelikeapro9724
      @codelikeapro9724 2 ปีที่แล้ว

      at that point get(1) is branch of get(4) not get(2)..... or you can say get(1) comes from get(4) it will simply retrun back to it...

  • @PriyaSingh-ul4hl
    @PriyaSingh-ul4hl 4 ปีที่แล้ว +2

    What if we are asked about print output. Can anybody explain please?

    • @VikasKumar-xu8if
      @VikasKumar-xu8if 3 ปีที่แล้ว +2

      Output: 12131241213512131246
      and the function will be called 41 times , there is some mistake in above solution (explained in video) as you can check by running the program and counting the calls by a global variable initialized with zero.

    • @uraharakisuke5305
      @uraharakisuke5305 2 ปีที่แล้ว

      @@VikasKumar-xu8if 41 toh option mein bhi nahi hai

  • @s.o.s6201
    @s.o.s6201 3 ปีที่แล้ว

    take a bow... god of C

  • @talentotech-p1e
    @talentotech-p1e ปีที่แล้ว

    I wonder what real program/algorithm would behave like that

  • @compangit1524
    @compangit1524 ปีที่แล้ว

    Answer is Option B, 25

  • @mohammadtaqiahsan5620
    @mohammadtaqiahsan5620 3 ปีที่แล้ว

    May I know your name sir?

  • @brocklesnarufcchamp1
    @brocklesnarufcchamp1 4 ปีที่แล้ว +3

    This question's not worth the trouble for 2 marks

  • @mlungisinkomo2382
    @mlungisinkomo2382 2 ปีที่แล้ว

    DUDE YOU ARE DOPE

  • @cyethacksolutions6761
    @cyethacksolutions6761 3 ปีที่แล้ว +4

    this is code for this recursion to count the Recursion output and count for calling
    #include
    int count=1;
    void get(int n)
    {
    if(n

    • @BilalBerek-tl3tq
      @BilalBerek-tl3tq ปีที่แล้ว

      why do you initialize count from one bro
      what is logic

    • @akashade5031
      @akashade5031 ปีที่แล้ว

      @@BilalBerek-tl3tq to count or include first call to get(6) by main() function

  • @sushantkumar4917
    @sushantkumar4917 3 ปีที่แล้ว +1

    Before starting video I made guss like
    (1+3)*6 = 24, so answer should be 25 😂😂✌️

    • @getayawkaltamrat1314
      @getayawkaltamrat1314 3 ปีที่แล้ว

      you will end up getting an A if you keeping guessing like this :D

  • @harshitpathak5376
    @harshitpathak5376 3 ปีที่แล้ว +1

    So much confusion 😕😐..

  • @NandanKumar-vq9iw
    @NandanKumar-vq9iw 8 หลายเดือนก่อน

    It is wrong:- when get(1) called the function returns there is no way to call get(0)

    • @stepsjr
      @stepsjr 3 หลายเดือนก่อน

      Its not 1 = 1 its n < 1

  • @shaiksameerbasha4702
    @shaiksameerbasha4702 2 ปีที่แล้ว

    👍

  • @hritushreemog9333
    @hritushreemog9333 5 ปีที่แล้ว

    how there is 7 calls , i mean i got confused, i am getting 6 calls which gives me total 24 calls can you elaborate please

    • @zitrakzsingh7295
      @zitrakzsingh7295 5 ปีที่แล้ว +1

      count the get(6) call too

    • @ExploreWithShiva_
      @ExploreWithShiva_ 4 ปีที่แล้ว +1

      First we call get(6) till get(0) total 7 calls

    • @ExploreWithShiva_
      @ExploreWithShiva_ 4 ปีที่แล้ว

      Then iteration

    • @VikasKumar-xu8if
      @VikasKumar-xu8if 3 ปีที่แล้ว

      "get" function will be called 41 times , there is some mistake in above solution (explained in video) as you can check by running the program and counting the calls by a global variable initialized with zero.

    • @asharya5311
      @asharya5311 3 ปีที่แล้ว

      @@VikasKumar-xu8if But 41 is not present in the options.

  • @ruthviksaikalahastri7513
    @ruthviksaikalahastri7513 ปีที่แล้ว

    Answer is (B) 25

  • @latasharma7328
    @latasharma7328 4 ปีที่แล้ว

    N value????

  • @boyarangaswamy3430
    @boyarangaswamy3430 5 หลายเดือนก่อน

    here first iteration get(1)

    • @stepsjr
      @stepsjr 3 หลายเดือนก่อน

      Its not 1 = 1 its n < 1

  • @sagarsahu6959
    @sagarsahu6959 4 ปีที่แล้ว

    This question is very interesting ❤️

  • @psarvani6994
    @psarvani6994 5 ปีที่แล้ว

    Sir how have you gone from step get(4) to get (5) as the value n will be 1 and we need to satisfy the condition n

    • @red_l6634
      @red_l6634 5 ปีที่แล้ว

      yes thats why he writes +2 calls.he means that get(4-3)=get(1) plus what g(1) calls. But we know what get(1) calls!!! it calls get(0) and get(-2) n

  • @psarvani6994
    @psarvani6994 5 ปีที่แล้ว

    Can someone explain me the answer

  • @nedstark9734
    @nedstark9734 5 ปีที่แล้ว +2

    If you solved it in your mind you gonna confuse at some time so I solved it using method II and got correct answer on my first try

  • @shivamrohatgi4495
    @shivamrohatgi4495 3 หลายเดือนก่อน

    not able to understand this one

  • @gauravnegi7871
    @gauravnegi7871 5 ปีที่แล้ว +2

    But there are 24 calls not 25

    • @BilalBerek-tl3tq
      @BilalBerek-tl3tq ปีที่แล้ว

      you did not count first call from main function for get(6).

  • @shubhamjain154
    @shubhamjain154 3 ปีที่แล้ว

    This paper setter will definitely go in hell....

  • @nahidmony7860
    @nahidmony7860 ปีที่แล้ว

    Brainstrorming

  • @real_kim8455
    @real_kim8455 3 ปีที่แล้ว

    When we get the 1st get(0) after that why aren't we pop'ing out all the way back to get(6) & instead going to get(-2)?
    Unable to understand. Please explain.

  • @jeedikantivenkat7814
    @jeedikantivenkat7814 5 ปีที่แล้ว +2

    Guys dont get confused
    Its very easy

  • @charuarora6621
    @charuarora6621 3 ปีที่แล้ว +1

    But when get(1) function is called .. condition(n

    • @areebshaikh321
      @areebshaikh321 3 ปีที่แล้ว +1

      Yes. After get (1) is called ,as (n

    • @chakradharthota1100
      @chakradharthota1100 3 ปีที่แล้ว

      Here get function is not in the if function.. so here condition failed if is not evaluted .. so control reaches to get (0)👍

  • @dilipkumar-ku5jx
    @dilipkumar-ku5jx ปีที่แล้ว

    fun fact: activation record also stores execution line where the function last left its execution and when it returns it starts executing from next line of execution line stored. I hope this comment will reduce the confusions if there are any
    +-------------------------------------+
    | Activation Record for 'get' |
    +-------------------------------------+
    | Parameters: |
    | |
    +-------------------------------------+
    | Local Variables: |
    | |
    +-------------------------------------+
    | Return Value: |
    | |
    +-------------------------------------+
    | Execution Line: |
    | get(n-1); |
    +-------------------------------------+

    • @cqwshi
      @cqwshi ปีที่แล้ว

      do you mean this by saying how the execution flow was from get (n-1) until n =0 and after this the flow was from only (n

  • @ravikiran3455
    @ravikiran3455 2 ปีที่แล้ว

    Awesome Explanation

  • @dakshpatel1769
    @dakshpatel1769 ปีที่แล้ว

    Thank you sir ❤

  • @shibambiswas
    @shibambiswas ปีที่แล้ว

    👍