最佳反转指望INT数组 [英] Optimal inversion counting on int arrays

查看:159
本文介绍了最佳反转指望INT数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我一直在寻找本地信息学奥林匹克竞赛的最新的考试,我发现了一个有趣的问题。简单地说,它要求为,给定一个整型数组,算多少倒有,在哪里反转是一对indicies的Ĵ等>的 A [1] - ; A [J] 。非正式地,反转的数目是对那些不按顺序的数目。最初,我犯了一个 O(N²)解决方案(是的,天真的),但看到它不会随输入的大小合身,我想过这个问题多一点,然后我意识到,这是可以通过一个变种合并排序,处理好投入的规模在做到这一点为O(n log n)的的时间。

Today I was looking the latest exam of the local informatics olympiad and I found a interesting problem. Briefly, it asks to, given an integer array, count how many inversions it has, where an inversion is a pair of indicies i, j such that i > j and A[i] < A[j]. Informally, the number of inversions is the number of pairs that are out of order. Initially I made a O(n²) solution (yes, the naive one), but seeing it wouldn't fit well with the size of the input, I thought about the problem a bit more and then I realized it's possible to do it within O(n log n) time by a variant of merge sort, which handles good the size of the input.

但在看到输入约束( N 整数1和M ,并没有重复),我想知道如果我的解决方案是最佳的,还是你知道还有没有其他办法解决这个问题的跳动为O(n log n)的运行?

But seeing the input constraints (n integers between 1 and M, and no duplicates), I was wondering if my solution is optimal, or do you know if is there any other solution to this problem that beats O(n log n) runtime?

推荐答案

最好的结果文献是为O(n√(log n)的)算法因的Chan和Patrascu 的。不知道有关的常数。

The best result in the literature is an O(n √(log n)) algorithm due to Chan and Patrascu. No idea about the constant.

这篇关于最佳反转指望INT数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