Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4) The Collatz. Conjecture, also known as the 3n+1 problem, is the hypothesis that i in the following algorithm will always reach the value 1:
4) The Collatz. Conjecture, also known as the 3n+1 problem, is the hypothesis that i in the following algorithm will always reach the value 1: 1. Let i be a positive integer 2. If i is 1, stop 3. If i is even, divide i by 2 4. Otherwise if iis odd, multiply i by 3 and add 1 5. Go to line 2 For instance, if i starts at 5, we have the sequence: 5 16 8 4 2 1 and if i is 12: 12 6 3 10 5 16 84 2 1 Mathematicians are interested in whether or not this sequence will always reach 1 (there are no known counterexamples), and in how many steps it takes to reach 1 (above, 5 takes 5 steps and 12 takes 9 steps) Write a Java method, int collatz(int i) that returns the number of steps to reach 1 on input
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