Question: I need Help for these 2 questions, please Loop 3: Create your own loop! (write the code here) A) What is the Big-Oh running time
I need Help for these 2 questions, please
Loop 3:
Create your own loop! (write the code here)
A) What is the Big-Oh running time ?
B) Run the code with several values of N.
C) Create a table with at least 5 different values of N with the run time in milliseconds.
Part 2:
Base Conversion
Write a program that uses recursion to convert a base 10 number into a base b number, where b < 10. If the number to be converted is n, then the algorithm to convert n to base b is:
1) Divide n by b. Store the quotient and the remainder.
2) The remainder is the rightmost digit of the final answer.
3) The quotient is now the new number n that you will recursively convert to base b.
4) Repeat step a by calling your recursive method with the quotient and the original base b.
5) Stop when n / b = 0. The remainder at this point will be the first digit of the final answer.
For example, to convert 30 into a base 4 number:
Quotient Remainder
30/4 7 2
7/4 1 3
1/4 0 1
The answer is the remainder column read bottom to top, so 30 (base 10) = 132 (base 4).
A skeleton of the recursive method is given below.
public static String convert(int number, int base)
{
int quotient =
int remainder =
if( )
return( + );
else
return( ) + );
}
Sample Output:
|
Enter a number to convert: 48 Enter a base to convert to: 8 48 converted into base 8 is 60.
Enter a number to convert: 157 Enter a base to convert to: 2 157 converted into base 2 is 10011101.v |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
