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

What will the array look like after 1 pass of insertion sort into ascending orde

ID: 3867313 • Letter: W

Question

What will the array look like after 1 pass of insertion sort into ascending order?

What will the array look like after 2 pass of insertion sort into ascending order?

What will the array look like after 3 pass of insertion sort into ascending order?

What will the array look like after 4 pass of insertion sort into ascending order?

AND

What will the array look like after 1 pass of selection sort into ascending order?

What will the array look like after 2 pass of selection sort into ascending order?

What will the array look like after 3 pass of selection sort into ascending order?

What will the array look like after 4 pass of selection sort into ascending order?

Given the following array values (as integers) 50 20 10 30 40

Explanation / Answer

1-What will the array look like after 1 pass of insertion sort into ascending order?

ans- It will look like this - 20,50,10,30,40 as in insertion sort the first element is considered as sorted the subsequent elements are sorted . so in this pass the 2nd element will be compared with the first element and as 20<50 so it is swapped.

2-What will the array look like after 2 pass of insertion sort into ascending order?

ANS- it will look like this 10,20,50,30,40 as now in this iteration first the 3rd element is compared with 2nd element as 10<50 it is swapped then 2nd element is compared with first element 10<20 so again it is swapped.

3-What will the array look like after 3 pass of insertion sort into ascending order?

ANS- it will look like 10,20,30,50,40 as nowin this iteration 4th element is compared with the 3rd element as 30<50 it is swapped then 3rd element is compared with 2nd element but 30>20 so it is not swapped and comparision stops here.

4-What will the array look like after 4 pass of insertion sort into ascending order?

ANS-it will look like 10,20,30,40,50 as in this pass 5th element is compared with 4th element so 40<50 so it is swapped now 4th element is compared with 3rd element 30<40 so it is not swapped and comparision ends here.

AND

1-What will the array look like after 1 pass of selection sort into ascending order?

ANS- it will look like 10,20,50,30,40 as in insertion sort the first element is assigned as the current minimum and it is compared with all the elements and the minimum element is found in the list and when the minimum element is found it is swapped with the first element and as the minimum element is in its position now commparisions starts from the second element and so on.

2-What will the array look like after 2 pass of selection sort into ascending order?

ANS- 10,20,50,30,40 as now first element is sorted so now current min is the second element i.e 20 and it is compared with all the elements after it and it is found that it is minimum element so no swapping occurs.

3-What will the array look like after 3 pass of selection sort into ascending order?

ANS- 10,20,30,50,40 as first 2 elements are sorted so now 50 is the current minimum and it is compared with the elements after it so minimum element founnd is 30 so it is swapped with 50.

4-What will the array look like after 4 pass of selection sort into ascending order?

ANS- 10,20,30,40,50 now as 3 elements are sorted so 4th element that is 50 is again current minimum so it is compared wwith only left element i.e 40 so min is now 40 and it is swapped with 50.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote