How do you find the best and worst case from a pseudo code?
I was wondering how would I find the best, worst case of this algorithm:
Inputs A: Array of Integers; N: Integer Variables i, k: Integer Begin for i := N - 2 down to 0 do for k := 0 to i do if (A[k] > A[k + 1]) then swap(A, k, k + 1) fi od od End
The worst case is when A is sorted in decreasing order. In that case the "if" statement is executed in every iteration of the nested "for".