Why we are taking base case in this problem as
if(n==0)
{
return 1;
}
if no friend is there , then how it is 1 way to go to the party??
Why we are taking base case in this problem as
if(n==0)
{
return 1;
}
if no friend is there , then how it is 1 way to go to the party??
hello @CODER_JATIN
people explain this case like->
for n =0 there is no way so they count this also as one way.
but if u dont want ot make this as ur base case then simply add these two base case
if n==1 // one persone so only one way
return 1
if n==2 // two person so two ways (alone + pair)
return 2
Okay Okay , and Aman bhaiya one thing more i want to know is that , how do i approach these kinds of problem in which we have to calculate the number of ways using recursion.
a)try to break problem into subproblem (dry run on some cases on paper may help)
b)
PNC knowledge will also come very handy in such kind of problem.so ready its basics
c) practice
Okay aman bhaiya, Thank you