508 views
0 votes
0 votes
We can express the insertion sort as a recursive procedure as follows.In order to sort $A[1\dots n]$, we recursively sort $A[1 \dots n-1]$ and then insert $A[n]$ into the sorted array $A[1 \dots n-1]$. Write a recurrence for the running time of this recursive version of insertion sort.

1 Answer

0 votes
0 votes
$T(n) = T(n-1) + \Theta(n)\ \ \ if\ n>1$

                $\Theta(1)\ \ \ \ \ \ \ \  \ \  \ \ \ \  \ \ \ \ \ \ \ \ \  if\ n=1$

Here $\Theta(n)$ is the time required for swapping the elements to create space for the element to be inserted.

Related questions

1 votes
1 votes
1 answer
1
akash.dinkar12 asked Jun 28, 2019
679 views
Explain why the worst-case running time for bucket sort is $\Theta(n^2)$. What simple change to the algorithm preserves its linear average-case running time and makes its...
0 votes
0 votes
2 answers
2