Types of Recursion (Part 2) | Tail & Non-tail Recursion

  Рет қаралды 286,352

Neso Academy

Neso Academy

Күн бұрын

Пікірлер: 397
@babatundelawal8096
@babatundelawal8096 Жыл бұрын
After searching everywhere for a proper explanation to tail recursion. I found this. This is great, thank you
@hosmjrshinh2675
@hosmjrshinh2675 4 жыл бұрын
9:06 My dear friend let me tell you one thing😘
@sayeedhasansaim8355
@sayeedhasansaim8355 4 жыл бұрын
Both of theme are non-tail recursion. 😊
@josuequintero-td5gh
@josuequintero-td5gh 2 ай бұрын
Does the function stop being called when n overflows?
@mustafaabozaina2787
@mustafaabozaina2787 2 жыл бұрын
Tail recursion performance is considered better than Non-Tail recursion because tail recursion is the last line executed so there's nothing left to do before leaving the function, this helps the compiler to optimize the execution because the function's stack frame need not be saved
@aj.arunkumar
@aj.arunkumar Жыл бұрын
this should hv been included in the video.. thanks
@zhiyizhu3040
@zhiyizhu3040 5 жыл бұрын
Thank you so much! I have been confused whole day about the concept of tail recursion, you just help me to have a good night sleep~
@RitikSharma-pc5yj
@RitikSharma-pc5yj 4 жыл бұрын
same happen with me today...I thought, just wasted my whole day but this video cleared my whole concept. hence my hard work pays off that I found this video....thankyou so much.
@nihalpandey5675
@nihalpandey5675 4 жыл бұрын
Same here
@lakshmiprasannachilukuri8814
@lakshmiprasannachilukuri8814 4 жыл бұрын
I request neso academy to give answers to the home work problems in the comment section...It will be even better if u explain them...
@hetaeramancer
@hetaeramancer 3 жыл бұрын
@Curtis Phoenix no one gives a damn with your instapwn and your second dummy acc...
@laus-thecurious4120
@laus-thecurious4120 2 жыл бұрын
Absolutely right
@kushagraacharya4629
@kushagraacharya4629 2 жыл бұрын
Your message has been successfully read and ignored ✓✓
@tejavathusrilaxmitejavathu5224
@tejavathusrilaxmitejavathu5224 2 жыл бұрын
@@laus-thecurious4120 Good
@sardarzain1066
@sardarzain1066 Жыл бұрын
Yeah
@bhanukumar3364
@bhanukumar3364 5 жыл бұрын
Sir ,why I not met such Teacher during my Graduation, Thanks a lot for wonderful teaching.
@irfansari_
@irfansari_ 2 жыл бұрын
Bro I am in Graduation. and I thing I am lucky to find this teacher
@bhaskarjyotigogoi9236
@bhaskarjyotigogoi9236 4 жыл бұрын
Both are Non Tail Recursive function. In Program 2 the range of int from -2^(31) to +2^(31)-1....When n=2^31 then it exceeds the range of int and again start from -2^(31) which is less than 0..
@nuwaver91
@nuwaver91 3 жыл бұрын
Are they both Non Tail Recursive because printf is the last thing in the function?
@nishantraj9762
@nishantraj9762 2 жыл бұрын
@@nuwaver91 yeah both are non tail recursive function
@p.gaurav.n.m2417
@p.gaurav.n.m2417 5 жыл бұрын
i am very happy that u people are helping us in almost all subjects.On behalf of all , my very big thanks to Neso Academy.......
@adnansarkar9219
@adnansarkar9219 3 жыл бұрын
both program 1 & 2 are non-tail recursion functions, But program 2 has no step to go base so it will be infinite.
@aydinfurkancan
@aydinfurkancan Жыл бұрын
@@s.oktaydonmez649 adamsın knk iyi akıl ettin
@sardarzain1066
@sardarzain1066 Жыл бұрын
Give signed value brother eg -10
@ergenbalik
@ergenbalik Жыл бұрын
@@s.oktaydonmez649 helal
@sruthimajhi5610
@sruthimajhi5610 Жыл бұрын
It has a base cond.
@jsmphompho8052
@jsmphompho8052 Жыл бұрын
@@s.oktaydonmez649 thank you, I also forgot about this fact
@shradhajadhav5609
@shradhajadhav5609 5 жыл бұрын
It's really helpful video, I always confused about recursion function but now everything is cleared about recursion
@RAHULYADAV-zr5fq
@RAHULYADAV-zr5fq 3 жыл бұрын
Hii
@omchoudhary4931
@omchoudhary4931 5 жыл бұрын
Seriously you are doing a great job for all of us . ✌️✌️ Thank you so much 💓💓
@sri7169
@sri7169 3 жыл бұрын
you guys doing a great job helping people WHO LOOKING out for knowledge # EDUCATION IS NOT A BUISNESS
@iuseyoutubealot
@iuseyoutubealot 2 жыл бұрын
100% it shouldn't be
@indhujag5920
@indhujag5920 3 жыл бұрын
Both are non-tail recursion. I executed Program 2 in Visual Studio Code. I took n=3.I got output and it prints from 3,6,12 upto byte limit and again return that from byte limit to 3. Program 2 is not infinte loop. It executes upto the byte limit of the computer and last line is also executed after return.
@randomguy8577
@randomguy8577 2 жыл бұрын
Thanks 😊
@twiz8859
@twiz8859 2 жыл бұрын
But in second program indeed value got true and finally if got executed but there is a printf before recursive procedure and after if being executed, there is, that printf statement left to be executed and second thing we didn't put rescursive procedure in else construct which mean still recursive procedure got executed anyway and in program 1 when value got zero recursive again isn't in else construct it still executed value 0;
@meenalsolanki9286
@meenalsolanki9286 5 жыл бұрын
Your videos really helped me out to understand many things on recursive exactly to the point.
@a_k1817
@a_k1817 3 жыл бұрын
Till now i can say that your LEGENDRY TEACHER
@AdityaSingh-ii4km
@AdityaSingh-ii4km 3 жыл бұрын
@SRI-PRIYAN
@SRI-PRIYAN 4 жыл бұрын
Most of the people think that the 2nd program is wrong and does not converge into the base case but it actually converges... It ia because int overflow even when the output is 1(the smallest positive number) the recursion can run only upto 32 times because an int is 4 bytes which is 32 bits... At n=1 the first bit is set and when n=2 second bit is set and so on... When it reaches the 32nd bit n is no longer a positive number and the program returns.
@kevint3522
@kevint3522 10 ай бұрын
Great comment! I'm glad I scrolled down and found it. Thank you!
@SandhyaSingh-ms6br
@SandhyaSingh-ms6br 4 жыл бұрын
Part 1 and part 2 both are great examples of non-tail recursion, in fact, 2nd code is very useful if you want to revise the concept of range of "int" along with studying type of recursion, ..... In the same code(2nd homework code) if we change any one of the two printf statements and print 2*n instead of n, then we'll notice that as the size of n doubles each time during recursive calling then as it reaches 1073741824, the recursive function that will be called by fun2(1073741824) will be fun2(-2147483648) [since max value of int is 2147483647] and as -214.... is less than zero therefore the base condition is met and thereafter the second printf statement will start getting executed and the functions will simultaneously pop out from the stack. The output obtained in this case (where we are printing 2*n instead of n clearly shows this)
@shreyapatel1400
@shreyapatel1400 3 жыл бұрын
Well explained thnk you dear
@godfather5777
@godfather5777 3 жыл бұрын
This comment should be pinned. Thanku🙌
@sidharthjain2129
@sidharthjain2129 3 жыл бұрын
We will get a palindrome r8? In program 2
@prodiptamondal1758
@prodiptamondal1758 3 жыл бұрын
thanks
@abdousaadi2715
@abdousaadi2715 3 жыл бұрын
cool explanation i thought the program would last forever thank you
@Post-random_post
@Post-random_post 4 жыл бұрын
Amazing lectures i never see this type of explaination aswome
@rking2788
@rking2788 3 жыл бұрын
Your voice is impressive and the way u teach is amazing
@SejalSakhare-y3u
@SejalSakhare-y3u Жыл бұрын
Ans=> PR-1: non-tail recursion function output : 0 (zero) PR-2:non-tail recursion function it is infinite loop.
@aakashverma8602
@aakashverma8602 5 жыл бұрын
both are non-tail recursive function as recursion calll is not the last thing done by funcion
@addagallanaresh4044
@addagallanaresh4044 5 жыл бұрын
print f is also be a functon
@adarshverma013
@adarshverma013 5 жыл бұрын
No only 1st is non-tail because in 2nd function will never return and last printf will never get evaluated so here only function call is the last thing done so tail recursive. No Sorry last printf will be evaluated as integer overflow will occur and n
@omaranas2965
@omaranas2965 4 жыл бұрын
@@adarshverma013 why last print will never evaluated?
@damnnations9308
@damnnations9308 4 жыл бұрын
@@omaranas2965 because it is an infinite loop
@omaranas2965
@omaranas2965 4 жыл бұрын
@@damnnations9308 aha ty bro
@muhammadalidildar
@muhammadalidildar 5 жыл бұрын
@0:50, fun function has type void and yet it is returning some value at line 6 of the code.
@omkargulave5774
@omkargulave5774 4 жыл бұрын
It is returning void function so it is absolutely fine. And other easy way to understand is fun(n) returning to fun(n-1). And if function is void it doesn't mean that function doesn't return anything it returns void.
@ravikumarsunkhesvarapu9122
@ravikumarsunkhesvarapu9122 5 жыл бұрын
Thank you so very much for your wonderful lectures, Sir!!
@Trippykiyay
@Trippykiyay Жыл бұрын
This is the best explanation of recursion that I’ve ever seen.
@devkinandansharma7558
@devkinandansharma7558 3 жыл бұрын
sir I can see your hard work in your videos
@QQ-gn7tc
@QQ-gn7tc 2 жыл бұрын
This channel shoud be given an award from @KZbin.
@rudranshnemade6299
@rudranshnemade6299 3 жыл бұрын
Yes both the 2 programs are non tail recursive because the recursive call is not the last thing done by function and in both the process we need the previous function record.
@sahryun
@sahryun 9 ай бұрын
if thats the case there exist no tail recursion at all, tail recursion should be removed from textbooks
@DandelionHope
@DandelionHope 6 жыл бұрын
A very big thanks to you sir for clearing my doubts on recursion
@robertsedgewick1266
@robertsedgewick1266 4 жыл бұрын
Brilliant explanation, stack frames were very well illustrated!
@kennymccormic7578
@kennymccormic7578 5 жыл бұрын
Sir, thinks so much for that! I've finally got it!
@ninoherrera3944
@ninoherrera3944 4 жыл бұрын
Well explained great job Neso Academy!
@RishiSingh-dj9ou
@RishiSingh-dj9ou 4 жыл бұрын
Such a great teacher @jaspreet sir
@tanviranjum6463
@tanviranjum6463 3 жыл бұрын
Both of them are non - talil recursive function.🙂🙏
@viveknirmal4811
@viveknirmal4811 4 жыл бұрын
PROGRAM 1 = NON TAIL RECURSIVE PROGRAM 2 = TAIL RECURSIVE AS LAST PRINTFF WILL NOT GET EVALAUTE BUT IT LEADS TO STACK OVERFLOW
@tokomnyori6730
@tokomnyori6730 4 жыл бұрын
The printf does evaluate. I've tested both programs and found out that both are non-tail recursive. I entered an input of 8, after hitting 1073741824 it went down to -2147483648 and triggered the base case. After the integer overflow, it prints the result in reverse. Please explain if I'm wrong.
@selvamsaravanan1095
@selvamsaravanan1095 4 жыл бұрын
@@tokomnyori6730 u r ri8
@tokomnyori6730
@tokomnyori6730 4 жыл бұрын
@@selvamsaravanan1095 Thanks 😊
@darshitgajjar5199
@darshitgajjar5199 4 жыл бұрын
Exactly true
@thebeatifulnature3142
@thebeatifulnature3142 4 жыл бұрын
Vivek nirma you are right 1.non tail and 2. Tail because printf is not evolut it may be leads to stack over flow so printf function not be evoluted so it is an tail recursive and in program 1. Fun2(0) arises and then printf should be evoluted so it is non tail
@Chillvibe77
@Chillvibe77 4 жыл бұрын
Your style of explaination is excellent ♥️
@Marianojoey
@Marianojoey Жыл бұрын
Thanks to your Recursion videos not only did I understand this issue, but also learnt something. So thanks. :D
@Aabara_ka_dabara
@Aabara_ka_dabara Жыл бұрын
please also make one vide on void functins and return 0 ,return 1 diffrence
@kousalyakommula1322
@kousalyakommula1322 3 жыл бұрын
sir your channel is a boon for us
@BeastGaming-hq6yu
@BeastGaming-hq6yu 4 жыл бұрын
1 2 non tail 1) value can be zero 2) value can not be zero as well 1) n=4 then 4/2=2 2%2=0 done. 2) n=1 then pt=1 , 2*1= 2 , pt=2 goes on... value wont be zero any value after zero can never be greater then zero.
@Hgh38
@Hgh38 4 жыл бұрын
Finally got it! You are a hero!
@ashishchawla90
@ashishchawla90 2 жыл бұрын
very beautiful explaination ..great work
@niteshmodi5468
@niteshmodi5468 3 жыл бұрын
If teacher like you would be there in college then the scenario of student's life would be different...
@entrtnmnthub5357
@entrtnmnthub5357 3 жыл бұрын
yep...i agree :")
@dr.nicksiz8251
@dr.nicksiz8251 2 жыл бұрын
Thank you all for these videos, my master. Probably you did intently but in the end , program 2 will get an stack overflow error. That doesnt satisfy the base statement.
@kathanparekh6135
@kathanparekh6135 3 жыл бұрын
2:28 Sir VOID return type wala function kuch return nahi karta instead use INT as return type
@riathakur3936
@riathakur3936 5 жыл бұрын
A very big THANKS...... You are really doing a very great job ..... I was really very confused about tail and non-tail both ..... Even after asking my lecturer thrice I won't be able to get it properly..... But u made me understand ...... A very big THANKS again.....
@arasahmad9176
@arasahmad9176 3 жыл бұрын
Because of your legendary lectures, now I fell in love with India.
@atharvakulkarni3007
@atharvakulkarni3007 6 жыл бұрын
1st is Non Tail but 2nd there is no base condition therefore it'll be in an ∞ loop but I can guess it as Tail because there there is nothing to do after calling the function in the function
@AbhishekKumar-kk6qs
@AbhishekKumar-kk6qs 5 жыл бұрын
Your answer is absolutely correct but there is base condition given(n
@kumarparaskaran7598
@kumarparaskaran7598 4 жыл бұрын
@@AbhishekKumar-kk6qs but when 2*n will exceed the integer range based on computer, then n will become negative( let us assume if int is 2 byte then after 32766 n will become -32768) and it will return, so I guess that 2nd is also non tail recursive
@aninditpanigrahi3334
@aninditpanigrahi3334 4 жыл бұрын
@@kumarparaskaran7598 this is the correct analysis !
@azcrypto1565
@azcrypto1565 4 жыл бұрын
both are non-tail recursive function because 2nd function is dependent upon the value you passed, if it will be greater number then the value multiplied with 2 will doubled and so on therefor 3 or 4 values are only printed by 1st printf function and then value will be negative (you know signed int concept) so 2nd printf will execute,too. for ex you can pass n as 536870900(nearer value of max signed value/4) so you get only 3 values WHICH is printed by 1st printf and 3 values which are printed by 2nd printf(which is same but in reverse position). SO, AT THE END NOTH ARE NON-TAIL RECURSIVE FUNCTION
@indhujag5920
@indhujag5920 3 жыл бұрын
No, Program 2 is non - tail recursive. Check out output in Visual Studio code.
@cs21deepalijaiswal84
@cs21deepalijaiswal84 4 жыл бұрын
Thank you so much sir for these lectures.C is our building block and you r letting us learn all our concepts with so ease.Warm regards!!!
@shivdix
@shivdix 11 ай бұрын
Hey depali would you got placed I m from ur clg
@0x656e
@0x656e 4 жыл бұрын
My dear friend you're the best 🙌❤
@RhaenyraT2001
@RhaenyraT2001 Жыл бұрын
why was the activation record of fun(0) not stored in the stack in example 1?? The activation record is stored when a function is called right? fun(0) was called.
@codingawarenes
@codingawarenes 3 жыл бұрын
Veryy nice explanation thank u sir
@kera2403
@kera2403 3 жыл бұрын
In case of tail recursion there is no need to maintain the stack because the function call is the last thing thats happening. That is why tail recursion is preferred.
@KuldeepSingh-rm2nr
@KuldeepSingh-rm2nr 6 жыл бұрын
Best channel to learn data structure....loved it😍
@sagnikmukherjee6604
@sagnikmukherjee6604 4 жыл бұрын
This was a great explanation of the topic that was about to drive me crazy... Thanks and keep it up
@ismailyakini592
@ismailyakini592 2 жыл бұрын
we can't use return in a void function like what did you do in the example of the tail recursion
@otetumooluwaseun3948
@otetumooluwaseun3948 Жыл бұрын
The 1st program is a non-tail recursive, but the 2nd one is a tail recursive program. That is because the recursion will enter an infinite recursion making it impossible for the printf to be executed. Therefore, the recursion remains the last thing to be called.
@tanjibmahammad1216
@tanjibmahammad1216 3 жыл бұрын
Thanks for this, Sir. It saves a bunch of time of mine.
@zawzawwin2918
@zawzawwin2918 5 жыл бұрын
Problem 1 is non-tail recursive and Problem 2 is infinity loop ........ I don't know please anyone know it explain me ...
@rachitsingh8040
@rachitsingh8040 4 жыл бұрын
yes there should be a return after printf. void func(int k){ if(k==0){ return; } func(k-1); printf("%d",k)' return; }
@nik-ys8ki
@nik-ys8ki 4 жыл бұрын
no u r wrong it will stop at the same value which will be passed to it
@kushalavardhan
@kushalavardhan 4 жыл бұрын
It must be like this. void func(int k){ if(k==0){ return; } return func(k-1); printf("%d",k); }
@azcrypto1565
@azcrypto1565 4 жыл бұрын
both are non-tail recursive function because 2nd function is dependent upon the value you passed, if it will be greater number then the value multiplied with 2 will doubled and so on therefor 3 or 4 values are only printed by 1st printf function and then value will be negative (you know signed int concept) so 2nd printf will execute,too. for ex you can pass n as 536870900(nearer value of max signed value/4) so you get only 3 values WHICH is printed by 1st printf and 3 values which are printed by 2nd printf(which is same but in reverse position). SO, AT THE END NOTH ARE NON-TAIL RECURSIVE FUNCTION
@manvithavemulapalli2535
@manvithavemulapalli2535 4 жыл бұрын
really good viedio I have ever seen tq neso academy!!!
@mr.schrodinger7
@mr.schrodinger7 Жыл бұрын
1st is non tail recursive. 2nd is tail recursive
@arvindersingh9863
@arvindersingh9863 5 жыл бұрын
Program 2 : base case not correct; Will execute till the stack overflow
@daverussell4052
@daverussell4052 3 жыл бұрын
what if the n is negative value?
@tusharmathur5360
@tusharmathur5360 3 жыл бұрын
@@daverussell4052 for neg it will not overflow
@bhavyaj3069
@bhavyaj3069 3 жыл бұрын
I think for negative value it will return back to main() [or the function that called it] Because.. the if condition becomes true so it returns back to the function that called it..
@arunkumarkurapati8093
@arunkumarkurapati8093 10 ай бұрын
Both of the given questions are the examples of non-tail recursive functions. As we are performing a modulo operation in the printf statement of first program and printing the value of n in the second program.
@abhaypratap9898
@abhaypratap9898 3 жыл бұрын
Please suggest any book for such questions 🥺🥺🥺
@tokomnyori6730
@tokomnyori6730 4 жыл бұрын
I've tested both programs and found out that both are non-tail recursive. I think the second program is not infinite because integer has its limit and it overflows and becomes zero or negative value. I entered an input of 8, after hitting 1073741824 it went down to -2147483648 and triggered the base case. Please explain if I'm wrong.
@konstantinrebrov675
@konstantinrebrov675 6 жыл бұрын
Both are non tail recursive. Why? Tail recursion is if the recursive function call is in the tail of the function, and there are no more operations like printing or multiply *. If there is nothing to be done after the next recursive function call, all the local variables calculations already happened and we don't need them anymore. In other words after executing the next recursive function call we will not need to access any data in the current stack frame anymore. If we do not need to access any data in the current recursive function call, we can just overwrite the current stack frame with the next stack frame. For both programs we are printing the int n after we are making the recursive function call, after we return. However, the value of int n is different for each recursive function call. Therefore the compiler has to store runtime stack to save us the state of the previous recursive function calls. If after we return from the recursion we will not use any local variables any more, we are telling the compiler to not save the current state of the runtime stack. So the compiler sees that the recursion is in the tail, and after that the function does not access any local variables so it can simply over write the current stack frame with the next stack frame.
@jacquelinepang7853
@jacquelinepang7853 4 жыл бұрын
^ I believe this
@jagdeepsingh-tv4ty
@jagdeepsingh-tv4ty 5 жыл бұрын
program 2 will fallback ,it will not go into infinite loop may be the stack has limited memory
@bhuwan9991
@bhuwan9991 6 жыл бұрын
program 1 is non tail recursive , but I can't say about program 2 because it will call itself again and again. since n*2 will increase the value passed to the fun2 and it will never go to the end condition i.e. n
@dagadoom
@dagadoom 5 жыл бұрын
I guess the integer overflow explains the function getting terminated
@indhujag5920
@indhujag5920 3 жыл бұрын
No, Program 2 is non - tail recursive. Check out the output in Visual Studio code.
@nehagull1052
@nehagull1052 4 жыл бұрын
sir can you please make a video on binary recursion??
@nik-ys8ki
@nik-ys8ki 4 жыл бұрын
program 1 - not-tail program program 2: this program is very interesting though . if u paas a value than it will stop at that same value because when it exceeds the range of data type it has to come back.
@lakshitavij8600
@lakshitavij8600 4 жыл бұрын
Can u please send me solution of these homework problems
@lakshitavij8600
@lakshitavij8600 4 жыл бұрын
I can't solve this
@indhujag5920
@indhujag5920 3 жыл бұрын
@@lakshitavij8600 Program 2 is non - tail recursive. Check out output in Visual Studio code.
@nickbeats9883
@nickbeats9883 3 жыл бұрын
This activation record thing is cool
@charuarora6621
@charuarora6621 3 жыл бұрын
Recursion is my fear point in C programming 🙌🏻 but if(!rocketscience){printf("It can be learned ");
@abigailbusch754
@abigailbusch754 3 жыл бұрын
This was so incredibly helpful!!!
@krishpatil9609
@krishpatil9609 4 жыл бұрын
I assumed n==5; When fun(2*5) will be called, it will start to print 5 10 20 40.......1342177280 Iteration/recursion is possible until value of n reaches 2147483647(max range for signed int) Since we are using fun(2*n) i.e. when value of n reaches 1342177280 then after 2*n will exceed the range of n i.e. fun(2684354560) , i.e. value of n will become -ve (lec 8). And as stated if(nn i.e. n=1342177280 i.e. fun(2*671088640) and fun will pop out then 671088640 then fun will popp .... ..... n=10 i.e. fun(2*5) Now fun(2*5) will popp out and control will return to main and then main will popp out.
@krishpatil9609
@krishpatil9609 4 жыл бұрын
This is for 2nd program.
@azcrypto1565
@azcrypto1565 4 жыл бұрын
both are non-tail recursive function because 2nd function is dependent upon the value you passed, if it will be greater number then the value multiplied with 2 will doubled and so on therefor 3 or 4 values are only printed by 1st printf function and then value will be negative (you know signed int concept) so 2nd printf will execute,too. for ex you can pass n as 536870900(nearer value of max signed value/4) so you get only 3 values WHICH is printed by 1st printf and 3 values which are printed by 2nd printf(which is same but in reverse position). SO, AT THE END NOTH ARE NON-TAIL RECURSIVE FUNCTION
@sowbhagyalakshmi7984
@sowbhagyalakshmi7984 2 ай бұрын
This channel ❤❤
@AbdallahAnalyst
@AbdallahAnalyst Жыл бұрын
i really appreciate this effort thank you very much❤❤❤❤
@Rani_6329
@Rani_6329 2 жыл бұрын
Thank you so much....very useful 👍
@anjaneyuluperam6076
@anjaneyuluperam6076 5 жыл бұрын
both r non tail recursive functions
@paurushgargtube
@paurushgargtube 4 жыл бұрын
Such a good explanation
@rushikothari1261
@rushikothari1261 4 жыл бұрын
Program 2 will make function call until Stack overflow condition occur. Hence the Output is Stack overflow Error. And it is Tail recursion
@nandinisunkara4070
@nandinisunkara4070 4 жыл бұрын
How is it tail? If the condition changes,It will be non-tail.
@rushikothari1261
@rushikothari1261 4 жыл бұрын
@@nandinisunkara4070 Does 2nd printf Executed atleast 1 time ? Ans is No.. Therefore, programs are just like Pf() Recursive()
@tokomnyori6730
@tokomnyori6730 4 жыл бұрын
Not stack overflow, integer overflow. Stack overflow is different than integer overflow. Both are non-tail recursive. In the second program, integer will hit its limit and will become negative negative number and it will hit the base case. It is non-tail recursive because it will evaluate the printf statement below.
@rushikothari1261
@rushikothari1261 4 жыл бұрын
@@tokomnyori6730 In which data structure Integer are stored in Computer?
@indhujag5920
@indhujag5920 3 жыл бұрын
No, Program 2 is non - tail recursive. Check out output in Visual Studio code. Func will just executes upto the Byte limit and starts returning back and last line is executed.
@belwizdadimed3967
@belwizdadimed3967 6 жыл бұрын
The stack usage is the same. you didn't show the optimization (by compiler) gained from the fact that it's a tail recursion. Someone can argue about the need to differentiate them since we may assume that explicit/implicit return is the last instruction that triggers the stack pop().
@konstantinrebrov675
@konstantinrebrov675 6 жыл бұрын
use gcc -O2 to enable tail recursion in C.
@belwizdadimed3967
@belwizdadimed3967 6 жыл бұрын
Konstantin Rebrov you didn't understand my point and hrnce you're responding to a question I didn't ask
@vaibhavshreenamdev8392
@vaibhavshreenamdev8392 5 жыл бұрын
sir in homework problem there is a function called main( ),its not mentioned so where should i start execution ?? i'm confused....
@madugulajoshi5050
@madugulajoshi5050 3 жыл бұрын
Same doubt
@006daredevil
@006daredevil 3 жыл бұрын
you have to assume any number and assume that fun2() function is called from main() function and passing a value to it.
@ashu3128
@ashu3128 3 жыл бұрын
int main() { printf(''%d'',fun2(any number here)); }
@MuhammadNaveed_51
@MuhammadNaveed_51 10 ай бұрын
great job man
@april63382
@april63382 3 жыл бұрын
hi, i want to ask question about the function in 08:49. I dont understand what the purpose of this function , for example, when n=4 the output:2, when n=3, the output:1. what are the meanings of the results? thank you.
@mohit6807
@mohit6807 2 жыл бұрын
It's so silly of me to reply your comment because now you already know the answer but As 3/2=1.5 but it is an integer variable so it will ignore the values after the dicmal Hope you get it know 😜😜
@nuwaver91
@nuwaver91 3 жыл бұрын
Are they both Non Tail Recursive because printf is the last thing in the function?
@niteshmodi5468
@niteshmodi5468 3 жыл бұрын
Thanks for the lecture especially the tail recursion part which was very confusing for me..
@maksberlec4832
@maksberlec4832 4 жыл бұрын
Both functions are non-tail. They all have printf after the function call.
@madhusudansahu5482
@madhusudansahu5482 4 жыл бұрын
2nd is not a recursive program
@maksberlec4832
@maksberlec4832 4 жыл бұрын
@@madhusudansahu5482I do not know how you came to this conclusion. The second function is recursive for sure because it call itself. The recursion is also non-tailed. The n variable become negative because it overflows at 2^31 (integer variable). After that the second printf gets executed. Finally I tested my conclusion with the program: #include #include void fun2(int n) { if (n
@anshikayadav7857
@anshikayadav7857 4 жыл бұрын
Can u explain the line of yours "n becomes negative bcz it overflows at 2^31." a bit more. I'm not able to grab this concept clearly.
@d_agudo
@d_agudo 4 жыл бұрын
thank you very much for this amazing video! helped me out!!
@saumyashrivastava30
@saumyashrivastava30 5 жыл бұрын
Good video 👍
@rounakbiswas3590
@rounakbiswas3590 6 жыл бұрын
Sir will you not update the videos in reasoning and aptitude Playlist?? You said there will be 250 videos but alas there are only 20. Thanking you in advance.
@saifahmedsunny
@saifahmedsunny 4 жыл бұрын
Thankyou neso academy
@shikshitverma1684
@shikshitverma1684 4 жыл бұрын
Sir plesse give the answer of homework problem in the next video for satisfaction.
@yaxinee
@yaxinee 25 күн бұрын
Thank u that what i needed
@chitrangreddy6479
@chitrangreddy6479 4 жыл бұрын
1 st one is non tail recursive and second one is tail recursive ...❤
@brocklesnarufcchamp1
@brocklesnarufcchamp1 4 жыл бұрын
How come the second one is tail recursive?
@anshiporwal2624
@anshiporwal2624 3 жыл бұрын
@@brocklesnarufcchamp1 perhaps there is nothing to evaluate after function calling they simply print n
@unknownfacts8929
@unknownfacts8929 10 ай бұрын
Both are non-tail recursive 😊
@DSAbyraj1729
@DSAbyraj1729 3 жыл бұрын
thank you sir .well expalained
@engineer_b_a_b_u
@engineer_b_a_b_u 9 ай бұрын
@neso Academy Here void fun(int n) is void type then you're writing return statements. Is it not an error??
@andistheinforitbutso7513
@andistheinforitbutso7513 3 жыл бұрын
Awesome 👌
@shanthiyasekar7317
@shanthiyasekar7317 4 жыл бұрын
First program is non tail recursive function and the second one is infinite
Advantage and Disadvantage of Recursion
5:01
Neso Academy
Рет қаралды 139 М.
Types of Recursion (Part 1) | Direct & Indirect Recursion
9:45
Neso Academy
Рет қаралды 293 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Tail Recursion Explained - Computerphile
16:05
Computerphile
Рет қаралды 177 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,3 МЛН
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 259 М.
Recursion in C
11:12
Neso Academy
Рет қаралды 975 М.
C_107 Types of Recursion-part 2 | Tail and Non-Tail Recursion
18:57
Jenny's Lectures CS IT
Рет қаралды 114 М.
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 949 М.
Call By Value & Call By Reference in C
8:34
Neso Academy
Рет қаралды 1,4 МЛН
Recursion in Programming - Full Course
1:51:36
freeCodeCamp.org
Рет қаралды 978 М.