Computer Science EngineeringVery hard
For void f(int n){ if(n>0){ f(n-1); printf("%d ",n); f(n-1); } }, how many numbers are printed by the call f(4)?
- A. 8
- B. 15
- C. 16
- D. 31
Correct answer: B. 15
Let P(n)=2P(n-1)+1 with P(0)=0, which gives 1, 3, 7, 15.
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
- The array [4, 10, 3, 5, 1] is converted into a max-heap by the standard bottom-up build-heap procedure. The resulting array is
- A binary tree has exactly 15 nodes with two children. How many leaves does it have?
- The auxiliary space used by a recursive DFS on a graph with V vertices, in the worst case, is
- What does f(37) return for int f(int n){ if(n==0) return 0; return f(n/2) + (n%2); }
- How many structurally distinct binary trees exist with 5 nodes?
- Which of the following algorithms can detect a negative-weight cycle reachable from the source?