I've searched high and low in my book aswell as several sites on the internet, but I'm just not entirely sure about my answers.
I need to give asymptotic runtimes of InsertionSort and FingerTreeSort (based on RB-Trees), in regards to the number of inversions present. InsertionSort runs in O(n+INV) time and FingerTreeSort runs in O(n+n*lg(INV/n+1). I need to give asymptotic runtimes for INV = 0, n, n^1.5 and n^2/4.
What I've come up with myself is that InsertionSort runs in: O(n), O(n), O(n^2) and O(n^2)
Is this correct? Why not? (I'm particularly not sure about INV = n and n^1.5)
And for FingerTreeSort: O(n*lg(n)), O(n*lg(n)), O(n*lg(sqrt(n))) and O(n*lg(n^2))
I'm in doubt about all of the ones in FingerTreeSort, but these are how I think they should be. How do I find the right asymptotic runtime? For instance for FingerTreeSort and n^1.5, I'm thinking that it would give O(n+n*lg(n^1.5/n+1) by plugging into the general runtime, and simplifying: O(n+n*lg(sqrt(n)+1) and seeing as it's asymptotic, I can disregard the lower figures such as +1 and +n giving me O(n*lg(sqrt(n))). Is this the correct way of doing it?
Thank you in advance to those that answer this question. I greatly appriciate it :)
ps. writing in java, not that it matters to the question.
Insertion Sort :
Formula : O(n + inv)
inv = 0 : O(n)
inv = O(n) : O(n +n) = O(n)
inv = O(n^1.5) : O(n+n^1.5) = O(n^1.5)
inv = (n^2)/4 : O(n + n^2) = O(n^2)
FingerTreeSort :
Formula (using the one supplied by OP) : O( n + n*(ln[(inv/n) +1 ] ) )
inv = 0 : O(n)
inv = O(n) : O(n + n*( ln[( O(n)/n ) + 1] ) ) = O(n + n*( ln[ O(1) +1] )) = O(n)
inv = O(n^1.5) : O(n + n*( ln[( O(n^1.5)/n ) + 1] ) ) = O(n + n*( ln[ c*(n^0.5) + 1] ) ) =
O(n + 0.5*n*ln(n)) = O(n*ln (n))
Similarly,for inv = O(n^2) : O(n*ln(n))