0% found this document useful (0 votes)
40 views1 page

Practice 1: Recursive Algorithms: Analysis and Design of Algorithms April 19, 2017

The document describes implementing a Recursive class containing several recursive algorithms as static methods: factorial, hanoi, fibonacci, division, addDigits, gcd, multiply, and maximum. These methods recursively calculate factorials, solve the tower of Hanoi problem, generate Fibonacci sequences, perform division via subtraction, add digits of a number, find greatest common divisors, multiply arrays, and find maximum array elements. The methods are to be tested using a provided Test class.

Uploaded by

Francisco Quinga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Practice 1: Recursive Algorithms: Analysis and Design of Algorithms April 19, 2017

The document describes implementing a Recursive class containing several recursive algorithms as static methods: factorial, hanoi, fibonacci, division, addDigits, gcd, multiply, and maximum. These methods recursively calculate factorials, solve the tower of Hanoi problem, generate Fibonacci sequences, perform division via subtraction, add digits of a number, find greatest common divisors, multiply arrays, and find maximum array elements. The methods are to be tested using a provided Test class.

Uploaded by

Francisco Quinga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practice 1: Recursive Algorithms

Analysis and Design of Algorithms

April 19, 2017

Implement a class called Recursive, which contains dierent recursive algo-


rithms. These recursive algorithms will be implemented as static methods of
the Recursive class. The methods to implement are the following:
public static int factorial(int n) : this method receives a positive integer
(n), and returns the factorial of that number.
public static void hanoi(int n, char s, char a, char t) : this method receives
a number of disks (n) and three characters corresponding to the source,
auxiliary and target pegs (s, a, t), and prints the movements that need to
be preformed to reach the solution of the tower of Hanoi for n disks.
public static int bonacci(int n) : this method receives a positive integer
(n), and returns the n rst terms of the Fibonacci sequence.
public static int division(int a, int b) : this method receives two positive
integers (a and b), and returns a divided by b by means of successive
subtractions.
public static int addDigits(int n) : this method receives a positive integer
(n), and returns the addition of the digits of that integer.
public static int gcd(int a, int b) : this method receives two positive integers
(a and b), and returns their greatest common divisor (gcd).
public static int multiply(int[] a, int n) : this method receives an array
(a) and the size of the array (n), and returns the multiplication of the
elements in the array.
public static int maximum(int[] a, int n) : this method receives an array
(a) and the size of the array (n), and returns the maximum element in the
array.
The class Test is provided to test these methods.

You might also like