Redian新闻
>
▲▲▲▲▲▲▲▲史上最有争议的征婚信息▲▲▲▲▲▲▲▲▲▲ (转载)
avatar
▲▲▲▲▲▲▲▲史上最有争议的征婚信息▲▲▲▲▲▲▲▲▲▲ (转载)# Fashion - 美丽时尚
y*e
1
先是看到一个facebook的题,说是implement search autocompletion,用trie。
然后又看到一题implement getWords(), 和hasPrefix()
我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
Linkedlist把children连起来,另一个是用hashmap连起来。。。
第一个思路大概是这样的
https://community.oracle.com/thread/2070706
但这个实现的也不严谨。。。
没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
较严谨完整呢?
非常感谢!
avatar
h*e
2
月底或者七月初,从洛杉矶要开车去凤凰城,可以顺路免费带上一程,
avatar
i*t
3
【 以下文字转载自 Piebridge 讨论区 】
发信人: invest (invest), 信区: Piebridge
标 题: ▲▲▲▲▲▲▲▲史上最有争议的征婚信息▲▲▲▲▲▲▲▲▲▲
发信站: BBS 未名空间站 (Sat Mar 26 07:28:05 2011, 美东)
★性别:地球人说是男的,别的星球说是女的
★出生年份:活了几千年的小青年,18熟女还是35的少女通吃
★所在地(至少明确state):香港
★职业情况(学生还是工作):both
★简单的物理参数(身高/体重):八尺猛壮熊男
★血型、星座:未知
★当前婚姻状态(从没结过婚/曾婚/丧偶):记不清了,好像没有
★联系方式(email/IM/站内):email,附照片吧,最好带视频
★是否希望版务对本帖锁贴并禁止讨论:是啊,但是我可以回复顶贴,别人就不要顶了
男人就不要回这个贴和联系我了。不要批评我,言论自由,而且我很蠢,无知,丑陋,
不值一
提,我只是要找个伴侣,不时可以用我的爱心去温存一下,去爱一下,去照顾她一下,
去和她
一起笑一下。本文欢迎转载,但要带上我的联系方式,最好帮助翻译成多国文字,多星
际文
字。因为不介意女的有多少光年,身高有几千公里,体重有几万亿吨,只要不是1克就
好了,还
要最好不要需要用显微镜才看到你。
我想找个好女孩做我的妻子,比我好最好了,那样我就赚到了。尽管理论上不可能,但
是希望

碰到一个傻子。在我面前不计利益得失,极度宽容,最好懂多国语言,这样出国就不用
说英语
人家听不懂了,还可以帮我鼓吹鼓吹我的疯狂的学术理论和痴人梦话。
不怕穿越,不怕自己的老公穿越。相信外星人是存在的,也不介意和外星人交朋友,不
管多
丑。
不怕辛劳,辛劳会有回报,所以越辛苦,回报越大,不会让你吃亏。
不怕埋怨,埋怨是爱,说明你不够完美,说明我不好。
主动爱人,我的爱在心中,需要你探入体知。
视金钱如粪土,赚金钱如长江流水,当然婚前有约,您的金库的钱我分文不取,您赏赐
给我的
我必定笑纳。我的钱可以给您保管。有钱就不必在意我在哪里,你在哪里,因为在一起容易。
最好博士,或相当渊博的本科以上学历
善于关心 对知识充满上瘾性好奇心而经常不顾其他的老公
喜欢旅游,探险,如果我掉到海里了,要冒死把我捞上来,海啸来了,不要看我死掉不管
我是说会去什么圣诞岛,复活节岛还有那些只有100多户的人家,方圆几千里都是水的
岛。
或许到50多岁,我们能凑钱去星际旅行一番,但是希望那时候我们身体都还好,愿意冒
死去去
探险,希望您是一个勇敢的人。
我并不很丑,你最终应该觉得我是世界上最美的人。
我并不是富翁。也没有显赫的地位。我不介意自己的国籍,种族,信仰,道德,法律。
我用心生存。
你一定要很善良,很无私,很勇于奉献,敢于牺牲,为爱献身。
我也会那样。
何时何地,不离不弃。
I am God, you are my Goddess.
Email:n************[email protected]
avatar
r*b
4
It is not a good idea to use trie to implement auto-completeion, espeically
at the facebook scale. Trie consumes a lot of memory, and the pionter-
jumping will lead to a lot of cache miss, and significantly slow down the
cpu.

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
j*g
7
Mark
avatar
b*i
8
楼主能把getWords()和hasPrefix()具体是要干什么描述一下吗
虽然从字面可以猜出大概,但是有题目会好一点,谢谢

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
y*e
9
面经里也没有说。。。我自己理解的是
boolean hasPrefix(String s), 其实就是search, 看看这个string s是不是存在在
trie里面
List getWords(String s), 是找以s开头的所有词,比如给ab,return abc,
abcd, abfg等等。

