private void button6_Click(object sender, EventArgs e) { string input = this.textBox5.Text; string pattern = this.textBox4.Text; //// string[] words = input.Trim().Split(' ', ',', ';', '.'); //SuffixArray sa1 = SuffixArray.Build(input); KarthicSuffixArray sa = new KarthicSuffixArray(input); List <string> matchedsuffix = sa.SearchPattern(pattern, sa.SourceString, sa.SuffixArray); //var str = input; //var sa1 = SuffixArray.Build(str); //string pat = pattern; //List<string> suffixes = new List<string>(); //sa1 = sa1.Search(pat); // int count = 0; // foreach (var pos in sa1) // { // count++; // suffixes.Add(input.Substring(pos)); // } // this.textBox6.Text = count.ToString(); this.textBox6.Text = matchedsuffix.Count.ToString(); }
private void button3_Click(object sender, EventArgs e) { string input1 = this.textBox8.Text; string input2 = this.textBox7.Text; // - Concatenate S1 and S2. //- Compute the suffix array. //- Compute the LCP of all adjacent suffixes. //the maximum LCP(i,i+1) is the required answer. //LongestCommonSubstring(input1, input2, out output); //http://algs4.cs.princeton.edu/63suffix/LongestCommonSubstring.java.html //update: if u think with eg..u will get this KarthicSuffixArray array = new KarthicSuffixArray(); string output = array.FindLongestCommonSubstring(input1, input2); this.textBox9.Text = output; }
private void button1_Click(object sender, EventArgs e) { string input = this.textBox3.Text; //string forward = input; //char[] chars = input.ToCharArray(); //Array.Reverse(chars); //string reverse = new string(chars, 0, chars.Length); //string palindromecheck = forward + "#" + reverse; //KarthicSuffixArray sa = new KarthicSuffixArray(input, true); //create two suffix tree.. //eg: Banana //forward suffix tree with chars and end with $ suffix1 =b,a,n,a,n,a, $ //revese the chars and make another tree and end with # suffix1= a,n,a,n,a ,b, # //For every suffix i in Sf, find the lowest common ancestor with the suffix n - i + 1 in Sr. //find the longest common substring of this string and its reverse. //string output = sa.LongestPanlindrome; //try 2 KarthicSuffixArray sa = new KarthicSuffixArray(); string reverse = Reverse(input); //f*****g success..logic is //reverse the given word //concat giveword + '#' + reveser //and then find the longest common substring this.textBox1.Text = sa.FindLongestCommonSubstring(input, reverse);; //Building the suffix tree takes \Theta(N) time (if the size of the alphabet is constant). //If the tree is traversed from the bottom up with a bit vector telling which strings are seen below each node, the k-common substring problem can be solved in \Theta(NK) time. If the suffix tree is prepared for constant time lowest common ancestor retrieval, it can be solved in \Theta(N) time.[1] }