0

A function f is defined as:

f(n) = n if n < 4

and

f(n) = 2f(n − 1) + 3f(n − 3) + 4f(n − 5) if n ≥ 4.

.

It asks us to implement two functions...

1) One where it has a recursive function with a recursive process

2) Another where it has a recursive function with an iterative process

I searched online for explanations of the iterative process, and I do understand it well. For further context, here is a link to another StackOverflow question where the community explains it really well (with a similar problem): No idea how to solve SICP exercise 1.11

My issue is applying the iterative process concept to this particular question, I can't seem to do it as maybe my understanding isn't as good as it seems. I have a recursive process solution to this question (below), just having a lot of trouble converting it to an iterative (tail-end) process.

My solution to the recursive process method

If anyone knows anything about iterative processes or could provide a solution to this question (Preferably in Scheme Dr. Racket), I would find it extremely helpful.

Micho
  • 3,929
  • 13
  • 37
  • 40
Zykoma
  • 1
  • 2
    Please don't post pictures of text. DrRacket's copy and paste commands are fully functional. – molbdnilo Feb 15 '18 at 08:26
  • 1
    It's exactly the same problem as the one you linked to but with a larger state (five state variables instead of three). – molbdnilo Feb 15 '18 at 08:31
  • 1
    You mean that if I tell you what the numbers are for the 5 previous values you do not know how to compute the next? This and the question you linked to can be solved by holding enough of the previous values to compute the next one. In the linked question it is 3, but in your case it's 5. Go back and read the accepted answer since that is the solution to this question. – Sylwester Feb 15 '18 at 11:34
  • I've added [an answer there](https://stackoverflow.com/a/48814182/849891) at the link question, trying to explain the thought process, with some pseudocode and Wikipedia links. see if it helps. (just write few equations below one another, for f(n), f(n+1), f(n+2)..., until you see the way). – Will Ness Feb 15 '18 at 18:56
  • I was still under the impression that it was still 3 state variables for some reason, but the information that I needed 5 state variables was very helpful! Thank you, it led me to implement the code correctly. – Zykoma Feb 16 '18 at 00:30
  • @Zykoma if you read through the blog post linked at the question that you mention, you'll see your problem stated and solved in the comments. – Will Ness Feb 18 '18 at 10:00

0 Answers0