Still having a hard time understanding this material. Any help is greatly apprec
ID: 3869256 • Letter: S
Question
Still having a hard time understanding this material. Any help is greatly appreciated!
Information All the questions below refer to the same array. You have to type your answer on a single line with one space between each number to get it correct. The initial array is 4 2 136 So if the question was to type in the initial array, you would enter 42136 And if the question was what is the sorted array, you would answer 1 2 346 Question 1 (1 point) What is the contents of the array after 1 pass of insertion sort (into ascending order?) A single pass includes inserting the selected element in it's correct position Save Question 2 (1 point) inserting the selected element in it's correct position Save Question 3 (1 point) What is the contents of the array after 3 passes of insertion sort (into ascending order?) A single pass includes inserting the selected element in it's correct positionExplanation / Answer
Q1- 2,4,1,3,6 as in insertion sort the first element is compared as sorted so for susequent usorted elements it is compared to the previous elements. so in iteraaation 1 4 is considered as sored so the next unsorted element is 2 so now 2 is compared with 4 it is smaller so the elements are swapped so after 1 pass the o/p is 2,4,1,3,6
Q2-1,2,4,3,6 similarly after pass 1 pass 2 is started and element 1 is taked as next unsorted element and it is first compared with 4 it is less so 4 and 1 are swapped again 1 is compared to 2 it is again found less so again it is swapped so after pass 2 o/p is 1,2,4,3,6.
Q3-1,2,3,4,6 again in pass 3 next unsorted element is 3 so it is compared with 4 it is found less so 3 and 4 are swapped now 3 is compared with 2 it is greater so the comparision fails and the pass is stopped here so after pass 3 the o/p is 1,2,3,4,6
Q4-1,2,3,4,6 in pass 4 6 is compared with 4 it is greater than 4 so no swappingg is done and the iterations is stopped as all the elements before 4 are sorted so the o/p after pass 4 is 1,2,3,4,6
Q5 true as after the array is in order no more comparisions are left so at this point insertion sort ends its execution.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.