您的位置:首页 > 其它

归并求逆序数

2018-01-22 20:31 204 查看
Recall the problem of finding the number of inversions. As in the course, we are given a sequence of n numbers a 1 ,··· ,a n , which we assume are all distinct, and we difine an inversion to be a pair i < j such that a i > a j .

We motivated the problem of counting inversions as a good measure of how different two orderings are. However, one might feel that this measure is too sensitive. Let’s call a pair a significant inversion if i < j and a i > 3a j . Given an O(nlogn) algorithm to count the number of significant inversions between two orderings.

有一点需要说明,把A分成两个数列R和L后,分别对R和L求逆序数,然后再求合并后的逆序数。这里对R或者L求逆序数的时候,同时也已经对R和L排好序了,所以合并的时候,求逆的时候,才会出现



其他的没什么注意的点了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  归并 逆序数