634 views
3 votes
3 votes

Consider the code below, defining the function $A$:

A(m, n, p) {
    if (p == 0) return m+n;
    else if (n == 0 && p == 1) return 0;
    else if (n == 0 && p == 2) return 1;
    else if (n == 0) return m;
    else return A(m, A(m,n-1,p), p-1);
}

Express $A(m, n, 2)$ as a function of $m$ and $n$.

2 Answers

2 votes
2 votes

A(m,n, 2) = A(m,A(m, n-1, 2), 1)

Similarly Here

A(m, 0, 2) = 1 = m0.

A(m, n-1, 2) = mn-1

So A(m,n,2)=A(m,A(m, n-1, 2), 1)

                   =A(m , mn-1 ,1 )

      A(m,n,2)=m*mn-1 =mn

Related questions

3 votes
3 votes
2 answers
1
go_editor asked May 27, 2016
617 views
Consider the code below, defining the function $A$:A(m, n, p) { if (p == 0) return m+n; else if (n == 0 && p == 1) return 0; else if (n == 0 && p == 2) return 1; else if ...
3 votes
3 votes
2 answers
2
2 votes
2 votes
2 answers
4
go_editor asked May 27, 2016
427 views
Let $A$ be array of $n$ integers that is not assumed to be sorted. You are given a number $x$. The aim is to find out if there are indices $k,\: l$ and $m$ such that $A[...