摘要:
#include #include #include #ifdef __linux
#include #include #endif void swap(int64_t* A, uint64_t i, uint64_t j)
{ int64_t tmp = A[i]; A[i] = A[j]; A[j] = tmp;
} int64_t ... 阅读全文
摘要:
以下摘自网络 随机化快排:快速排序的最坏情况基于每次划分对主元的选择。基本的快速排序选取第一个元素作为主元。这样在数组已经有序的情况下,每次划分将得到最坏的结果。一种比较常见的优化方法是随机化算法,即随机选取一个元素作为主元。这种情况下虽然最坏情况仍然是O(n^2),但最坏情况不再依赖于输入数据,而是由于随机函数取值不佳。实际上,随机化快速排序得到理论最坏情况的可能性仅为1/(2^n)。所以随机化... 阅读全文