Deprecated: Implicit conversion from float-string "1648297569.698" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648297569.698" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648297569.698" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648297569.698" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1648297569.698" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1693551331.253" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1693551331.253" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1693551331.253" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1693551331.253" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1693551331.253" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1648365690.060" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648365690.060" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648365690.060" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648365690.060" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1648365690.060" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1651422353.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1651422353.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1651422353.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1651422353.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1651422353.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
Programming in C: GO Classes 2023 | Weekly Quiz 4 | Question: 17
retagged by
550 views
2 votes
2 votes

How many times is foo activated (called), including the first "$\text{foo}(3,12)$"

$\text{max()}$ and $\text{min()}$ are functions that return maximum and minimum respectively.
 

int foo(int a, int b) {
    if (a==b) {
        return b;
    }
    int mn =min(a,b), mx =max(a,b);
        return foo(mn,mn) + foo( mx - mn , mn);
}
retagged by

3 Answers

2 votes
2 votes
The recurrence relation to count number of function call looks like,
$F(a,b)=1+F(min(a,b),min(a,b))+F(max(a,b)-min(a,b),min(a,b))$   if $a\neq b$
            =1              if $a= b$

$F(3,12)=F(3,3)+F(9,3)+1$

$F(9,3)=F(3,3)+F(6,3)+1$

$F(6,3)=F(3,3)+F(3,3)+1$

now ,$F(3,3)=1$ as a=b

putting the value in $F(6,3)$ we get ,

$F(6,3)=3$

$F(9,3)=5$

$F(3,12)=7$

so correct answer is 7.
edited by
Answer:

Related questions


Deprecated: Implicit conversion from float-string "1648297566.725" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648297566.725" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648297566.725" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648297566.725" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1648297566.126" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648297566.126" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648297566.126" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648297566.126" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1648297567.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648297567.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648297567.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648297567.972" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1648297567.387" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1648297567.387" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1648297567.387" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1648297567.387" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
856
views
3 answers
5 votes
GO Classes asked Mar 26, 2022
856 views
Consider the following pair of mutually recursive functions. What does $g(g(2))$ evaluate to?int f(int n){ if (n==0) return 0; return f(n-1)+g(n-1); } int g(int n){ if (n...
643
views
2 answers
9 votes
GO Classes asked Mar 26, 2022
643 views
Consider the following recursive function. What is $f(0)?$int f(int x) { if (x 1000) return x - 4; else return f(f(x+5)); }
543
views
3 answers
5 votes
GO Classes asked Mar 26, 2022
543 views
What will be output printed by $\text{mystery}2(6)$?void mystery2(int n) { if (n 0) { printf("%d", n); mystery2(n-2); mystery2(n-3); printf("%d", n); } }
585
views
3 answers
4 votes
GO Classes asked Mar 26, 2022
585 views
What will be the output printed by $\text{mystery}3(6)$?void mystery3(int n) { if (n == 0 || n == 1) return; mystery3(n-2); printf("%d", n); mystery3(n-1); }