Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please MAKE SURE YOU ARE ANSWERING THE QUESTION AS ASKED !! Please answer as asked (a) (b) (c) (c) (c) (f) Figure 2.2 The operation
Please MAKE SURE YOU ARE ANSWERING THE QUESTION AS ASKED !!Please answer as asked
(a) (b) (c) (c) (c) (f) Figure 2.2 The operation of INSERTION-SORT on the array A=5,2,4,6,1,3. Amay indices appear above the rectangles, and values stored in the array positions appear within the rectangles. (a)-(e) The iterations of the for loop of lines 1-8. In each iteration, the black rectangle holds the key taken from A[j], which is compared with the values in shaded rectangles to its left in the test of line 5. Shaded arrows show array values moved one position to the right in line 6 , and black arrows indicate where the key moves to in line 8 . (f) The final sorted array. Using the figure above as a model, illustrate the operation of insertion sort algorithm on the array A=(28,30,63,17,30,41) Q2. Think back to when I showed you the operation of insertion sort on cards in class. The way I did it, if this were the cards in my hand, and the next card was 4 (of whatever suit), we would compare it first with the ace, then with the 2 , then with the 3 , then with the four before finding its spot in the sorted order. The way I did differs from the algorithm as written above (yes: mistakes were made). For the purpose of this assignment, let's call my version Weronika's Insertion Sort (WIS), and the version in the Cormen book Real Insertion Sort (RIS). Please answer the following: Q2.1 Describe how WIS is different from RIS in plain English. Q2.1 Describe how WIS is different from RIS in plain English. Q2.2 Here is the loop invariant for RIS: At the start of each iteration of the for loop of lines 1-8, the subarray A[1j1] consists of the elements originally in A[1j1], but in sorted order. Although WIS differs from RIS, it is correct. If you were to prove its correctness, would you use a different loop invariant? Why or why not? Q2.3 RIS is very efficient when the input is already sorted -- in that case the running time is a linear function of the length of the array. Is this also true of WIS? Explain. Q2.4 Write pseudocode for WIS. Q2.5 Is WIS an improvement on RIS, or is best forgottenStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started