Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

What is the use of bootstrap program?

Answered: 1 week ago

Question

What is a process and process table?

Answered: 1 week ago

Question

What is Industrial Economics and Theory of Firm?

Answered: 1 week ago