Menu

[Solved]G Implement Numbersoe Sequence 1 1 2 3s 2 Following Method Returns Ith Number Fibonacci Fi Q37039382

don’t do 6and 8
g implement numbersoe sequence: 1,1,2,3s 2. The following method returns the ith number in the Fibonacci fib(o) returns 1: fi34 Laboratory write a recursive method that returns the maximum integer in the array it is passed. your method by passing itg implement numbersoe sequence: 1,1,2,3s 2. The following method returns the ith number in the Fibonacci fib(o) returns 1: fib(1) returns 1; fib(2) returns 2, fib(3) returns a bers returns 5, fib(5) returns 8, and so on. 8, 13,…. Each number after the first two is the sum of the two preceding nu 3, fib(4) public static long fib(long i) if(i < 2) return 1; return fib(i 1) fib(i 2); Each time you call this method and pass it a value greater than or equal to 2, it coltl. 1) and fib(1 fib(i 2)). Asa result, self twice because it has two recursive calls (fib(i the total number of calls can become excessive, making this method extraordina inefficient. Write a program that includes this method. Your program should pr narily prompt for and read in an integer. It should then call fib passing it the integer read. For what integer passed is the program’s run time 10 seconds? Double the integer passed and rerun your program. Does the run time also double? Again double the integer passed and rerun. What is the relation between the integer passed and run time? 3. Implement the fib method in Lab Exercise 2 using a loop instead of recursion. Per . Rewrite the reverse method in Fig. 14.6. Reverse a string by placing its last character Rewrite the reverse method in Fig, 14.6. Use the reverse method in the String Write a method that does multiplication on nonnegative integers using recursion. e loop implementation more efficient? at the beginning of the reverse of the substring that contains the entire string except for its last character. Test your program Buffer class. Test your method by using it to compute the product of 0 and 0, the product of 0 and 5, the product of 5 and 0, and the product of 5 and 10. Hint: axb aX (b 1) a for b> for b0 the string Write a recursive method that returns the number of occurrences of ‘A’ int t is passed. Test your method with the following strings:” “, “A”, “B”,”BCA” and “ABACAD 34 Laboratory write a recursive method that returns the maximum integer in the array it is passed. your method by passing it a 20-slot int array initialized with random integers. Test nt() in the Random class. Use the seed 1 when you con- Generate integers with nextI struct the Random object. A recursive method does not have to first recurse down and then up. It can first recurse up and then down. Write a recursive method that returns the sums of the integers from 1 to n when passed n. Your method should first recurse up, hit the top when the parameter is equal to the largest integer to be summed, and then recurse down. (Hint: Your method should have two parameters.) 10. Write a method that implements Ackermann’s function: Ack(x, y) y 1 when x 0 when x > 0 and y=0 when x Ack(x, y)Ack (x-1,1) ACK (x, y)-A(x-1, A(X,y-1)) > 0 and y > 0 Use type long, write a program that displays the value of Ack (n, n) for n ,1、 0, 1, For what value of n is the value of Ack (n, n) too large for type long? Acker- mann’s function is famous because Ack (n, n) grows so rapidly with increasing n. I. Write a recursive method that determines if the first string it is passed is a substring of second string it is passed. Test your method with the following pairs: and “A”, C. and ABC, an the “АВС”, “ABC” and “ABC”, “mine” and . determines”, “minee. and determines”. Show transcribed image text g implement numbersoe sequence: 1,1,2,3s 2. The following method returns the ith number in the Fibonacci fib(o) returns 1: fib(1) returns 1; fib(2) returns 2, fib(3) returns a bers returns 5, fib(5) returns 8, and so on. 8, 13,…. Each number after the first two is the sum of the two preceding nu 3, fib(4) public static long fib(long i) if(i for b0 the string Write a recursive method that returns the number of occurrences of ‘A’ int t is passed. Test your method with the following strings:” “, “A”, “B”,”BCA” and “ABACAD
34 Laboratory write a recursive method that returns the maximum integer in the array it is passed. your method by passing it a 20-slot int array initialized with random integers. Test nt() in the Random class. Use the seed 1 when you con- Generate integers with nextI struct the Random object. A recursive method does not have to first recurse down and then up. It can first recurse up and then down. Write a recursive method that returns the sums of the integers from 1 to n when passed n. Your method should first recurse up, hit the top when the parameter is equal to the largest integer to be summed, and then recurse down. (Hint: Your method should have two parameters.) 10. Write a method that implements Ackermann’s function: Ack(x, y) y 1 when x 0 when x > 0 and y=0 when x Ack(x, y)Ack (x-1,1) ACK (x, y)-A(x-1, A(X,y-1)) > 0 and y > 0 Use type long, write a program that displays the value of Ack (n, n) for n ,1、 0, 1, For what value of n is the value of Ack (n, n) too large for type long? Acker- mann’s function is famous because Ack (n, n) grows so rapidly with increasing n. I. Write a recursive method that determines if the first string it is passed is a substring of second string it is passed. Test your method with the following pairs: and “A”, C. and ABC, an the “АВС”, “ABC” and “ABC”, “mine” and . determines”, “minee. and determines”.

Expert Answer


Answer to g implement numbersoe sequence: 1,1,2,3s 2. The following method returns the ith number in the Fibonacci fib(o) returns … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *