Question

$$ \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)$?

Was it helpful?

Solution

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)$.

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top