algorithm - 证明 10 次交换存在 O(n) 算法

标签 algorithm sorting swap

一个著名的问题是找到对数组进行排序的最小交换量。我的问题是我们有大小为 n 的数组,我们知道我们可以用 10 次交换对它进行排序(我们不知道移动,只知道移动的次数)。我想证明存在一个对这个数组进行排序的 O(n) 算法(对于时间)。

首先,为了证明这个陈述,我应该提供一些代码吗?我不知道如何证明 其次,这与排序数组的最小交换量有关吗?

谢谢你的帮助

最佳答案

您的解决方案在 Adaptive sorts algorithms 中.

A classic example of an adaptive sorting algorithm is Straight Insertion Sort. In this sorting algorithm, we scan the input from left to right, repeatedly finding the position of the current item, and insert it into an array of previously sorted items.

我们知道:

The performance of this algorithm can be described in terms of the number of inversions in the input, and then T(n) will be roughly equal to I(A)+(n-1), where I(A) is the number of Inversions.

因此,在您的情况下,反转的次数是常数,该算法的复杂度将为 Theta(n)

关于algorithm - 证明 10 次交换存在 O(n) 算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58473663/

相关文章:

python - BM-25搜索算法在python中的实现

java - SHA 算法每次为相同的 key 生成唯一的哈希字符串

C 程序在给出正确输出后意外崩溃

c++ - 如何在没有复制赋值运算符的情况下交换两个对象?

algorithm - Photoshop 的高光或阴影改变背后的算法是什么?

c# - 如何在遵守某些约束的同时生成数字序列?

javascript - 如何在javascript Map中保持顺序?

PostgreSQL - 按 UUID 版本 1 时间戳排序

ios - 如何对填充了我自己的对象的 NSMutableArray 进行排序

java - Java JVM 中的内存交换到磁盘