由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个微软面试题
相关主题
问个简单的GooG题目请教个面试题
问个google面试题问个google面试题
问个关于排序的面试题问个微软面试题
一道面试题问个Introduction to Algorithms上的BST题
问一道F家面试题问个binary search tree的问题
BST合并的面试题问个面试题
明天面老中,考虑差不多就放水问个amazon面试题
写个面经 分享一些题目问个google面试题
相关话题的讨论汇总
话题: algorithm话题: time话题: numbers话题: constraint话题: edp
进入JobHunting版参与讨论
1 (共1页)
B*******1
发帖数: 2454
1
Difference is Minimum
Algorithm to find the two numbers whose difference is minimum among the set
of numbers.
For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
The algorithm should return min diff = 20-19 = 1.
Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
known & is not an option. Try to keep it linear
d****3
发帖数: 93
2
坑?
这个问题至少nlogn, 可以证明的...

set

【在 B*******1 的大作中提到】
: Difference is Minimum
: Algorithm to find the two numbers whose difference is minimum among the set
: of numbers.
: For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
: The algorithm should return min diff = 20-19 = 1.
: Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
: Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
: known & is not an option. Try to keep it linear

B*******1
发帖数: 2454
3
不是坑, careercup上面看来的。
s**x
发帖数: 405
4
O(n) time is impossible.
If an O(n) time algorithm for this problem exists, then such an algorithm
can also solve EDP (the Element Distinctness Problem, http://en.wikipedia.org/wiki/Element_distinctness_problem) in O(n) time.
Unfortunately EDP is proved to be Θ(nlogn).
I*********g
发帖数: 93
5
这个问题的特殊性在于元素是数。
solution和bucket sort 类似
s*******f
发帖数: 1114
6
it may also be solved in linear expected time by a randomized algorithm that
inserts each item into a hash table and compares only those elements that
are placed in the same hash table cell.[1]

【在 s**x 的大作中提到】
: O(n) time is impossible.
: If an O(n) time algorithm for this problem exists, then such an algorithm
: can also solve EDP (the Element Distinctness Problem, http://en.wikipedia.org/wiki/Element_distinctness_problem) in O(n) time.
: Unfortunately EDP is proved to be Θ(nlogn).

l*****a
发帖数: 14598
7
The internal implementation of set in STL is BST
so in fact set is already sorted...

set

【在 B*******1 的大作中提到】
: Difference is Minimum
: Algorithm to find the two numbers whose difference is minimum among the set
: of numbers.
: For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
: The algorithm should return min diff = 20-19 = 1.
: Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
: Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
: known & is not an option. Try to keep it linear

a********m
发帖数: 15480
8
“compares only those elements that are placed in the same hash table cell.
”这个不能保证总是线性吧。关键怎么选hashtable大小?

that

【在 s*******f 的大作中提到】
: it may also be solved in linear expected time by a randomized algorithm that
: inserts each item into a hash table and compares only those elements that
: are placed in the same hash table cell.[1]

B*******1
发帖数: 2454
9
Difference is Minimum
Algorithm to find the two numbers whose difference is minimum among the set
of numbers.
For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
The algorithm should return min diff = 20-19 = 1.
Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
known & is not an option. Try to keep it linear
d****3
发帖数: 93
10
坑?
这个问题至少nlogn, 可以证明的...

set

【在 B*******1 的大作中提到】
: Difference is Minimum
: Algorithm to find the two numbers whose difference is minimum among the set
: of numbers.
: For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
: The algorithm should return min diff = 20-19 = 1.
: Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
: Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
: known & is not an option. Try to keep it linear

相关主题
BST合并的面试题请教个面试题
明天面老中,考虑差不多就放水问个google面试题
写个面经 分享一些题目问个微软面试题
进入JobHunting版参与讨论
B*******1
发帖数: 2454
11
不是坑, careercup上面看来的。
s**x
发帖数: 405
12
O(n) time is impossible.
If an O(n) time algorithm for this problem exists, then such an algorithm
can also solve EDP (the Element Distinctness Problem, http://en.wikipedia.org/wiki/Element_distinctness_problem) in O(n) time.
Unfortunately EDP is proved to be Θ(nlogn).
I*********g
发帖数: 93
13
这个问题的特殊性在于元素是数。
solution和bucket sort 类似
s*******f
发帖数: 1114
14
it may also be solved in linear expected time by a randomized algorithm that
inserts each item into a hash table and compares only those elements that
are placed in the same hash table cell.[1]

【在 s**x 的大作中提到】
: O(n) time is impossible.
: If an O(n) time algorithm for this problem exists, then such an algorithm
: can also solve EDP (the Element Distinctness Problem, http://en.wikipedia.org/wiki/Element_distinctness_problem) in O(n) time.
: Unfortunately EDP is proved to be Θ(nlogn).

l*****a
发帖数: 14598
15
The internal implementation of set in STL is BST
so in fact set is already sorted...

set

【在 B*******1 的大作中提到】
: Difference is Minimum
: Algorithm to find the two numbers whose difference is minimum among the set
: of numbers.
: For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
: The algorithm should return min diff = 20-19 = 1.
: Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
: Assumption - Sorting O(nlogn) & comparison of adjacent numbers is already
: known & is not an option. Try to keep it linear

a********m
发帖数: 15480
16
“compares only those elements that are placed in the same hash table cell.
”这个不能保证总是线性吧。关键怎么选hashtable大小?

that

【在 s*******f 的大作中提到】
: it may also be solved in linear expected time by a randomized algorithm that
: inserts each item into a hash table and compares only those elements that
: are placed in the same hash table cell.[1]

a*****t
发帖数: 30
17
嗯,在想这样行不行:
设数组有N 个数A[0..N-1],最小min, 最大max..
建立N-1个bucket, b[0],b[1]...b[N-2];
A[i]放入b[j],j=(i-min)/(max-min) * (N-1);
同时A[i] 跟 b[j-1],b[j],b[

【在 a********m 的大作中提到】
: “compares only those elements that are placed in the same hash table cell.
: ”这个不能保证总是线性吧。关键怎么选hashtable大小?
:
: that

1 (共1页)
进入JobHunting版参与讨论
相关主题
问个google面试题问一道F家面试题
问个google面试题BST合并的面试题
问个大数据处理的面试题明天面老中,考虑差不多就放水
一个NxN矩阵每行每列都sort好,如何排序?写个面经 分享一些题目
问个简单的GooG题目请教个面试题
问个google面试题问个google面试题
问个关于排序的面试题问个微软面试题
一道面试题问个Introduction to Algorithms上的BST题
相关话题的讨论汇总
话题: algorithm话题: time话题: numbers话题: constraint话题: edp