由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 面试的时候用到Trie,要求实现吗?
相关主题
FB面试题一道 求解suffix tree 和 trie
String list如何排序攒人品,分享Pinterest面经
design search engine typeahead的问题发一个fb面经
最近好几个trie的面试题,有人愿意分享一下trie到底怎么implement的吗?google 电面fast phone book loopup
一道关于trie的题目问一道面试设计题
Google onsite 题目求助G家电面面经--佛云了~~
请教一道面试题Permutation leetcode-
一道题问个google老题的最佳解法
相关话题的讨论汇总
话题: node话题: key话题: trie话题: string话题: value
进入JobHunting版参与讨论
1 (共1页)
r*******n
发帖数: 3020
1
我面试还没遇到过用到Trie的题目。
J****3
发帖数: 427
2
遇到过写个trie结构 大概说了说解决的问题
j*******t
发帖数: 223
3
sedgewick的书里有讲过很简单的trie。
public class TrieST {
private static final int R = 256; // extended ASCII
private Node root = new Node();
private static class Node {
private Object val;
private Node[] next = new Node[R];
}
public boolean contains(String key) {
return get(key) != null;
}
public Value get(String key) {
Node x = get(root, key, 0);
if (x == null) {
return null;
}
return (Value) x.val;
}
private Node get(Node x, String key, int d) {
if (x == null) {
return null;
}
if (d == key.length()) return x;
char c = key.charAt(d);
return get(x.next[c], key, d+1);
}
public void put(String key, Value val) {
root = put(root, key, val, 0);
}
private Node put(Node x, String key, Value val, int d) {
if (x == null) {
x = new Node();
}
if (d == key.length()) {
x.val = val;
return x;
}
char c = key.charAt(d);
x.next[c] = put(x.next[c], key, val, d+1);
return x;
}
}
s********u
发帖数: 1109
4
我觉得,在实际使用中,可以就写个node,就是自带一个bool值,一个char值,和一个
vector。其他的函数,可以写成global或者solution类里面。否则你既要写
node,还要写trie类。
比如boggle game那个题,明显就是不用trie自己的search比较好,因为每次只需要
search一个char就行了。用trie自己的,就要search一个string。
struct TrieNode {
char mContent;
bool mMarker;
vector mChildren;
Node(char *c) { mContent = c; mMarker = false; }
};
f**********s
发帖数: 115
5
我好几次需要写比较复杂的结构,都是一个劲找话说,说到没时间写了,也就不用写了
。。。有挂过,也有pass过,有点靠运气呵呵
r*******n
发帖数: 3020
6
我面试还没遇到过用到Trie的题目。
J****3
发帖数: 427
7
遇到过写个trie结构 大概说了说解决的问题
j*******t
发帖数: 223
8
sedgewick的书里有讲过很简单的trie。
public class TrieST {
private static final int R = 256; // extended ASCII
private Node root = new Node();
private static class Node {
private Object val;
private Node[] next = new Node[R];
}
public boolean contains(String key) {
return get(key) != null;
}
public Value get(String key) {
Node x = get(root, key, 0);
if (x == null) {
return null;
}
return (Value) x.val;
}
private Node get(Node x, String key, int d) {
if (x == null) {
return null;
}
if (d == key.length()) return x;
char c = key.charAt(d);
return get(x.next[c], key, d+1);
}
public void put(String key, Value val) {
root = put(root, key, val, 0);
}
private Node put(Node x, String key, Value val, int d) {
if (x == null) {
x = new Node();
}
if (d == key.length()) {
x.val = val;
return x;
}
char c = key.charAt(d);
x.next[c] = put(x.next[c], key, val, d+1);
return x;
}
}
s********u
发帖数: 1109
9
我觉得,在实际使用中,可以就写个node,就是自带一个bool值,一个char值,和一个
vector。其他的函数,可以写成global或者solution类里面。否则你既要写
node,还要写trie类。
比如boggle game那个题,明显就是不用trie自己的search比较好,因为每次只需要
search一个char就行了。用trie自己的,就要search一个string。
struct TrieNode {
char mContent;
bool mMarker;
vector mChildren;
Node(char *c) { mContent = c; mMarker = false; }
};
f**********s
发帖数: 115
10
我好几次需要写比较复杂的结构,都是一个劲找话说,说到没时间写了,也就不用写了
。。。有挂过,也有pass过,有点靠运气呵呵
相关主题
Google onsite 题目求助suffix tree 和 trie
请教一道面试题攒人品,分享Pinterest面经
一道题发一个fb面经
进入JobHunting版参与讨论
c********p
发帖数: 1969
11
mark.
一直想弄明白这个到底怎么实现,一直没实现。。。拖了半年。
y******u
发帖数: 804
12
什么情况要用trie啊?
i******t
发帖数: 22541
13
word counts

【在 y******u 的大作中提到】
: 什么情况要用trie啊?
p*u
发帖数: 136
14
WORD PUZZLE
给一个n*n的matrix,每个格子有一个字母(a~z)。另外给一个词典,有m个单词。
求matrix上的出现的单词

【在 r*******n 的大作中提到】
: 我面试还没遇到过用到Trie的题目。
q****m
发帖数: 177
15
Node put(Node x, String key, Value val, int d) 里面的value 是什么用途?计数
吗?比如单词出现的次数?或者还要记录这个node对应的key?

【在 j*******t 的大作中提到】
: sedgewick的书里有讲过很简单的trie。
: public class TrieST {
: private static final int R = 256; // extended ASCII
: private Node root = new Node();
: private static class Node {
: private Object val;
: private Node[] next = new Node[R];
: }
: public boolean contains(String key) {
: return get(key) != null;

p*****2
发帖数: 21240
16
trie =
isword: false
add = (trie, word)->
if word.length is 0
trie.isword = true
else
ch = word[0]
trie[ch] = {isword:false} unless trie[ch]?
add(trie[ch], word[1..])

exists = (trie, word)->
return trie.isword if word.length is 0
ch = word[0]
trie[ch]? and exists trie[ch], word[1..]
x*****0
发帖数: 452
17
m
b****f
发帖数: 138
18
Mark
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个google老题的最佳解法一道关于trie的题目
GOOG intern interview 题目Google onsite 题目求助
一道MS题请教一道面试题
急问,Boggle (crossword)的解题思路?一道题
FB面试题一道 求解suffix tree 和 trie
String list如何排序攒人品,分享Pinterest面经
design search engine typeahead的问题发一个fb面经
最近好几个trie的面试题,有人愿意分享一下trie到底怎么implement的吗?google 电面fast phone book loopup
相关话题的讨论汇总
话题: node话题: key话题: trie话题: string话题: value