Here is a suffix tree implementation that is reasonably efficient. I did not study the implementation of Ukkonen, but the running time of this algorithm, in my opinion, is quite reasonable, approximately O(N Log N) . Note that the number of internal nodes in the created tree is equal to the number of letters in the parent row.
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using NUnit.Framework; namespace FunStuff { public class SuffixTree { public class Node { public int Index = -1; public Dictionary<char, Node> Children = new Dictionary<char, Node>(); } public Node Root = new Node(); public String Text; public void InsertSuffix(string s, int from) { var cur = Root; for (int i = from; i < s.Length; ++i) { var c = s[i]; if (!cur.Children.ContainsKey(c)) { var n = new Node() {Index = from}; cur.Children.Add(c, n);
cdiggins Sep 13 '13 at 13:47 on 2013-09-13 13:47
source share