Skip to content

Category Archives: Pattern Searching

Given an input text and an array of k words, arr[], find all occurrences of all words in the input text. Let n be the… Read More
Background Suffix Array : A suffix array is a sorted array of all suffixes of a given string. Let the given string be “banana”. 0… Read More
Given a 2D grid of characters and a word, find all occurrences of the given word in the grid. A word can be matched in… Read More
This algorithm finds all occurrences of a pattern in a text in linear time. Let length of text be n and of pattern be m,… Read More
Given a stream of characters (characters are received one by one), write a function that prints ‘Yes’ if a character makes the complete string palindrome,… Read More
Given a string, find the longest substring which is palindrome. We have already discussed Naïve [O(n3)], quadratic [O(n2)] and linear [O(n)] approaches in Set 1,… Read More
In Manacher’s Algorithm Part 1 and Part 2, we gone through some of the basics, understood LPS length array and how to calculate it efficiently… Read More
In Manacher’s Algorithm Part 1 and Part 2, we gone through some of the basics, understood LPS length array and how to calculate it efficiently… Read More
In Manacher’s Algorithm – Part 1, we gone through some of the basics and LPS length array. Here we will see how to calculate LPS… Read More
Given a string, find the longest substring which is palindrome.  if the given string is “forgeeksskeegfor”, the output should be “geeksskeeg” if the given string… Read More
Given two strings X and Y, find the Longest Common Substring of X and Y. Naive [O(N*M2)] and Dynamic Programming [O(N*M)] approaches are already discussed… Read More
In earlier suffix tree articles, we created suffix tree for one string and then we queried that tree for substring check, searching all patterns, longest… Read More
Given a string, build it’s Suffix Array We have already discussed following two ways of building suffix array: Naive O(n2Logn) algorithm Enhanced O(nLogn) algorithm Please… Read More
Given a text string, find Longest Repeated Substring in the text. If there are more than one Longest Repeated Substrings, get any one of them.… Read More
Given a text string and a pattern string, find all occurrences of the pattern in string. Few pattern searching algorithms (KMP, Rabin-Karp, Naive Algorithm, Finite… Read More