title: cost of lines in algorithm help me understand this
body: <p><a href="http://i.imgur.com/ukKb0Sz.png" rel="nofollow">http://i.imgur.com/ukKb0Sz.png</a></p>
  
  <p><a href="http://i.imgur.com/c1ARjzB.png" rel="nofollow">http://i.imgur.com/c1ARjzB.png</a></p>
  
  <p>Okay so basically i have an algorithm of an insertion sort, however next to it is a constant which is the cost of running each line of code</p>
  
  <p>now my mathematical background is not very strong but i do understand most of it, however what i cannot make sense of is why is the coefficient of n^2 and n have the constants divided by two?</p>
  
  <p>what is the significance of it? is it because it is a loop within a loop? or maybe because two values are compared? or some other mathematical reason like formula of summation n(n-1)/2 </p>
  
  <p>first image is the algorithm in pseudo code and the summation under it the best case scenario(where the algorithm is already sorted) and the second picture is the algorithm worst case scenario(summation) which is where my question is pointed at</p>
  
  <p>note: also tj denote the number of times the while loop test in line 5 is executed for that value of j</p>