Question: Please show the steps on how to solve the problems in detail. 7. Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary

 Please show the steps on how to solve the problems in
Please show the steps on how to solve the problems in detail.

7. Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary array Al0..n of n elements. void ISORT (dtype A, int n) int i,j for i = 1 to n-1 //Insert Ali] into the sorted part Al0..i 1 while (j>0 and Aj] Aj) SWAP (A),Ai 1) (a) lustrate the algorithm on the following array by showing each comparison/swap operation What is the total number of comparisons made for this worst-case data? A (5,4,3,2, 1) (b) Write a recursive version of this algorithm (c) Let f(n) be the worst-case number of key comparisons made by this algorithm to sort n elements. Write a recurrence equation for f(n). (Note that the sequence of comparisons are exactly the same for both non-recursive and recursive versions. But, you may find it more convenienet to write the recurrence for the recursive version.) (d) Find the solution for f(n) by repeated substitution 8. Consider the bubble-sort algorithm described below void bubble (dtype A], int n) nt i,j //Bubble max of A0.i] down to A) for (i-1; i>0; i--) for (j =0; j Aj SWAP (Alj).Alj); (a) Analyze the time complexity, T(n), of the bubble-sort algorithm. (b) Rewrite the algorithm using recursion (c) Let f(n) be the worst-case number of key-comparisons used by this algorithm to sort n ele- ments. Write a recurrence for f(n). Solve the recurrence by repeated substitution (i.e, iteration method)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!