Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

LO 8-1 Outline the basic principles of organization management.

Answered: 1 week ago

Question

suggest a range of work sample exercises and design them

Answered: 1 week ago