0
$\begingroup$

$$ \Theta - Tight \ asymptotic \ bound $$

If we change lines $5-7$ in Insertion sort

enter image description here

With BINARY-SEARCH(A,p,r,v)

enter image description here

Why don't we get a running time of $\Theta(n\lg n)$ as we go through the array $\Theta(n)$ and then do a binary search $\Theta(\lg n)$?

$\endgroup$
2
$\begingroup$

You still need to shift $O(n)$ elements to make room for the newly inserted element even if you find the correct position in $O(\log n)$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.