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
This is high quality for a UA-cam channel on CS. Great Job from the US.
@@sohamshinde1258 he said he's from the US
All are INDIANS
@@hetaeramancer 😂 he wasted his time on Duolingo.✅
one day there will be billions of viewers in your tutorial
it should be but people ain't too much interested in studying unlikely they are busy unnecessary drama..
@@sarfaraz6582 You got a girlfriend?
Don't waste time in bf or gf or any other human being, invest only on YOU
@@fortnitelove8129 yeah forreal
not really billions, but several millions!
I have never found such a channel that is so good at explaining CS stuff. Great job.
I've never seen any sir as you explain about C language.
You're the God of C. Love you sir 😍
Ya, He is God of C😍😍
Amazing, I like the stack diagram, helps u visualize the whole process
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
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.
One of the best online playlist to learn recursion . Sir please if you could make a series on backtracking and dynamic programming as well. _/\_
I totally agree with you.
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
Best explanation of this material on YT. Thank you!
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.
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
Answer for homework problem is 15. Thank you
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();
}
what's the output?
@@hetaeramancer output is same as in the question.... I've tested it after that i posted it
Sir you explained it very well . nobody can explain like this 👌👌👌👌
sir,thank you soo much ....
these videos are very helpful for many students like me..
once again thank you soo much sir...
Thank you for this class. It opened my mind to a hard task I was doing.
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);
}
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"??
Same doubt pls ans
Thank you,God bless you
wow..amazing
sir at 5:04...in cases like these ...will post increment operator not be a problem?
Thank you very much. Do we still return statement for void return type?
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
Over Here how after decreament in even function the n value increases by 2 ?????
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
Mission accomplished, respect++
You are an outstanding explanation sir but what you have written is that syntax or example? Please give me reply sir
Example ig
Nice and very well explained.
Sir for this programme we need to write the even and odd logics right
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.
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 .
is it necessary to use return; ??? if it is not used then also result will be same right??
Then what is significance of writing "return 0" in main function?
In the void functions, why u typed return?
Yea I too have same doubt
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
I think hence the base case is been define, doesn't matter whether in an if or while.
it's wonderfull explanation
Hello when we return value why void came instead of that int may be come
What would have happened if there was pre increment in place of post increment?
Sir why is void used before function??
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);
}
}
Love from Pakistan thanks too much sir g
Very awesome lectures 👌
Amazing. Go on.
Amazing video thank you for explain it
your voice >>>
Great explanation❤
that's neat and clear...gud job
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
This one is which problem Bhai.. print o/p upto from 1 to 10 numbers
Excellent
are those types applicable in java?
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
Why we have declared int n =1; in a global variable or not as an inside main function?
because if not, it will only be available in main function. unless u use call by reference(pointer).
Wow. This is really helpful
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"??
you are the best
you basicly dont need the return because void functions is a non-return functions
You made it seem so easy
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.
GOOD sir
Omg...where i was... thnk u
how the return; works?
Pls. Explain..
Thank You sir
Very nice explanation
suprab expalnation sir
sir,please solve indirect recursion question, gate 2017
Sir ouput should show in opposite order because it was in stack
Well explained.
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?
Because we're using a void data type so it doesn't expect anything in return
@@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.
@@FarhanAli-gd2qv probably your compiler is smart lol
Well then I can't say
@@bablu1921 you can try it too in the visual studio code.
@@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 ?
Thanks sir
❤❤❤
Please upload video fastly sir
It’s a kind request
Really osm concept😍
isnt it dynamic scoping then?
Why is only odd function called in the main function? Why Even function is not called?
Why do you not execute the code
Is it the same as Trampoline function?
what's that?
You sure WAP is 'write a program"?,lol🙃
I came looking for this comment 😂
Nicely explained
But how does the compiler know that which is odd number and which is even ??
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
compiler knows some inbuilt functions ig
Can we write even (n++) instead even ( )
And not write n++
Yea it works
realy helpfull
By what date should we expect next lectures?
if we are already incrementing the value of n in the printf function then why are we incrementing it again??
incrementation of n variable in both functions are necessary.
Dry run your program then you will get to know.
Void odd()
It's return how it is possible
Void means it's doesn't return???
Hey odd and even function not return any value, it only print on its own function but doesn't return any value.
Why we write return statement??
@@sahilsaxena8374 to return some value to the function
@@sahilsaxena8374 to stop the execution of that function and return to previous function
Nice question 👍
Superb
Respect....
Thank u
We are returning an integer to the main fun but why is the data type of odd fun and even fun void
In function defination why we are using void odd,void even
Same doubt
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
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?
By calculating time and space complexity.
#include
int i;
int main()
{
for(i=1;i
Comment for myself: Indirect Recursion happens, when the recursion doesn't only happen on the function body alone of the function caller.
sir it is not working it programe goes to infinity
awesome
in the even function, the if condition and the return statement are useless.
I wish i thought of WAP as write a program...
If somebody wants to know the same program without indirect recursion 👇
int main()
{
for(int i = 1; i
Man jae sir
Mast
WAP == Write a program
Everybody knows that 😂
Code don't get executed properly
Output is not what is revealed in video
Hello Sir I got wrong ouput