Purchase Solution

order-statistic tree to count the number of inversions

Not what you're looking for?

Ask Custom Question

Need help to show how to use an order-statistic tree to count the number of inversions in an array of size n in time O(n lg n).

Note that we call a pair (i,j) an inversion if i < j, but key[i] > key[j]. Thus, an increasing sequence has no inversions. A decreasing list has the maximum number of inversions, n(n-1)/2.

I believe we start by letting k be the number of inversions in the sequence. We then create an order-statistic tree and store with each node the original index in the sequence.

Is there anything else we store in the node and what would be the algorithm for the number of inversions?

Purchase this Solution

Solution Summary

Advice on how to use an order-statistic tree to count the number of inversions in an array of size n in time O(n lg n) is offered.

Solution Preview

Please see the attached file.

We use an order statistic tree according to the attribute key[.]. Store with each node the original index in the sequence, an integer between 1 and n which we shall call index[.]. Let size[x] be the size of the subtree rooted at node x. Let left[.] and ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Javscript Basics

Quiz on basics of javascript programming language.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

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.