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*...

  • 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,...

  • 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...

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • Q5. [5 marks] Consider the following recursive function: int Test (int number) //Line 1 //Line 2...

    Q5. [5 marks] Consider the following recursive function: int Test (int number) //Line 1 //Line 2 if (number == 0) //Line 3 return number; //Line 4 else //Line 5 return (number + Test (number - 1)); //Line 6 //Line 7 a. Identify the base case. b. Identify the general case. c. If Test (0) is a valid call, what is its value? If not, explain why. d. If Test (5) is a valid call, what is its value? If not,...

  • computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int...

    computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int 10 for(= 0; i < 101) printf("d", 1); A. 10 times B. 1 time C. It will run forever D. 0 times 2. What will be the output of this program? #include <stdlib.h> #include <stdio.h> int main() int a = 100, b = 200, C = 300; if(!a >= 500) b = 300; C = 400; printf("%d, 8d, &d", a, b, c); return 0;...

  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

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
ADVERTISEMENT