Question

1) How many times is the fib method invoked for fb(5)7 a. 14 b. 15 c. 25 d. 31 e. 32 2) Fill in the code to complete the following method for computing Fibonacei aumber publie statie long fib(long index) t if (index--0) Base case return 0; return 1 return else if (index1)/ Base case else I/ Reduction and recursive calls a. fib(index 1) b. fib(index-2) c. fib(index-1)+ fib(index -2) d. fib(index - 2) + fib(index -1) 3) What is the return value for xMethod(4) after calling the following method? static int xMethod(int n) f if (n1) return I; else return n+xMethod(n 1); a. 12 b. C. d. 9 10 4) How many times is the factorial method in invoked for factorial(5)? a. 3 b. 4 c. 5 d. 6 5) Which method can you use to find out the number of the bytes in a file using InputStream? a. length0 b. availableO c. size0 d. getSize0
0 0
Add a comment Improve this question Transcribed image text
Answer #1
1.
b. 15

2.
Option c

3.
Option c

4.
Option c

5.
Option c


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
1) How many times is the fib method invoked for fb(5)7 a. 14 b. 15 c....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5 & 6 Name: lue for a, b, and d? what's the 5. A). Summarize the...

    5 & 6 Name: lue for a, b, and d? what's the 5. A). Summarize the master method. (opis) R) Anoly master method to the following case. What s the value for a, b, and dy running time for the function? (10pts) int factorial(int n) else if(n > 1) return n * factorial(n - 1); return 1; 6. What is the output of following function for start pointing to first node of following linked list? 6->5->4->3->2->1 void fun (struct node*...

  • long fib(int n) { long result;    if (n==0) result = 0; else if (n==1 ||...

    long fib(int n) { long result;    if (n==0) result = 0; else if (n==1 || n==2) result = 1; else result = fib(n-1) + fib(n-2);    return result; } [C language] Question : Why is this code is so slow? Explain ex2) Make the program from exercise 1 faster by trading space for time. Create an array of int that can be used as a cache. Each index in the array should correspond to a value that you can...

  • Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n):...

    Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...

  • Given the following code for a binary search, how many times this method have to be...

    Given the following code for a binary search, how many times this method have to be executed in order to find the number 5? A) 1 time B) 2 times C) 3 times D) 4 times E) more than 5 times public class BinarySearch{ public static void main(String []args){ if (right >= left) { int middle = left + (right - left) / 2; if (arr[middle] == num) return middle; if (arr[mid] > num) return binarySearch(arr, left, middle - 1,...

  • Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to...

    Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to calculate the Fibonacci Function 1.) Use a recursive function called fib() to calculate the Fibonacci Function for the following values for the variable n. int n = 10; int n = 20; int n = 30; int n = 40; int n = 45; int n = 46; 2.) In addition to calculating and displaying the results, use a "timer" to see how long...

  • use the code and change it Task This assignment is very straight-forward and quick to do...

    use the code and change it Task This assignment is very straight-forward and quick to do since BigInteger supports integer operations just as long does! Start by downloading the code below (scroll down). (Certainly compile and run the code to see what it does.) Add "import java.math.BigInteger;" to the top of the file. Replace all "Long" types with "BigInteger" in the entire file. (This works because long was intentionally only used for computed values.) Replace all "long" types with "BigInteger"...

  • please also explain how the answer came about if possible b) Base 7. Master Theorem (3...

    please also explain how the answer came about if possible b) Base 7. Master Theorem (3 points) Consider the following recursive function for n >0 case: a| c) Recursive case: an Algorithm 1 int recFunc(int n) //Base Case if n <= 2 then return n; end if / /Recursive Case: while i< n do print("Hello!") end while int a 2*recFunc(n/2); return a; Find the runtime of the above recursive function using the master theorem

  • C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the +...

    C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the + operator. //Pre : M and N are defined and N > 0. //Post: Returns M x N { int Prod; if (N == 1)     Prod = M;                       //base case else     Prod = M + Multiply(M, N - 1); //recursive step return Prod; } 2) Reverse #include <iostream.h> void Reverse(int N) //Displays string of length N in the reverse order //Pre : N...

  • Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string),...

    Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) {    System.out.println(longestRun("aabbbccd"));    System.out.println("Expected 3");    System.out.println(longestRun("aaa"));    System.out.println("Expected 3");    System.out.println(longestRun("aabbbb"));    System.out.println("Expected 4");          int count = countP("Mississippi"); System.out.println(count);    int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...

  • In class we wrote a method closestPairFast that on an input array of numbers, finds the...

    In class we wrote a method closestPairFast that on an input array of numbers, finds the distance of the closest pair by first sorting the input array and then finding the closest adjacent pair. (See the file ClosestPair1D.java in the Code folder on D2L.) In this problem, you are asked to modify the method so that it returns an integer array consisting of the indices of the closest pair in the original array. If there is a tie, just return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT