title: Time complexity for a sorting algorithm
body: <p>I came across the following question while I was doing some exercise: </p>
  
  <blockquote>
    <p>A sorting algorithm starts from start of the list, scan until two succeeding items that are in the wrong order are found. Swap those items and go back to the beginning. The algorithm ends when the end of the list is reached.</p>
    
    <p>What is the worst-case running time for a list of size n? </p>
  </blockquote>
  
  <p>I feel that it is similar with bubble sort, but probably worse that that because it doesn't finish the whole pass of scanning the list. But I can't figure out how to calculate its time complexity. I am not sure if the code I came up below for this algorithm is correct. Many thanks for your help!</p>
  
  <pre><code>for (int i=0, i&lt;n , i++){//n is the size of the array
       if (array[i]&gt;array[i+1]){
            swap (array[i], array[i+1]);
            i=0;
       }
  }
  </code></pre>