由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求问一道算法题~
相关主题
F电面求教一道关于string的Google面试题~~
aababccbc remove abc面试题:根据输入字符串,返回正则表达式
贡献一道电话面试题问个经典题目,感觉没错啊,可是过不了OJ,超时了,请大神帮着
问个题?一个基本的string问题
上一道题给你们休息休息C++ Q66: reverse a string -- is it efficient
问一个facebook的电面贡献一道G家的面试题
做题做得很郁闷,求指点Google 2 phone interviews exposed + 求祝福
find first diff of 2 strings菜鸟的问题:Given a string, find whether it has any permutation of another string
相关话题的讨论汇总
话题: str1话题: str2话题: string话题: strings话题: overlap
进入JobHunting版参与讨论
1 (共1页)
c**********x
发帖数: 32
1
Question:
There are 1000 distinct strings, each string is composed by the chars in{‘a
','b','c','d'}. And each string.Length()==30;
here's a function aims at calculating the overlap of two different strings;
int overlapNumber(string str1, string str2){...}
overlapNumber is the length of largest prefix of str2 which is contained by
str1(Not necessary the surfix of str1)
and what I want is to calculate all the overlapNumbers between every two
strings within this string sets.
Notice: overlap(str1,str2) is sometimes not equal to overlap(str2,str1).
=========================================================================
My Solution:
My solution is somehow straightforward:
I change a little bit of the KMP string match algorithm and calculate every
two strings within this sets.
This takes O(n^2)
=========================================================================
Any Da Shen has a better solution?
I'm thinking of using tries...will it help?
Thanks!
c**********x
发帖数: 32
2
新人球罩,召唤大神,
c**********x
发帖数: 32
3
补充:
这题的优化只能在两两string的求overlap上面优化吗?有没有什么方法可以在整个
string set上面优化神马的?
z****s
发帖数: 409
4
想了一会没想出来。。。不过你这数据也太没诱惑力了,已经能1000^2*60做出来了,
实在没动力想了。
x*****a
发帖数: 9
5
优化overlapNumber+整体.
给每一个str做他的suffix tree. 然后就正常搜
s**********e
发帖数: 326
6

我也觉得应该是这样优化。

【在 x*****a 的大作中提到】
: 优化overlapNumber+整体.
: 给每一个str做他的suffix tree. 然后就正常搜

g*********e
发帖数: 14401
7
为什么你的solution只有n2时间?每对str的kmp运算不止常数时间吧?

‘a
by

【在 c**********x 的大作中提到】
: Question:
: There are 1000 distinct strings, each string is composed by the chars in{‘a
: ','b','c','d'}. And each string.Length()==30;
: here's a function aims at calculating the overlap of two different strings;
: int overlapNumber(string str1, string str2){...}
: overlapNumber is the length of largest prefix of str2 which is contained by
: str1(Not necessary the surfix of str1)
: and what I want is to calculate all the overlapNumbers between every two
: strings within this string sets.
: Notice: overlap(str1,str2) is sometimes not equal to overlap(str2,str1).

c**********x
发帖数: 32
8

嗯 应该是n^2 * n

【在 g*********e 的大作中提到】
: 为什么你的solution只有n2时间?每对str的kmp运算不止常数时间吧?
:
: ‘a
: by

c**********x
发帖数: 32
9

错了。。
是 n^2 * length

【在 g*********e 的大作中提到】
: 为什么你的solution只有n2时间?每对str的kmp运算不止常数时间吧?
:
: ‘a
: by

c**********x
发帖数: 32
10

弱弱的问一句,suffix tree怎么写啊?看了一晚上了。。。

【在 x*****a 的大作中提到】
: 优化overlapNumber+整体.
: 给每一个str做他的suffix tree. 然后就正常搜

C******w
发帖数: 23
11
用个简单的dp可以求得str1 str2的overlap,复杂度是O(length)
1 (共1页)
进入JobHunting版参与讨论
相关主题
菜鸟的问题:Given a string, find whether it has any permutation of another string上一道题给你们休息休息
readLine和balanceParanthesis的code谁写了?问一个facebook的电面
求问一道G家Onsite题做题做得很郁闷,求指点
onsite遇到的几个面试题find first diff of 2 strings
F电面求教一道关于string的Google面试题~~
aababccbc remove abc面试题:根据输入字符串,返回正则表达式
贡献一道电话面试题问个经典题目,感觉没错啊,可是过不了OJ,超时了,请大神帮着
问个题?一个基本的string问题
相关话题的讨论汇总
话题: str1话题: str2话题: string话题: strings话题: overlap