I'm given a pseodocode statement as such:
function testFunc(B)
for j=1 to B.length-1
for i=1 to B.length-j
if(B[i-1] > B[i]
swap B[i-1] and B[i]
And I'm told to show that this algorithm runs in Big o O(n^2) time
.
So I know that the first for loop runs n
times, because I believe it's inclusive. I'm not sure about the rest of the lines though, would the second for loop run n-2
times? Any help would be much appreciated.