Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Quiz 3Feb 25CSC 326Spring 2021NAME:_______________1)(6pts) Multiple choice questions: circle oneansweronlyi. Predict output of following programint f1(int n) {if(n == 4)return n;else return 2*f1(n+1);}int main() {cout

Quiz 3Feb 25CSC 326Spring 2021NAME:_______________1)(6pts) Multiple choice questions: circle oneansweronlyi. Predict output of following programint f1(int n) {if(n == 4)return n;else return 2*f1(n+1);}int main() {cout << f1(2);return 0;}[a] 4[b] 8[c] 16[d] 32ii. What does the following function print for n = 25?voidf2(intn) {if(n == 0)return;f2(n/2);cout<< n%2;}[a] 10011[b] 11001[c] 11111[d] 00000iii. If f3(6) is being called in main(), how many times willf3()be invoked?voidf3(intn) {if(n < 1) return;f3(n-1);f3(n-3);cout<< " "<< n;}[a] 15[b] 25[c] 35[d] 45iv. What is the output of the following program?intf4(intn) {if(n <= 1)return1;if(n%2 == 0)returnf4(n/2);returnf4(n/2) + f4(n/2+1);}intmain(){cout << f4(11);return0;}[a] Stack overflow[b] 3[c] 4[d] 5 Page 2of 2v. Which of the following statement is true?[a] Recursion is always better than iteration[b] Recursion uses more memory and time compared to iteration[c] Recursi on uses less memory and time compared to iteration[d] Recursion is always better and simpler than iteration.vi. Which of the following line will make sum() function recursive?unsigned int sum(unsigned int n){if(n == 0)return 0;return __________;}[a] (n 1) + sum(n)[b] n + sum(n)[c] n + sum(n 1)[d] (n 1) + sum(n 1)2)(4pts) Given the following codeint toc(int m, int n){int x, y;if(m==0 ||n==0) return (m+n);x = toc(m-1, n);y = toc(m, n-1);return (x+y);}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

Students also viewed these Databases questions