Question
/** * Two implementations of the factorial function. * This is just a place holder class for the two functions * * @author Charles Hoot
/** * Two implementations of the factorial function. * This is just a place holder class for the two functions * * @author Charles Hoot * @version 4.0 */ public class RecursiveFactorial {
/** * The basic recursive factorial. * * @param n The number to compute factorial of. * @return n factorial. */ public long basic(long n) { long result = 1; if (n > 1) result = n*basic(n-1); return result; } /** * The tail recursive version of factorial. * * @param n The number to compute factorial of. * @return n factorial. */ public long tailRecursive(long n) { // IMPLEMENT THIS METHOD USING THE RECURSIVE HELPER FUNCTION // AND RETURN SOMETHING APPROPRIATE return 0; }
/** * The tail recursive helper function for factorial. * * @param n The number to compute factorial of. * @param partial The partial result that is being built up. * @return n factorial. */
private long helper(long n, long partial) { long result = 0; // IMPLEMENT THIS TAIL RECURSIVE METHOD return result; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started