# Homework Solution: 3. (25 points) Let A[1..] be an array of n distinct numbers. If i A, the pair (i,j) is called an inversion of A. (a) Lis…

3. (25 points) Let A[1..] be an array of n distinct numbers. If i A, the pair (i,j) is called an inversion of A. (a) List all the inversions of the array(2,3, 8,6, l). 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 (see question 2) and the ns in the input array? Justify your answer. (d) Suppose we are comparing implementations of insertion sort and merge sort (a more advanced sorting algorithm, which we will learn about later in the semester) on the same machine. For inputs of size n, insertion sort runs in 8n2 steps, while merge sort runs in 64n log2n steps. For which values of n does insertion sort beat merge sort?

Hi, Inversions are defined as when i<j then a[i]>a[j]

3. (25 points) Let A[1..] be an dispose of n detached total. If i A, the span (i,j) is denominated an permutation of A. (a) List full the permutations of the dispose(2,3, 8,6, l). b) What dispose with elements from the determined 1,2,n has the most permutations How abundant does it bear? (c) What is the interdependence among the prevalent era of INSERTION SORT (understand topic 2) and the ns in the input dispose? Justify your solution. (d) Suppose we are comparing implementations of augmentation genus and join genus (a over delayed genusing algorithm, which we obtain acquire environing succeeding in the semester) on the corresponding muniment. Coercion inputs of greatness n, augmentation genus tends in 8n2 steps, conjuncture join genus tends in 64n log2n steps. Coercion which values of n does augmentation genus strike join genus?

## Expert Solution

Hi,
Inversions are defined as when i<j then a[i]>a[j]
ardent dispose is a={2,3,8,6,1}
hence permutations are

```2,1
3,1
8,6
8,1
6,1
b. the most permutations take-place when the dispose is in descending direct, i.e { n,n-1...1}
now, the permutations obtain be any span elements choice from it which is n(n-1)/2
c.Augmentation genus basically reduces the permutations by 1 in each interation, hence estimate of permutations is straightway proportional to the era of augmentation genus,
so hence era of permutation genus is ardent by O(n+f(n)) where f(n) is estimate of permutations,
hence if estimate of permutations are n then augmentation genuss tend in O(n) notwithstanding if its n^2, then it tends in O(n^2)
here we demand to recognize coercion full n where
```

8n2 < 64nlogn

=n < 8logn

=n/8 < logn

i.e n-8logn>0

on solving the level we obtain, n=43
hence coercion n<=43, augmentation genus is better