title: Finding big-O complexity. of three algorithms
body: <p>I am trying to find the the time complexity of the following algorithm.</p>
  
  <p>From what i can see the first two loops in alg1 are <strong>n^2</strong> however I'm not sure what running time the loop in alg2 is then.</p>
  
  <pre><code>public class algo {
  
  
  
  
  public static int alg1(int[] A, int n) {
      int l = 0;
  
      for (int i = 0; i &lt;= n-1; i++) {
          for (int j = i+1; j &lt;= n-1 ; j++) {
             if(alg2(A,i,j) &amp;&amp; j-i &gt; l) {
                 l = j-i+1;
             }
          }
      }
  
      return l;
  
  }
  
  private static boolean alg2(int[] A,int i, int j) {
      if(i==j) {
          return true;
      }
  
      for (int k = i; k &lt;= j-1; k++) {
          if(A[k] != A[k+1]) {
              return false;
          }
      }
  
      return true;
  }
  }
  </code></pre>