Question: Consider the following two variants of the pseudo code for the Insertion Sort algorithm. Using each variant, sort the array: 5 1 , 5 2

Consider the following two variants of the pseudo code for the Insertion Sort algorithm. Using each variant, sort the array: 51,52,5354,55. Note that 51,52,dots,55 are five different instants of integer 5 and need to be treated as separate elements (that are of the same numerical value). Determine the number of comparisons encountered with each of the two variants of the algorithm to sort the above array and what is the final sorted array (include the suffixes of the elements throughout your work).
Input: Array A[0..n-1]
Begin
for (index i=1 to n-1) do
v=A[i]
index j=i-1
while (index j0) do
if )(A[j] then
break 'j' loop
else
end if
A[j+1]=A[j]
j=j-1
end while
A[j+1]=v
End
Input: Array A[0dotsn-1] Begin for (index i=1 to n-1) do ,v=A[i] index j=i-1 while (index j0) do
if )>(A[j] then
break 'j' loop
else
A[j+1]=A[j]
end if
j=j-1
end while
A[j+1]=v
End
Pseudo Code - I
Pseudo Code - II
 Consider the following two variants of the pseudo code for the

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!