Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions