So I am doing some practice problems both to better my understanding of code, as well as practice for some upcoming interviews but I am having trouble understanding running time in Big O. The question was:
You have a staircase with N steps, and you can take any mixture of single and double steps to reach the top. How many different ways can you climb the staircase?
I made a simple answer to the problem
//When the function is first called, I set the second argument, x, to 0
int count_steps(int n, int x){
if(x==n){
return 1;
}
else if(x>n){
return 0;
}
return count_steps(n, x+2) + count_steps(n,x+1);
}
If someone could either give me an answer, or a good explanation on how Big O works with recursion I would appreciate it. Also if you have any ideas on more efficient solutions I'd appreciate any kind of hint, because I'm working to improve it too.