Week 10
Prefix free codes
题目
In data compression, a set of binary strings is if no string is a prefix of another. For example, {01,10,0010,1111} is prefix free, but {01,10,0010,10100} is not because 10 is a prefix of 10100. Design an efficient algorithm to determine if a set of binary strings is prefix-free. The running time of your algorithm should be proportional the number of bits in all of the binary stings.
分析
实际上时间复杂度就是要不超过 c N W cNW cNW,因此可以用这周学的前缀树
对前缀树,因为只有两位,相当于一个2路前缀树,只要向树中不断插入值,只要在插入过程中遇到既有键,就说明拥有公共前缀。
Boggle
题目
Boggle is a word game played on an 4 4 4-by- 4 4 4 grid of tiles, where each tile contains one letter in the alphabet. The goal is to find all words in the dictionary that can be made by following a path of adjacent tiles (with no tile repeated), where two tiles are adjacent if they are horizontal, vertical, or diagonal neighbors.
分析
使用一个前缀树来维护词典中的单词,对方格进行深度遍历
Suffix trees
问题
Learn about and implement , the ultimate string searching data structure.
分析
官方承认这个是非常难的,因此放弃