Mergesort and couting the amount of inversions

J

Jochus

Today, I've programmed Mergesort. And it works very good :)!

But now, the teacher said that you could use Mergesort to count the amount
of inversions.

This is what I found on the internet:
 
J

John Ratliff

Jochus said:
Today, I've programmed Mergesort. And it works very good :)!

But now, the teacher said that you could use Mergesort to count the amount
of inversions.

This is what I found on the internet:

---
Note: Merge Sort can be slightly modified to count inversion index (i.e.
bubble sort swaps) in O(n log n) time. When the right partition goes in
first in Merge step, that means all the remaining items in left partition <
first element in right partition (i.e. you have to swap with all of them).

This is not a question for comp.lang.c++ which deals with standard C++
language issues ONLY. Please find a newgrsoup dedicated to algorithms.

See http://www.parashift.com/c++-faq-lite/ for more information.

--John Ratliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top