wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Implementing recursive relations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Implementing recursive relations" Watch "Implementing recursive relations" New topic
Author

Implementing recursive relations

Mark Rem
Greenhorn

Joined: Dec 11, 2004
Posts: 13
I'm fairly new to java and I have this assignment to do? How would i go about doing this?

Implement a program which computes the following recurrence relation:

f(1) = 1; f(2) = 1; f(3) = 1; f(4) = 1; f(5) = 1;

f(n) = f( n - 1 ) + 3 * f( n - 5 ) for all n > 5

Display the results for n = 6, 7, 12, and 15
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
A Java method can call itself without any special syntax.

Please show us the code you have so far.


Mike Gershman
SCJP 1.4, SCWCD in process
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
But it may be that an iterative solution would be more computationally efficient?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
it may be that an iterative solution would be more computationally efficient

... unless the assignment called for the use of recursion.
Mark Rem
Greenhorn

Joined: Dec 11, 2004
Posts: 13
I don't even know how to get started..
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I'll gve you an example:


Now deal with the boundary conditions (what if i=1 or i=2?) and also modify the equation to fit your assignment.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I'll gve you an example:


Now deal with the boundary conditions (what if i=1 or i=2?) and also modify the equation to fit your assignment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing recursive relations