345 views
0 votes
0 votes

Given an array of n elements, two elements in the array a[i] and a[j] are said to be inverse only if a[i]>a[j] && i<j. What is the time complexity required to find the number of inverses in the given array using merge sort?

a) O(n)

b) O(n2)

c) O(nlogn)

d) O(logn)

1 Answer

0 votes
0 votes

Answer is Option B,

Largest possible inversions are possible when array is in decreasing order ,

Eg . [5,4,3,2,1]

therefore total pairs formed is nC2 ,

= n(n-1)/2

=O(n^2)

Therefore , TC = O(n^2)

Related questions

0 votes
0 votes
1 answer
2
Shankar Jha asked Jun 15, 2018
603 views
Assume that merge sort algorithm in the worst case takes 30 seconds for an input of size 64 which of The following most closely approximates the maximum input size of a p...
1 votes
1 votes
1 answer
3
Rishav Kumar Singh asked Jul 25, 2018
914 views
In a modified merge sort, the input array is split at a position one-third of the length(N) of the array. What is the worst case time complexity of this merge sort?