【在 b******i 的大作中提到】
: 楼主能把getWords()和hasPrefix()具体是要干什么描述一下吗
: 虽然从字面可以猜出大概,但是有题目会好一点,谢谢

avatar
d*v
10
Mark
avatar
a*r
12
C++ R-way trie implementation. Coursera princeton algorithm II 讲的很详细。
const int N = 26;
struct TrieNode{
int val;
vector link;
TrieNode(int x=-1): val(x), link(N){}
};
class Trie{
public:
Trie(){
root = new TrieNode;
}

void put(string &key, int val){
put(root, key, val, 0);
}

int get(string &key){
TrieNode *t = get(root, key, 0);
if(t) return t->val;
else return -1;
}

void remove(string &key){
remove(root, key, 0);
}
private:
TrieNode *root;

void remove(TrieNode *&root, string &key, int d){
if(!root) return;
if(key.length() == d) root->val = -1;

int k = key[d]-'a';
remove(root->link[k], key, d+1);

if(isEmptyNode(root->link[k])){
if(root->link[k]) delete root->link[k];
root->link[k] = nullptr;
return;
}
}

bool isEmptyNode(TrieNode *root){
if(!root) return true;
if(root->val != -1) return false;

for(int i = 0; i < N; i++){
if(root->link[i]) return false;
}

return true;
}

void put(TrieNode *&root, string &key, int val, int d){
if(!root) root = new TrieNode;

if(key.length() == d){
root->val = val;
return;
}

int k = key[d]-'a';
put(root->link[k], key, val, d+1);
}

TrieNode *get(TrieNode *root, string &key, int d){
if(!root) return nullptr;
if(d == key.length()) return root;
int k = key[d]-'a';
return get(root->link[k], key, d+1);
}
};
avatar
l*i
13
facebook hackcup round1 has a trie problem so you can see the world's first
class programmer's implementation.
avatar
y*e
14
要不要这么拼。。。。一流选手的代码俺怎么看的懂。。。

first

【在 l***i 的大作中提到】
: facebook hackcup round1 has a trie problem so you can see the world's first
: class programmer's implementation.

avatar
y*e
15
先是看到一个facebook的题,说是implement search autocompletion,用trie。
然后又看到一题implement getWords(), 和hasPrefix()
我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
Linkedlist把children连起来,另一个是用hashmap连起来。。。
第一个思路大概是这样的
https://community.oracle.com/thread/2070706
但这个实现的也不严谨。。。
没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
较严谨完整呢?
非常感谢!
avatar
r*b
16
It is not a good idea to use trie to implement auto-completeion, espeically
at the facebook scale. Trie consumes a lot of memory, and the pionter-
jumping will lead to a lot of cache miss, and significantly slow down the
cpu.

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
j*g
19
Mark
avatar
b*i
20
楼主能把getWords()和hasPrefix()具体是要干什么描述一下吗
虽然从字面可以猜出大概,但是有题目会好一点,谢谢

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
y*e
21
面经里也没有说。。。我自己理解的是
boolean hasPrefix(String s), 其实就是search, 看看这个string s是不是存在在
trie里面
List getWords(String s), 是找以s开头的所有词,比如给ab,return abc,
abcd, abfg等等。

