Question: help me out, not sure how many times this loop will run for the insertion sort !! 2 - Consider the insertion sort algorithm discussed

 help me out, not sure how many times this loop will

help me out, not sure how many times this loop will run for the insertion sort !!

2 - Consider the insertion sort algorithm discussed in class. See below. (20 points) Consider an array A of five elements, with A1]-5, AI2 7, A3-2, A141-4, and 5] = 3. INSERTION-SORT(A) 1 for j2 to length[A] do key AUI Insert Aj] into the sorted sequence A[1..j - 1] 4 while i > 0 and Ali] > key do Ali + 1] A[i] Ali 1key a) How many times will statement #8 be executed? For each time through the outer-loop given by statement #2, give value ofthe variable "key" after statement #2, and the content of the array right after statement #8 is executed. b) c) How often is statement #6 executed? (Note this statement is in the inner while loop.)

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!