Computer Science EngineeringVery hard
Consider int f(int n){ if(n<=1) return 1; return f(n-1)+f(n-2); }. What does f(6) return?
- A. 8
- B. 13
- C. 21
- D. 10
Correct answer: B. 13
With f(0)=f(1)=1 the values run 1,1,2,3,5,8,13, so f(6)=13.
Practise more Algorithms, Data Structures & Programming (ISRO CS) questionsAlgorithms, Data Structures & Programming (ISRO CS): notes and key points
More Algorithms, Data Structures & Programming (ISRO CS) questions
- Quicksort that always picks the first element as pivot runs in what time on an already sorted array?
- Dijkstra's algorithm using a binary heap and adjacency lists runs in
- For n a power of 2, what is the Theta bound of the loop: x=0; for(i=1;i<=n;i=2) for(j=0;j<i;j++) x++;
- How many leaf nodes does a binary heap stored in an array of 15 elements have?
- A table of size 7 uses h(k) = k mod 7 with linear probing. After inserting 15, 22, 8 and 1 in that order, at which index does key 1 reside?
- The Bellman-Ford single-source shortest path algorithm has running time