18 Replies
with this as input f(f(4,2), 1)
it stops running after y == 0 or y == x right
Yes, it's a recursive function, so it calls itself until the y is eqal to 0 or y is equal to x. I recommend to write a tree of calls on a paper
i did
i have a question about when f(4,2) is done though
since the input is x and y
with y being 1 for example
and x is 4,2?
how does that work
Okay so at first you go into the most nested call, which is f(4,2) and analyze it. The f(4,2) returns f(3,2) + f(3,1) and so on and so on - the result of this recursion which I believe is 6 and then you analise f(6, 1).
ye i have 6 aswell
so after f(4,2)
it just takes 6,1
then it will continue again?
Yes - you got f(6, 1) right now
And you need to perform the same analysis
ye its just that in the answers they said it was 6
but thats a bit weird
they didnt explain the answer though
Hmmm strange thing, let me check it on my paper
Okay the answer is for sure 6 - I've incorporated it to the Raider and run the function in a programm, but now we need to answer why 😄
ah oke
Ah
The answer is 6
Because f(6,1) is equal to 6 😄
i wrote it down if u do 6,1 the outcome is also 6
Yes
I was a bit confused
But yeah
That's allright
so it doesnt take the first part into account
It takes it as an argument to a new call
so It would be like invoking f(6, 1) by hand
but here you calculate the x argument with that function also
you could do even f(f(4,2), f(0,0) it would produce the same outcome
f(f(4,2), f(0,0)) *
i think i get it
thanks for the help
You're welcome
If you got any more questions feel free to attack up
This question made me realize that I suck at recursive stuff and need to learn it better
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.