Question: An insertion sort sorts an array by successively inserting the elements of the array into the sorted portion. The pseudocode describes the algorithm. Note that

An insertion sort sorts an array by successively inserting the elements of the array into the sorted portion. The pseudocode describes the algorithm. Note that arrays start from 1, so the first element of an N element array is A[1] and the last element is A[N].
Given: An array A of size N to be sorted
1 Function Insertion_Sort(A, N)
2 Let j =2
3 While j = N
4 Let i = j
5 While i >1 & A[i-1]> A[i]
6 Swap A[i] and A[i-1]
7 Decrement i
8 Increment j
Which line above shows that the sorted segment is being scanned from right to left?
Line 5
Line 4
Line 2
Line 7
 An insertion sort sorts an array by successively inserting the elements

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!