由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一个NxN矩阵每行每列都sort好,如何排序?
相关主题
Print out all elements in a sorted matrix请问一个老的google题
问道面试题小公司面试官问我做出的最大成就是什么?
算法一问一个特别的inplace merge two sorted arrays
Find the K largest element in a sorted M*N array数组中找和为0的3个数,4个数
heap sort的缺点是什么?和quick sort比问个经典问题的improvement
贡献另外一个Amazon面试的题算法问题,m*m matrix
请教一个老算法题, k-th largest sum如何让python dictionary sorting 的速度变得很快? (转载)
说说4sum的复杂度吧电面了个公司,感觉很不好
相关话题的讨论汇总
话题: sorting话题: sort话题: log话题: complexity话题: sqrt
进入JobHunting版参与讨论
1 (共1页)
h*********i
发帖数: 2605
1
我记得以前有人讨论过。一种方法是merge sort, maintain a heap,用时O(n^2logn)
,还有更快的方法么?
h*********i
发帖数: 2605
2
any idea?
k*k
发帖数: 49
3
Constructing Young's Tableau does not offer too much benefit on sorting...
for n^2 numbers, the lower bound for comparison-based sorting is
2 n^2 log n (or N log N if N == n^2)
given each row/col is sorted, sorting will take in O(N^1.5) N * sqrt(N);
N for total numbers, sqrt(N)=n for complexity to extract min from remaining matrix.
N*sqrt(N) > N log N ...
so i guess it is better just sort it directly.
h*********i
发帖数: 2605
4
一共n*n个数字,怎么可能O(N)时间完成呢。
假设你说的是O(n^2),虽然行列都sort好了,但是:
a1 a2
b1 b2
我们还是不知道b1和a2的相对大小
所以每次要从n行里找出最大的(用heap),用O(logn)时间。所以总共应该是O(n^
2logn)。

remaining matrix.

【在 k*k 的大作中提到】
: Constructing Young's Tableau does not offer too much benefit on sorting...
: for n^2 numbers, the lower bound for comparison-based sorting is
: 2 n^2 log n (or N log N if N == n^2)
: given each row/col is sorted, sorting will take in O(N^1.5) N * sqrt(N);
: N for total numbers, sqrt(N)=n for complexity to extract min from remaining matrix.
: N*sqrt(N) > N log N ...
: so i guess it is better just sort it directly.

h*********i
发帖数: 2605
5
发现你刚才修改过了。
我也觉得O(NlogN)是最快的。

remaining matrix.

【在 k*k 的大作中提到】
: Constructing Young's Tableau does not offer too much benefit on sorting...
: for n^2 numbers, the lower bound for comparison-based sorting is
: 2 n^2 log n (or N log N if N == n^2)
: given each row/col is sorted, sorting will take in O(N^1.5) N * sqrt(N);
: N for total numbers, sqrt(N)=n for complexity to extract min from remaining matrix.
: N*sqrt(N) > N log N ...
: so i guess it is better just sort it directly.

k*k
发帖数: 49
6
yes... but with additional space for min-heap
considering the complexity of constructing such a table in addition to the n
^2 log n sorting complexity...
young's table is really not a good way to tackle sorting problem....
1 (共1页)
进入JobHunting版参与讨论
相关主题
电面了个公司,感觉很不好heap sort的缺点是什么?和quick sort比
问一个时间复杂度的问题,数组里取k个最大数贡献另外一个Amazon面试的题
Young Tableau如何找出前n个最小元素?请教一个老算法题, k-th largest sum
【什么时候需要做heap, 什么时候需要做BST】说说4sum的复杂度吧
Print out all elements in a sorted matrix请问一个老的google题
问道面试题小公司面试官问我做出的最大成就是什么?
算法一问一个特别的inplace merge two sorted arrays
Find the K largest element in a sorted M*N array数组中找和为0的3个数,4个数
相关话题的讨论汇总
话题: sorting话题: sort话题: log话题: complexity话题: sqrt