Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(1) The Insertion Sort below can output an ascending array. Please modify the pseudocode to make it output a descending array. (10 points) INSERTION-SORT(A)

 

(1) The Insertion Sort below can output an ascending array. Please modify the pseudocode to make it output a descending array. (10 points) INSERTION-SORT(A) for j 1 2 3 5678 = 2 to A.length A[j] key = // Insert A[] into the sorted sequence A[1..j-1]. =j-1 while >0 and A[i]> key A[i+1] =A[i] 1=1-1 A[i+1] = key (2) Please give an array with 5 elements, which is the worst case of the modified insertion sort code. (5 points) (3) Please give an array with 5 elements, which is the best case of the modified insertion sort code. (5 points)

Step by Step Solution

3.43 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

lets first modify the pseudocode for the Insertion Sort algorithm to make it output a descending arr... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Algorithms questions

Question

For the slack form in (29.38)(29.41), what are N, B, A, b, c, and ?

Answered: 1 week ago

Question

Evaluate the product Tk=2(1 1/k).

Answered: 1 week ago

Question

2. smiling and laughter (being sociable);

Answered: 1 week ago