Question: 2. (20 pts) Given a sequence of numbers A, design an algorithm that counts the number of inversions, where an inversion is a pair

2. (20 pts) Given a sequence of numbers A, design an algorithm

2. (20 pts) Given a sequence of numbers A, design an algorithm that counts the number of inversions, where an inversion is a pair (a;, a) such that i aj. Please state the steps of your algorithm clearly and analyze its running time. (a) (10 pts) Given two sorted arrays L and R, design a linear (O(|L| + |R|)) time algorithm that counts the number of pairs (1,r) such that 1 L, r = R and I > r. (b) (10 pts) Suppose we have a linear time algorithm for question (a), design a O(n log n) time algorithm that computes the number of inversion in A.

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 Programming Questions!