title: Calculating Time complexity for a transpose matrix
body: <p>The code is a summarized version of a piece of code trying to transpose a matrix. My task for this is to find the time complexity of this program.</p>
  
  <p><a href="https://i.stack.imgur.com/pFLKT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pFLKT.png" alt="enter image description here"></a></p>
  
  <p>I am only interested in the time complexity for the number of swaps that occur. I found out that on the outer loop for the swapping it occurs n-1 times and as for the inner loop it occurs (n^2 -n)/2 times. </p>
  
  <hr>
  
  <p>I derived these solutions by subst n with a number.</p>
  
  <ul>
  <li>When n=4, my inner loop would loop 1+2+3 times </li>
  <li>When n=5, my inner loop would loop 1+2+3+4 times</li>
  <li>Therefore innerloop=(n^2 - n) / 2</li>
  </ul>
  
  <p>How would i calculate the time complexity of this code? </p>
  
  <hr>
  
  <p>I saw somewhere online where the person just took the values from his innerloop count and determine it was a O(n) complexity.</p>
  
  <hr>
  
  <p>[Edit]
  Do i need to cater in the other loops to calculate the time complexity as well?</p>