title: Time Complexity - Calculating Worst Case For Algorithms
body: <p>I am reading some information on time complexity and I'm quite confused as to how the following time complexities are achieved and if there is a particular set of rules or methods for working this out?</p>
  
  <p><em><strong>1)</em></strong></p>
  
  <pre><code>Input: int n
  for(int i = 0; i &lt; n; i++){
     print("Hello World, ");
  }
  for(int j = n; j &gt; 0; j--){
     print("Hello World");
  }
  </code></pre>
  
  <ul>
  <li>Tight: 6n + 5 </li>
  <li>Big O: O(n)</li>
  </ul>
  
  <p><em><strong>2)</em></strong></p>
  
  <pre><code>Input: l = array of comparable items
  Output: l = array of sorted items
  Sort:
  for(int i = 0; i &lt; l.length; i++){
       for(int j = 0; j &lt; l.length; j++){
           if(l{i} &gt; l{j}){
  } }
       Swap(l{i},l{j});
  }
  return ls;
  </code></pre>
  
  <ul>
  <li>Worst Case Time Complexity: 4n2 +3n+2 = O(n2)</li>
  </ul>