Purchase Solution

Significant Inversions Algorithm : Inversion Pairs

Not what you're looking for?

Ask Custom Question

You are given a sequence of n distinct numbers A1, ... , An. An inversion is a pair i < j such that Ai > Aj. Call a pair (i, j) a significant inversion if i < j and Ai > 2*Aj. Give an O(n*log(n)) algorithm to count the number of significant inversions in the input sequence.

Purchase this Solution

Solution Summary

An algorithm for inversion pairs is investigated.

Solution Preview

Use quick sort to sort the sequence S as sorted sequence S' as A1', A2', ...., An', time is n*log(n).

Find the position of each element of S in S' using binary search. For example:

S: 9 3 6 18 2 7 54
S': 2 3 6 7 9 18 54

Then the positions of each element of S' is:

position: 5, 2, 3, 6, 1, ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Networking Questions

This quiz consists of some basic networking questions.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.