Question: Problem 1. (20 points) Let A -fa,a2 an be an array of n distinct numbers. I i aj, then the pair (i, j) ls called

 Problem 1. (20 points) Let A -fa,a2 an be an array

Problem 1. (20 points) Let A -fa,a2 an be an array of n distinct numbers. I i aj, then the pair (i, j) ls called an inversion of A. a) List the five inversions of the array (2,3,8,6,1) b) What array with elements from the set 1,2,.n has the most inversions? How many does it have? c) What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer. The insertion sort algorithm is reproduced here for your reference. o procedure insertion-sort (ai,a,2, an are n distinct integers for j 2 to do key: a i-j -1 2 3 4whilei >0 and a, > key do D insert aj into the sorted sequence a..,aj-1 i41a 5 6 8 iput now sorted in ascending order Hint: How many inversions does each iteration of the while loop in lines 4 - 6 eliminate

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!