由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 我来贡献一个面试题吧
相关主题
有人能解释一下这段C++代码吗帮帮看看这段tree insertion
C++缘何厚deque薄queue?问个简单的问题
为一个atoi 竟然还要争;我来给个标准答案[合集] 如何得到一个指向STL元素的指针?
some problems with "cin"about loop-invariant optimization
A problem on string parsing (using either grep or perl)一道算法题,到现在也没弄明白,谁能帮忙看看。
一道C++面试编程题c++ exception
an interview questionC++: exception: out-of-order execution?
Efficient algorithms for finding number, help please一个图形变形的问题
相关话题的讨论汇总
话题: 2k话题: requires话题: 4k话题: algorithm话题: heap
进入Programming版参与讨论
1 (共1页)
w***g
发帖数: 5958
1
一个数列排序。已知每个数在原数列中的位置和排完序后的位置相差不超过K位。如何设
计排序算法。
昨天被面的。在给出证明算法正确时相当地纠结了一阵。
a****o
发帖数: 686
2
O(n log k)
a****o
发帖数: 686
3
The key invariant is to show that after every iteration of the loop, the
heap contains the smallest element in every list. (omit a formal induction
proof, as the question only asked you to devise an algorithm.) Notice that
each EXTRACT-MIN and INSERT operation requires O(lg k) time, since there are
never more than 2k elements in the heap. The loop requires only a constant
amount of other work, and is repeated n times, resulting in O(nlg k) running
time.
s*w
发帖数: 729
4
more details:
sorted lists are as:
1,2k+1,4K+1,...
2,2k+2,4k+2,...
...
2k,2k+2k,4k+2k...
total 2k lists to merge
so o(nlogk) with n as total # of elements
a****o
发帖数: 686
5
the algorithm requires no merge. and i'm not sure if your method works.

【在 s*w 的大作中提到】
: more details:
: sorted lists are as:
: 1,2k+1,4K+1,...
: 2,2k+2,4k+2,...
: ...
: 2k,2k+2k,4k+2k...
: total 2k lists to merge
: so o(nlogk) with n as total # of elements

1 (共1页)
进入Programming版参与讨论
相关主题
一个图形变形的问题A problem on string parsing (using either grep or perl)
求react-bootstrap和node/express一起使用的例子一道C++面试编程题
本质上说魏和姜的方案就是an interview question
cnn 如何做到 scale invariantEfficient algorithms for finding number, help please
有人能解释一下这段C++代码吗帮帮看看这段tree insertion
C++缘何厚deque薄queue?问个简单的问题
为一个atoi 竟然还要争;我来给个标准答案[合集] 如何得到一个指向STL元素的指针?
some problems with "cin"about loop-invariant optimization
相关话题的讨论汇总
话题: 2k话题: requires话题: 4k话题: algorithm话题: heap