Redian新闻
>
editor 的supporting letter上的地址该怎么写?
avatar
editor 的supporting letter上的地址该怎么写?# Immigration - 落地生根
b*b
1
已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
我想到的使用hash,提示说binary search tree更好……没想到idea。
求教
avatar
I*1
2
如果不写具体的center,就直接写:
U.S. Department of Homeland Security
U.S. Citizenship and Immigration Services
是不是可以?
还有看到有的人写的地址是:
United States Department of Justice
Immigration and Naturalization Service
到底哪个是正确的?
谢谢!
avatar
i*h
3
hash是O(N)
BST要O(NlgN)吧?
avatar
i*3
4
In all letters, I used:
U.S. Department of Homeland Security
U.S. Citizenship and Immigration Services
avatar
b*b
5
为什么是nlgn, 已经sorted了。
我觉得关键他要求的是第一个。。。这个不知道该怎么处理

【在 i***h 的大作中提到】
: hash是O(N)
: BST要O(NlgN)吧?

avatar
c*g
6
随便哪个都行
avatar
d*o
7
输入和输出再定义清楚。
输入是什么,输出是什么?
给个例子。

【在 b******b 的大作中提到】
: 已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
: 我想到的使用hash,提示说binary search tree更好……没想到idea。
: 求教

avatar
l*a
8
他的提示也不对啊
已经有序就首尾找。。

【在 b******b 的大作中提到】
: 已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
: 我想到的使用hash,提示说binary search tree更好……没想到idea。
: 求教

avatar
i*h
9
你在排序里面二分法找一个数不得 O(lgN)?

【在 b******b 的大作中提到】
: 为什么是nlgn, 已经sorted了。
: 我觉得关键他要求的是第一个。。。这个不知道该怎么处理

avatar
d*e
10
这个不应该是一头一尾两个index移动吗?

【在 b******b 的大作中提到】
: 已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
: 我想到的使用hash,提示说binary search tree更好……没想到idea。
: 求教

avatar
b*b
11
输入是一个sorted的数组
1,2,3,3,4,5.。。。
如果要求两个数之和为6,
输出为 3 ,3

【在 d****o 的大作中提到】
: 输入和输出再定义清楚。
: 输入是什么,输出是什么?
: 给个例子。

avatar
i*h
12
哦是你对, 这样一来只要O(N)
还是和BST没关系

【在 d**e 的大作中提到】
: 这个不应该是一头一尾两个index移动吗?
avatar
h*y
13
我也觉得如此,难道我题目没有看明白?

【在 d**e 的大作中提到】
: 这个不应该是一头一尾两个index移动吗?
avatar
i*h
14
为什么不是1,5?

【在 b******b 的大作中提到】
: 输入是一个sorted的数组
: 1,2,3,3,4,5.。。。
: 如果要求两个数之和为6,
: 输出为 3 ,3

avatar
b*b
15
因为 相比于1,5,
3,3 是最早完整出现的
原谅我的表达吧。。。。实在是表述不清楚了

【在 i***h 的大作中提到】
: 为什么不是1,5?
avatar
i*h
16
我知道了
用BST 找 6/2
然后中心开花向外找

【在 b******b 的大作中提到】
: 因为 相比于1,5,
: 3,3 是最早完整出现的
: 原谅我的表达吧。。。。实在是表述不清楚了

avatar
d*e
17
真的不是很明白
不过可以在于你从哪里数起
我觉得应该从1开始数

【在 b******b 的大作中提到】
: 因为 相比于1,5,
: 3,3 是最早完整出现的
: 原谅我的表达吧。。。。实在是表述不清楚了

avatar
b*b
18
恩,恩,就是从1开始数起

【在 d**e 的大作中提到】
: 真的不是很明白
: 不过可以在于你从哪里数起
: 我觉得应该从1开始数

avatar
d*e
19
我明白题目的意思了。
谢谢。

【在 b******b 的大作中提到】
: 恩,恩,就是从1开始数起
avatar
b*b
20
这样是不是还得取决于建立一个结构良好的二叉树?
如果二叉树是个高度为n的二叉树,计算复杂度也不低啊

【在 i***h 的大作中提到】
: 我知道了
: 用BST 找 6/2
: 然后中心开花向外找

avatar
d*e
21
我觉得前面有同学说的正确
用hash就是O(n)空间,O(n)时间
用bst是O(1)空间,O(nlgn)时间

【在 b******b 的大作中提到】
: 恩,恩,就是从1开始数起
avatar
i*h
22
排序数组本身就是一个平衡BST啊

【在 b******b 的大作中提到】
: 这样是不是还得取决于建立一个结构良好的二叉树?
: 如果二叉树是个高度为n的二叉树,计算复杂度也不低啊

avatar
i*h
23
对这个问题, 时间是 O(lgN + N), 也是O(N)

【在 d**e 的大作中提到】
: 我觉得前面有同学说的正确
: 用hash就是O(n)空间,O(n)时间
: 用bst是O(1)空间,O(nlgn)时间

