I got a sorting algorithm. I know it could have been written in many other and more simple ways but that's not the point of my question.
Here is the algorithm:
sort(A : Array of N, i : N, j : N)
assert j-i+1 isTwoPotency
if A[i] > A[j] then swap A[i] and A[j]
if i+1 < j then
k:= (j − i + 1)/4
sort(A, i, j − 2k)
sort(A, j − 2k + 1, j)
sort(A, i + k, j − k)
sort(A, i, j − 2k)
sort(A, j − 2k + 1, j)
sort(A, i + k, j − k)
My question is, why does the algorithm work correctly in the following case?
sort(A, 1, length(A))
and the array would be:
A[1 . . . length(A)]
length(A) is a two potency and we can assume that there are no identical numbers inside the array. I already tested it, got no errors so I assume it works correctly. But how can I prove that the algorithm always works correctly in these conditions?
And I am wondering how long does the algorithm needs as running time. It would be great if you could give me the running time as big theta notation (that's the one I understand the best)
f(n) = Θ(g(n))
