Redian新闻
>
一道比较特别的排序题。求思路求解答。。
avatar
一道比较特别的排序题。求思路求解答。。# JobHunting - 待字闺中
i*7
1
given an array of n unsorted integers and each number is at most k positions
away from its final sorted position, give an efficient sorting algorithm.
avatar
h*t
2

positions
nlogk 复杂度算法.

【在 i*********7 的大作中提到】
: given an array of n unsorted integers and each number is at most k positions
: away from its final sorted position, give an efficient sorting algorithm.

avatar
l*c
3
void kAwaySort(int s[], int n)
{
quickSort(0,k-1);
int i = k;
while(imerge(s, i-k, i-1, i) //merge s[i] into the subarray s[i-k,i-1];
i++;
}
avatar
p*e
4
more details?
I can only come up with O(nk) algorithm

algorithm

【在 h****t 的大作中提到】
:
: positions
: nlogk 复杂度算法.

avatar
Z*Z
5
Note k is between 1 and n-1. As k approaching n-1, your algorithm should con
verge to O(n lgn) naturally :)

【在 p***e 的大作中提到】
: more details?
: I can only come up with O(nk) algorithm
:
: algorithm

avatar
p*e
6
I got it. thx!

con

【在 Z*****Z 的大作中提到】
: Note k is between 1 and n-1. As k approaching n-1, your algorithm should con
: verge to O(n lgn) naturally :)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。