avatar
i*h
24
不过最坏情况还没从头开始找好...

【在 i***h 的大作中提到】
: 对这个问题, 时间是 O(lgN + N), 也是O(N)
avatar
b*b
25
对哦,一下糊涂了,汗……

【在 i***h 的大作中提到】
: 排序数组本身就是一个平衡BST啊
avatar
y*u
26
移动的过程可以用binary search

【在 d**e 的大作中提到】
: 这个不应该是一头一尾两个index移动吗?
avatar
y*u
27
hash 显然有worst case啊

【在 d**e 的大作中提到】
: 我觉得前面有同学说的正确
: 用hash就是O(n)空间,O(n)时间
: 用bst是O(1)空间,O(nlgn)时间

avatar
d*e
28
我好像跟我之前遇到的题混了一下,但这样似乎也是O(n)?
for each x in the array
map(x) = N-x
index_end = -1
for i in 0..n-1
if exists map(map(array_i))
if index_end == -1
index_end = n-1-i
else
index_end = min(index_end, n-1-i)
if index_end != -1
return (n-1-index_end, index_end)

【在 y**********u 的大作中提到】
: hash 显然有worst case啊
avatar
y*n
29
头一个指针从左到右找。然后通过binary search 找另一个数。worse case是olgn.
avatar
d*y
30
头一个指针从左到右找。然后通过binary search 找另一个数。
It makes sense, pointer + a sorted numbers
worse case是olgn.
How can get this?
avatar
y*n
31
= =刚刚二B了- -worse case还是O(n)吧

【在 d******y 的大作中提到】
: 头一个指针从左到右找。然后通过binary search 找另一个数。
: It makes sense, pointer + a sorted numbers
: worse case是olgn.
: How can get this?

avatar
y*n
32
I made it wrong again, it should be nlog(n)
log(n-1)+log(n-2)+....log(1) = log((n-1)*log(n-2)*...log(1))
=O(nlog(n))
Hope it is right this time

【在 d******y 的大作中提到】
: 头一个指针从左到右找。然后通过binary search 找另一个数。
: It makes sense, pointer + a sorted numbers
: worse case是olgn.
: How can get this?

avatar
r*n
33
O(N)

【在 b******b 的大作中提到】
: 已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
: 我想到的使用hash,提示说binary search tree更好……没想到idea。
: 求教

avatar
d*y
34
log(n-1)+log(n-2)+....log(1) = log((n-1)*log(n-2)*...log(1))
=O(nlog(n))
this one should be
log(n-1)+log(n-2)+....log(1) = log((n-1)(n-2)...(1))log(n-1) O(nlog(n))
Is this right?
avatar
b*u
35
不好用吧?一个heap容易用数组表示,可用sorted array的话,root和child index的
关系不容易表达。
这题从左到右每个对后面进行binary search就行,找到N/2还没有就没了。O(nlogn).

【在 i***h 的大作中提到】
: 排序数组本身就是一个平衡BST啊
avatar
g*u
36
Imput:
array A, sum s.
Output:
pair (u,v)
Given an sorted array, choose the middle element m, then m is the root of a
balanced BST. If s-m>m, we search the right sub-tree, otherwise we search
the left sub-tree. Doing this recursively, we can find (u,v) in O(log(n)).

【在 b******b 的大作中提到】
: 输入是一个sorted的数组
: 1,2,3,3,4,5.。。。
: 如果要求两个数之和为6,
: 输出为 3 ,3

avatar
g*u
37
哦,不好意思,这个不对,有可能 u 在 left subtree,而 v 在 right subtree

a

【在 g**u 的大作中提到】
: Imput:
: array A, sum s.
: Output:
: pair (u,v)
: Given an sorted array, choose the middle element m, then m is the root of a
: balanced BST. If s-m>m, we search the right sub-tree, otherwise we search
: the left sub-tree. Doing this recursively, we can find (u,v) in O(log(n)).

avatar
y*u
38
这个map是什么数据结构?
如果是array的话,小心越界。如果是hash或者bst的话,不止O(n)了

【在 d**e 的大作中提到】
: 我好像跟我之前遇到的题混了一下,但这样似乎也是O(n)?
: for each x in the array
: map(x) = N-x
: index_end = -1
: for i in 0..n-1
: if exists map(map(array_i))
: if index_end == -1
: index_end = n-1-i
: else
: index_end = min(index_end, n-1-i)

avatar
r*n
39
这题牙根就不用神马BST
有一道很出名的题, 给一个2-d array, 冲右冲下都是递增的, 怎么找其中的某个
element...答案是从右上角开始一步一步走, O(n)时间
看着眼熟不?

【在 b******b 的大作中提到】
: 已知一个sorted的array,怎么找到第一个pair的两个数,其之和为N。
: 我想到的使用hash,提示说binary search tree更好……没想到idea。
: 求教

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