Tag: suffix tree

找到Python最长重复字符串的有效方法(From Programming Pearls)

摘自编程珍珠第15.2节 可在此处查看C代码: http : //www.cs.bell-labs.com/cm/cs/pearls/longdup.c 当我使用suffix-array在Python中实现它时: example = open(“iliad10.txt”).read() def comlen(p, q): i = 0 for x in zip(p, q): if x[0] == x[1]: i += 1 else: break return i suffix_list = [] example_len = len(example) idx = list(range(example_len)) idx.sort(cmp = lambda a, b: cmp(example[a:], example[b:])) #VERY VERY SLOW max_len = -1 for i […]