title: Determining the time complexity for code segments
body: <p>What is the time complexity for each of the following code segments?</p>
  
  <pre><code>1. int i, j, y=0, s=0;
  for ( j = 1; j &lt;= n; j ++) 
  {
    y=y+j;
  }
  for ( i = 1; i &lt;= y; i ++) 
  {
    s++;
  }
  </code></pre>
  
  <p>My answer is O(2n) since it iterates through each loop n times and there are two loops</p>
  
  <pre><code>2. function (n) {
    while (n &gt; 1) {
    n = n/3 ;
  }
  </code></pre>
  
  <p>My answer for this one is n^(1/3) since n becomes a third of its size every time</p>
  
  <pre><code>3. function (n) {
  int i, j, k ;
  for ( i = n/2; i &lt;= n; i ++ ) {   //n/2?
    for ( j = 1; j &lt;= n; j = 2*j ) {  //logn
      for ( k = 1; k &lt;= n; k = 2*k ) {  //logn
        cout &lt;&lt; ”COSC 2437.201, 301” &lt;&lt; endl;
      }
    }
  }
  }  
  </code></pre>
  
  <p>I said the answer to this one was O(log2*log2n*n/2) but I'm pretty confused about the first for loop. The loop only has to iterate half of n times, so it would be n/2 correct? Thanks for your help, everyone.</p>