edited by
4,953 views

2 Answers

Best answer
1 votes
1 votes

Recurrence relation for $fun (x, y)$ is

$fun(x, y) = x + fun(x, y-1) \\= 2x + fun(x, y-2) \\= \dots \\= yx + fun(x, 0) \\= yx$

That is $fun(x, y)$ returns the product of $x$ and $y$.

Now, recurrence relation for $fun2$ is 

$fun2(a, b) = a \times fun2(a, b-1) \\= a \times a \times fun2 (a, b-2) \\= \dots \\= a^b \times fun2(a, 0) \\= a^b \times 1 = a^b$. 

Just a small change of 

 if (b == 0) return 1;

to

 if (b == 0) return 0;

will have made $fun2$ return $0$ always. 

The given code returns $a^b$. 

selected by

Related questions

1 votes
1 votes
1 answer
1
Aghori asked Jul 4, 2017
483 views
int A(struct node* node) { if (node==NULL) return 0; else { int lDepth = A(node->left); int rDepth = A(node->right); /* use the larger one */ if (lDepth rDepth) return(l...
3 votes
3 votes
3 answers
2
1 votes
1 votes
2 answers
3
Anjana Babu asked Dec 21, 2016
553 views
Write C Program using Recursive Funtions for the Problem Described below and Analyse the Complexity Of the CodeProblemGiven an unordered array arr[] which contains n di...
1 votes
1 votes
1 answer
4