The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
65 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 (n == 0) return m;
    else return A(m, A(m,n-1,p), p-1);
}

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

asked in Algorithms by Veteran (96.1k points) | 65 views

1 Answer

0 votes

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

To compute this we solve the base cases first:

The base case is : A(m, 0, 1) = 0 = m∗0
So the value of  : A(m,n -1,1) = m(n-1)

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

                  =m+m(n-1)

      A(m,n,1) =mn

answered by Boss (38.2k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,541 questions
54,083 answers
187,206 comments
70,992 users