title: Can algorithms have the same best- and worst-case time complexity?
body: <p>Is it possible for an algorithm/program to have the same worst-case and best-case time?</p>
  
  <p>For example:</p>
  
  <pre><code>public static int factorial(int number)
  {
      factorial = 1; 
      for (i = 1; i &lt;= number; i++) 
          factorial = factorial * i;
  }
  </code></pre>
  
  <p>It's a program segment for the factorial problem, and I was trying to solve for the time complexity. It seems to have no worst and best case time, since whatever input you may have it will still go through the rest of the code, unlike when you have if-else statements.</p>
  
  <p>If that's the case should I assume that what ever I get from this code it would be the best, worst and average case time?</p>
  
  <p>Did I get this right?</p>
  
  <pre><code>public static int factorial(int number)
      {
          factorial = 1;                   // 1
          for (i = 1; i &lt;= number; i++)    // 1+3n
              factorial = factorial * i;   // 2
          return factorial;                // 1
      }
  </code></pre>
  
  <p>Worst Case/Best Case:
   3n+5</p>
  
  <p>Big – O :
  O(n)</p>