title: Complexity of recursive algorithm
body: <p>I have an algorithm, and I would like to find out the complexity of it, but there is recursion, and I don't know how to count with recursion. My code is:</p>
  
  <pre><code>public boolean algorithm(int x, int y) {
      if (x == matrixHeight - 1 &amp;&amp; matrix1[x][y] == '0') {
          return true;
      } else if (x == 1 &amp;&amp; matrix1[x-1][y] == '0') {
          return true;
      } else if (y == matrixWidth - 1 &amp;&amp; matrix2[x][y] == '0') {
          return true;
      } else if (y == 1 &amp;&amp; matrix2[x][y-1] == '0') {
          return true;
      }
      if (matrix1[x-1][y] == '0' &amp;&amp; tempMatrix[x-1][y] == '-'){
          path.push(new int[]{x-1, y});
          tempMatrix[x-1][y] = '+'
          if (!algorithm(x-1, y)) {
              path.pop();
          } else {
              return true;
          }
      }
      if (matrix2[x][y] == '0' &amp;&amp; tempMatrix[x][y+1] == '-'){
          path.push(new int[]{x, y+1});
          tempMatrix[x][y+1] = '+';
          if (!algorithm(x, y+1)) {
              path.pop();
          } else {
              return true;
          }
      }
      if (matrix1[x][y] == '0' &amp;&amp; tempMatrix[x+1][y] == '-'){
          path.push(new int[]{x+1, y});
          tempMatrix[x+1][y] = '+';
          if (!algorithm(x+1, y)) {
              path.pop();
          } else {
              return true;
          }
      }
      if (matrix2[x][y-1] == '0' &amp;&amp; tempMatrix[x][y-1] == '-'){
          path.push(new int[]{x, y-1});
          tempMatrix[x][y-1] = '+';
          if (!algorithm(x, y-1)) {
              path.pop();
          } else {
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <ul>
  <li>There, <code>x</code>, <code>y</code> are coordinates in matrix.</li>
  <li><code>matrix1</code> and <code>matrix2</code> are two-dimensional arrays that contain <code>'0'</code> or <code>'1'</code></li>
  <li><code>tempMatrix</code> is a two-dimensional array that contains '+' or '-'</li>
  <li><code>path</code> is a Stack</li>
  <li><code>matrixHeight</code> is <code>matrix1.length</code></li>
  <li><code>matrixWidth</code> is <code>matrix[0].length</code></li>
  <li><code>N</code>, <code>M</code> is the size of the matrix (constant)</li>
  </ul>
  
  <p>Note: this is maze solver that uses backtrack.</p>