Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help with this question Use the pseudocode provided by the book for Instertion S

ID: 3541878 • Letter: H

Question

help with this question

Use the pseudocode provided by the book for Instertion Sort (p.18) to describe each and every step made by the code to sort this array: {31; 41; 59; 26; 41; 58}. In other words, it has to be in greater detail than what is shown on page 18 in the book - the book shows simultaneous movements which is not the case for most programming languages as we now know. So you will have to describe every step and each time any value in the array changes, I want you to write out what the array is at that time. (E.g. for the array on page 18: first key = 2, then i= 1, then A[1]>key so A[2] = A[1], so the array is now {5,5,4,6,1,3} then i=0 so the while loop stops. Then A[i+1] = key which is A[1] = 2. So now the array is {2,5,4,6,1,3}. Etc.

Explanation / Answer

Hi,

These are the steps for insertion sort. Hope it Helps :)

For your convenience, i have highlighted which number is being focused in every step.


31,41,59,26,41,58

31,41,59,26,41,58

31,41,59,26,41,58

31,41,26,59,41,58

31,26,41,59,41,58

26,31,41,59,41,58

26,31,41,41,59,58

26,31,41,41,58,59