Question: Exercise 2 . 3 2 . ( ? ) This question has three parts. ( a ) Design the standard recursive collatz method, which receives

Exercise 2.32.(?)
This question has three parts.
(a) Design the standard recursive collatz method, which receives a positive integer and
returns the Collatz sequence for said integer. This sequence is defined by the following
recursive process:
collatz(1) D 1
collatz(n) D collatz(3* n +1) if n is odd.
collatz(n) D collatz(n /2) if n is even.
The sequence generated is the numbers received by the method until the sequence reaches
one (note that it is an open research question as to whether this sequence converges
to one for every positive integer). So, collatz(5) returns the following String of
comma-separated integers: "5,16,8,4,2,1". The last number cannot have a comma
afterwards.
(b) Then, design the collatzTR method that uses tail recursion and accumulators to solve
the problem. Hint: you will need to design a private static helper method to solve
this problem.
(c) Finally, design the collatzLoop method that solves the problem using a loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!