title: How many times is this function called?
body: <p>I have this subalgorithm on recursion and I know that it's called 5 times, but I don't understand why. The initial values are m=1, n=2.</p>
  
  <p>I've thought the function is called for 7 times. </p>
  
  <pre><code>int Ack(int m, int n)
  {
      if (m==0) 
          return n+1;
      else 
           {
              if (m&gt;0 &amp;&amp; n==0) 
                  return Ack(m-1,1);
              else 
                  return Ack(m-1,Ack(m,n-1));
          }
  }
  </code></pre>
  
  <p>I expect that it's called 7 times or even more, but the actual number is 5.</p>
  
  <p>This how 7 is arrived at:</p>
  
  <ol>
  <li>Ack(1,2) </li>
  <li>Ack(0,Ack(1,1)) </li>
  <li>Ack(1,1) </li>
  <li>Ack(0,Ack(1,0)) </li>
  <li>Ack(1,0) </li>
  <li>Ack(0,1), a function which returns 2. Ack(0,1)=Ack(1,0)=2 ==> </li>
  <li>Ack(0,2) (we came back to number 4) = 3 </li>
  <li>Ack(0,3) (we came back to number 2)</li>
  </ol>