+1 vote
in Data Structures & Algorithms I by (110k points)
What is the time complexity of the code that uses merge sort for determining the number of inversions in an array?

(a) O(n^2)

(b) O(n)

(c) O(log n)

(d) O(n log n)

My doubt stems from Arrays Types topic in division Arrays Types of Data Structures & Algorithms I

The question was posed to me in an online interview.

1 Answer

+1 vote
by (408k points)
selected by
 
Best answer
Right answer is (d) O(n log n)

Explanation: The code of merge sort is slightly modified in order to calculate the number of inversions in an array. So the time complexity of merge sort remains unaffected and hence the time complexity is O(n log n).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.

Categories

...