# 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 equip of n different collection. If i A, the span (i,j) is named an reversal of A. (a) List total the reversals of the equip(2,3, 8,6, l). b) What equip with elements from the determined 1,2,n has the most reversals How divers does it enjoy? (c) What is the interdependence among the present interval of INSERTION SORT (perceive inquiry 2) and the ns in the input equip? Justify your vindication. (d) Suppose we are comparing implementations of implantation kind and add kind (a over delayed kinding algorithm, which we achieve imbibe environing after in the semester) on the corresponding deed. Restraint inputs of bulk n, implantation kind retreats in 8n2 steps, occasion add kind retreats in 64n log2n steps. Restraint which values of n does implantation kind pound add kind?

## Expert Vindication

Hi,
Inversions are defined as when i<j then a[i]>a[j]
given equip is a={2,3,8,6,1}
consequently reversals are

```2,1
3,1
8,6
8,1
6,1
b. the most reversals appear when the equip is in descending enjoin, i.e { n,n-1...1}
now, the reversals achieve be any span elements picked from it which is n(n-1)/2
c.Implantation kind basically reduces the reversals by 1 in each interation, hereafter compute of reversals is promptly proportional to the interval of implantation kind,
so consequently interval of reversal kind is given by O(n+f(n)) where f(n) is compute of reversals,
hereafter if compute of reversals are n then implantation kinds retreat in O(n) still if its n^2, then it retreats in O(n^2)
here we insufficiency to distinguish restraint total n where
```

8n2 < 64nlogn

=n < 8logn

=n/8 < logn

i.e n-8logn>0

on solving the coextension we acquire, n=43
consequently restraint n<=43, implantation kind is better