由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 分别用LinkedList和HashMap构建字典树(Compact Trie)怎么做
相关主题
过去n小时的top searchleetcode 129
2-sum 用hash table实现的问题word ladder ii 谁给个大oj不超时的?
今天Amazon的phone interview菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。
几个Java面试题 (转载)Clone graph
Bloomberg面经(onsite)求帮忙看看这个clone graph的解法。弄半天还是不对。 多谢!
谁来解释下hashtable的iterator是怎么实现的面试题:Data structure to find top 10 search strings
An Old Question -- Top N Occurance Frequance急, 请教个面试问题
某家onsite面经Given an int array and an int value. Find all pairs in arr
相关话题的讨论汇总
话题: node话题: hashtable话题: trie话题: firstchild话题: label
进入JobHunting版参与讨论
1 (共1页)
S*******C
发帖数: 822
1
Input: WORD.LST
And a randomly picked 1000 words from the same WORD.LST for querying.
This is a list of > 100,000 English words. It is sorted alphabetically.
Your task is to create a Compact Trie. Each node of trie will contain,
(1) A leading character (possibly empty (for root))
(2) String Label (possibly null (for root))
(3) Boolean IsWord , indicating whether the current node represents a whole
word or not (this is helpful when one word may be a prefix of another).
(4) Node *RightSIbling
(5) Node *FirstChild
If a node stores "stock" as the label string then leading character should
be 's'
You will need a method for FindChild, which takes FirstChild and a character
c as input and searches for correct node by following RightSibling pointers
until it finds the node with c as its leading character.
How to create a Trie.
You can use repeated insertions: you'll need following insert method...
Input Trie T (as Node *root) , and a String newWord ;
First run a find method on newWord until it fails : it could fail in two
ways
(i) It fails in the middle of some label -- in this case split this nodes
label into two parts: make two child nodes of this node, one having the rest
of the label string, along with original node's FirstChild pointer, and
second child gets the remaining part of the original word as a new node.
Organize these two children as a sorted linked list. And make its leftmost
node as FirstChild pointer of original node.
(ii) it fails to find appropriate child while searching for leading
character, then simply insert a new Node at this point in the child list,
and put the remaining part of the word as label for this node.
----------------------------------------------------------------------------
---
Now the Hashing part, speed up FindChild operation by using a HashTable,
Use a chaining based global Hashtable. Use the number of lines N in WORD.LST
as the size of Hashtable[N].
HashEntryNode will have following fields:
{Node *parent,
char c
Node *child
HashEntryNode *next
}
The Hashtable is an array of HashEntryNode* Hashtable[N] .
Hash function will take two values as an input Node *parent and char c and
calculate hash value between 0.. N-1.
1 (共1页)
进入JobHunting版参与讨论
相关主题
Given an int array and an int value. Find all pairs in arrBloomberg面经(onsite)
BB 一题谁来解释下hashtable的iterator是怎么实现的
find top K most occurring words in streaming data 这题怎么做比较好An Old Question -- Top N Occurance Frequance
也问一个算法题某家onsite面经
过去n小时的top searchleetcode 129
2-sum 用hash table实现的问题word ladder ii 谁给个大oj不超时的?
今天Amazon的phone interview菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。
几个Java面试题 (转载)Clone graph
相关话题的讨论汇总
话题: node话题: hashtable话题: trie话题: firstchild话题: label