Ask Question
10 June, 14:03

Give a recursive version of the algorithm Insertion-Sort (refer to page 18 in the textbook) that works as follows: To sort A[1 ... n], we sort A[1 ... n - 1] recursively and then insert A[n] in its appropriate position. Write a pseudocode for this recursive version of InsertionSort and analyze its running time by giving a recurrence relation and solving it

+2
Answers (1)
  1. 10 June, 15:47
    0
    see explaination

    Explanation:

    void insertion (int e, int * x, int start, int end)

    {

    if (e > = x[end])

    x[end+1] = e;

    else if (start < end)

    {

    x[end+1] = x[end];

    insertion (e, x, start, end-1);

    }

    else

    {

    x[end+1] = x[end];

    x[end] = e;

    }

    }

    void insertion_recurssion (int * b, int start, int end)

    {

    if (start < end)

    {

    insertion_sort_recur (b, start, end-1);

    insertion (b[end], b, start, end-1);

    }

    }

    void main ()

    {

    insertion_recurssion (x, 0,5);

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Give a recursive version of the algorithm Insertion-Sort (refer to page 18 in the textbook) that works as follows: To sort A[1 ... n], we ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers