由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 再讨论一个面试难题
相关主题
问个面试题给定一个值和sorted队列,找到所有pair(其和等于给定值)
问一道google面试题(from careercup)那道经典的求和问题
find subset that sum up to given numberyahoo面试题
Given an int array and an int value. Find all pairs in arr题目来啦
问一道题(3)问一道google题(from careercup)
求解ts onsite 题。。请大牛解答问一个小于X距离的问题
all my baozi for people can give some answer to the question这些找missing number的题是不是都不能用求和做?
大家帮忙看看这个4sum怎么就不对再问一道老题
相关话题的讨论汇总
话题: given话题: points话题: middle话题: pairs话题: distance
进入JobHunting版参与讨论
1 (共1页)
b******7
发帖数: 79
1
Given a set of points (x,y) , find all pairs of points whose distance is
less than a given number, say, K.
这个题brute force: 对每个点,求和其他点距离,O(N^2),不知道哪位大侠有高见啊
?请不吝赐教!万分感激!
s*******i
发帖数: 712
2
对啊,我也想问这题。面经里出现好几次,每次出现大家都说很old。就是没一个人给
个答案的。

【在 b******7 的大作中提到】
: Given a set of points (x,y) , find all pairs of points whose distance is
: less than a given number, say, K.
: 这个题brute force: 对每个点,求和其他点距离,O(N^2),不知道哪位大侠有高见啊
: ?请不吝赐教!万分感激!

a**********s
发帖数: 588
3
这个用quad tree解最好, 复杂度是相对于结果大小来说linear的
b****a
发帖数: 4465
4
sort the data, then a binary search?
g*******y
发帖数: 1930
5
我觉得应该也能用closest pair的思路来做吧
我感觉quadtree的思路就是closest pair的思路的二维版

【在 a**********s 的大作中提到】
: 这个用quad tree解最好, 复杂度是相对于结果大小来说linear的
a******h
发帖数: 19
6
KD-tree is also able to find the solution.
b******7
发帖数: 79
7
不太懂,哪位能讲讲基本思路吗?
b******7
发帖数: 79
8
不太懂,哪位能讲讲基本思路吗?
a*****r
发帖数: 55
9
输出结果已经是N*N的了,怎么可能更快。
m*****f
发帖数: 1243
10
我详细说说吧, 就是closest pair的思路
1. 在x轴上排序
2. 取中点x_middle把点分成左半边和右半边
3. 递归寻找左半边和右半边距离小于k得pair
4. 同时还有一边在左,一边在右的pair,
5. 3+4 = all answer
其他都是O(nlogn)没问题, 第四步如果强解一样是o(n^2), 但是因为有条件是小于k,
那么只要考虑 x > x_middle-k 的左边点和 x < x_middle +k 的右边点即可,
并且对某个x_left, 只需考虑
x_middle < x_right < x_middle + k - (x_middle-x_left)
的右边点, 可知是O(n).
应该没错把
n******r
发帖数: 1247
11
没觉得x轴上排序会有什么用
如果k等于最远两点间的距离
那么找出最远的两个点已经是0(N^2)复杂度了

,

【在 m*****f 的大作中提到】
: 我详细说说吧, 就是closest pair的思路
: 1. 在x轴上排序
: 2. 取中点x_middle把点分成左半边和右半边
: 3. 递归寻找左半边和右半边距离小于k得pair
: 4. 同时还有一边在左,一边在右的pair,
: 5. 3+4 = all answer
: 其他都是O(nlogn)没问题, 第四步如果强解一样是o(n^2), 但是因为有条件是小于k,
: 那么只要考虑 x > x_middle-k 的左边点和 x < x_middle +k 的右边点即可,
: 并且对某个x_left, 只需考虑
: x_middle < x_right < x_middle + k - (x_middle-x_left)

f*********r
发帖数: 68
12
这题问的有问题吧. 如果让你输出all pairs of points whose distance is
less than a given number K. 显然是O(N^2).
是不是应该问find K pairs of points with smallest distance. 这个有比O(N^2)好
的算法.

【在 b******7 的大作中提到】
: Given a set of points (x,y) , find all pairs of points whose distance is
: less than a given number, say, K.
: 这个题brute force: 对每个点,求和其他点距离,O(N^2),不知道哪位大侠有高见啊
: ?请不吝赐教!万分感激!

k***e
发帖数: 556
13
quad tree, kd tree都是computational geometry里面的内容。你们怎么都这么牛x?
令人发指的强啊
1 (共1页)
进入JobHunting版参与讨论
相关主题
再问一道老题问一道题(3)
Leet Code, three sum closest求解ts onsite 题。。请大牛解答
Given a list of Points, output k Points closest to (0,0)怎么做all my baozi for people can give some answer to the question
Amazon first round phone interview大家帮忙看看这个4sum怎么就不对
问个面试题给定一个值和sorted队列,找到所有pair(其和等于给定值)
问一道google面试题(from careercup)那道经典的求和问题
find subset that sum up to given numberyahoo面试题
Given an int array and an int value. Find all pairs in arr题目来啦
相关话题的讨论汇总
话题: given话题: points话题: middle话题: pairs话题: distance