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

Assume values in an int array that is currently filled to capacity, with the fol

ID: 3565611 • Letter: A

Question

Assume values in an int array that is currently filled to capacity, with the following values: 9,4,12,2,6,8,18

(1) Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?

a) 9,4,12,2,6,8,18

b) 4,9,12,2,6,8,18

c) 2,4,12,9,6,8,18

d) 2,4,6,8,9,12,18

e) 2,4,9,12,6,8,18

(2) Which of the following lists of numbers would accurately show the array after the first pass through the Insertion Sort algorithm?

a) 9,4,12,2,6,8,18

b) 2,4,12,9,6,8,18

c) 4,9,12,2,6,8,18

d) 4,2,9,12,6,8,18

e) 2,4,6,8,9,12,18

(3) What is the difference between the two sort algorithms?

Explanation / Answer

1)- Selection sort algorithm, in the first pass will replace the smallest element of the array with first element of that array

so 9 will be replaced by 2

hence correct answer is

c) 2,4,12,9,6,8,18

2. insertion sort takes the element from array index 1 and insert them at their proper place one by one

so it will take element 4 and try to insert it at it's true order which will be before 9

hence after first pass elements would be:

c) 4,9,12,2,6,8,18

3.Difference b/w two algorithms: in selection sort at each pass the smallest element in array is found out and replaced with the ith element where i goes from 0 to n-1 whilein the insertion sort we iterate from i=1 to i=n-1and insert ith element in its sorted order in array indexed from 0 to i