【在 b******i 的大作中提到】
: 楼主能把getWords()和hasPrefix()具体是要干什么描述一下吗
: 虽然从字面可以猜出大概,但是有题目会好一点,谢谢

avatar
d*v
22
Mark
avatar
a*r
24
C++ R-way trie implementation. Coursera princeton algorithm II 讲的很详细。
const int N = 26;
struct TrieNode{
int val;
vector link;
TrieNode(int x=-1): val(x), link(N){}
};
class Trie{
public:
Trie(){
root = new TrieNode;
}

void put(string &key, int val){
put(root, key, val, 0);
}

int get(string &key){
TrieNode *t = get(root, key, 0);
if(t) return t->val;
else return -1;
}

void remove(string &key){
remove(root, key, 0);
}
private:
TrieNode *root;

void remove(TrieNode *&root, string &key, int d){
if(!root) return;
if(key.length() == d) root->val = -1;

int k = key[d]-'a';
remove(root->link[k], key, d+1);

if(isEmptyNode(root->link[k])){
if(root->link[k]) delete root->link[k];
root->link[k] = nullptr;
return;
}
}

bool isEmptyNode(TrieNode *root){
if(!root) return true;
if(root->val != -1) return false;

for(int i = 0; i < N; i++){
if(root->link[i]) return false;
}

return true;
}

void put(TrieNode *&root, string &key, int val, int d){
if(!root) root = new TrieNode;

if(key.length() == d){
root->val = val;
return;
}

int k = key[d]-'a';
put(root->link[k], key, val, d+1);
}

TrieNode *get(TrieNode *root, string &key, int d){
if(!root) return nullptr;
if(d == key.length()) return root;
int k = key[d]-'a';
return get(root->link[k], key, d+1);
}
};
avatar
l*i
25
facebook hackcup round1 has a trie problem so you can see the world's first
class programmer's implementation.
avatar
y*e
26
要不要这么拼。。。。一流选手的代码俺怎么看的懂。。。

first

【在 l***i 的大作中提到】
: facebook hackcup round1 has a trie problem so you can see the world's first
: class programmer's implementation.

avatar
s*x
27
其实就是tree,只是多了一个flag标志,表示这是一个end,表示suffix的终结
avatar
C*r
28

espeically
what should be the right way then?

【在 r*****b 的大作中提到】
: It is not a good idea to use trie to implement auto-completeion, espeically
: at the facebook scale. Trie consumes a lot of memory, and the pionter-
: jumping will lead to a lot of cache miss, and significantly slow down the
: cpu.

avatar
y*e
29
我自己发的帖子耶。。。。
avatar
J*o
30

楼主怎么感叹起自己发帖来了。。。

【在 y*****e 的大作中提到】
: 我自己发的帖子耶。。。。
avatar
w*e
31
这lc上不是有吗
avatar
j*l
32
现在你可以自己回答自己问题了
avatar
j*3
33
mark
avatar
c*n
34
你能不能把原题paste 出来, 这样如果题目不清楚,胡乱做完全是走火入魔

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
p*3
35

波妹,又换id了?

【在 y*****e 的大作中提到】
: 先是看到一个facebook的题,说是implement search autocompletion,用trie。
: 然后又看到一题implement getWords(), 和hasPrefix()
: 我在网上找了好久,没看到比较完整的实现,大概思路两个,一个是用array或
: Linkedlist把children连起来,另一个是用hashmap连起来。。。
: 第一个思路大概是这样的
: https://community.oracle.com/thread/2070706
: 但这个实现的也不严谨。。。
: 没办法,我把在角落里吃灰的clrs拿出来,竟然没有找到trie的implementation!!
: 我还以为这书就是百科全书呢。。。。不知有没有哪位大侠愿意分享一下到底怎么写比
: 较严谨完整呢?

avatar
k*e
36
mark
avatar
h*b
37
mark
刚做了lc新题,每个node里面加了children的hashmap(用于快速决定放弃继续向下搜
索)和arraylist(用于储存重复的children),结果TLE了
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。