title: Uncertain of my Big O analysis
body: <pre><code>int RiskSort(int* PlayerA, int* PlayerB,int Length){
      int i,j;
      int Losses = 0;
      for(i=0;i&lt;Length-Losses;i++){
           printf("%d,%d\n",PlayerA[i],PlayerB[i]);
          if(PlayerB[i]&lt;PlayerA[i]){
                  for(j=i;j&lt;((Length-1)-Losses);j++){
                      Swap(&amp;PlayerB[j],&amp;PlayerB[j+1]);
                  }
                  i--;
                  Losses++;
          }
  
      }
  return Losses;
  
  }
  </code></pre>
  
  <p>I just wrote this and I am getting O(n log n) as my answer, This is homework but the Big O part is just my way of studying.</p>
  
  <p>Thanks again</p>
  
  <p>Edit: I am getting N from the first for loop and N-1-X amount of passes on the if, and i am unsure how to notate that so since it limits the amount of passes i called it log n ( probably inaccurate but I couldn't find a guide that wasn't look at code and pick online)</p>
  
  <p>Edit 2: Just trying to make this function more efficient</p>
  
  <pre><code>int RiskSortB(int* PlayerA, int* PlayerB,int Length){
  int i,j;
  int Losses = 0;
  for(i=0;i&lt;Length-Losses;i++){
  j=i+1;
  if(PlayerB[i]&lt;PlayerA[i])
      Losses++;
  
  while(PlayerB[i]&lt;PlayerA[i]&amp;&amp;j&lt;Length){
      if(PlayerB[j]&gt;=PlayerA[i]){
          Swap(&amp;PlayerB[i],&amp;PlayerB[j]);
          if(j!=(Length-Losses))
              Swap(&amp;PlayerB[j],&amp;PlayerB[Length-Losses]);
      }
      j++;
  }
  
  
  }
  
  return Losses;
  }
  </code></pre>
  
  <p>So since the amount of time maximum Swap is called per for loop is 2 it means its O(2N) but constants don't matter so its O(N) right?</p>