B*******1 发帖数: 2454 | 1 careercup上面看到的
Design a site similar to tinyurl.com
就是把一个很长很长的link压缩成一个短的
譬如
http://www.mitbbs.com/mitbbs_bbsedit.php?brdname=JobHunting&
title=%CE%CA%B8%F6google%C3%E6%CA%D4%CC%E2&author=Bayesian1&
file=M.1309911387_2.E0&id=31906283&gid=31906283
压缩成
http://tinyurl.com/3lgxxho
这个用hash还是trie啊?
thanks |
s*****n 发帖数: 5488 | 2 any reason for trie?
1-1 map, then redirect should be enough.
【在 B*******1 的大作中提到】 : careercup上面看到的 : Design a site similar to tinyurl.com : 就是把一个很长很长的link压缩成一个短的 : 譬如 : http://www.mitbbs.com/mitbbs_bbsedit.php?brdname=JobHunting& : title=%CE%CA%B8%F6google%C3%E6%CA%D4%CC%E2&author=Bayesian1& : file=M.1309911387_2.E0&id=31906283&gid=31906283 : 压缩成 : http://tinyurl.com/3lgxxho : 这个用hash还是trie啊?
|
B*******1 发帖数: 2454 | 3 主要是考虑空间复杂度
url很多很多的时候,trie是不是会比hash省空间啊?
而且hash的collision机会也会大很多。
【在 s*****n 的大作中提到】 : any reason for trie? : 1-1 map, then redirect should be enough.
|
s*****n 发帖数: 5488 | 4 I think by good design you don't need hash at all. simply increse the code
by one for a new link. than compute the index of long url by decoding the
cookie.
【在 B*******1 的大作中提到】 : 主要是考虑空间复杂度 : url很多很多的时候,trie是不是会比hash省空间啊? : 而且hash的collision机会也会大很多。
|
t**r 发帖数: 3428 | |