# Category Archives: Pattern Searching

## Frequency of a substring in a stringNovember 21, 2017

Given a input string and a substring. Find the frequency of occurrences of substring in given string. Examples: Input : man (pattern) dhimanman (string) Output… Read More »

## Count of occurrences of a “1(0+)1” pattern in a stringJuly 31, 2017

Given an alphanumeric string, find the number of times a pattern 1(0+)1 occurs in the given string. Here, (0+) signifies the presence of non empty… Read More »

## Find all the patterns of “1(0+)1” in a given string | SET 2(Regular Expression Approach)July 3, 2017

In Set 1, we have discussed general approach for counting the patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0’s.In… Read More »

## Find all the patterns of “1(0+)1” in a given string | SET 1(General Approach)June 27, 2017

A string contains patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0’s. Count all such patterns. The patterns are allowed… Read More »

## Boyer Moore Algorithm | Good Suffix heuristicJune 21, 2017

We have already discussed Bad character heuristic variation of Boyer Moore algorithm. In this article we will discuss Good Suffix heuristic for pattern searching. Just… Read More »

## is_permutation() in C++ and its application for anagram searchJune 4, 2017

is_permutations() is used to check if two containers like string and vector are permutation of each other. It accepts three parameters, the first two parameters… Read More »

## Match Expression where a single special character in pattern can match one or more charactersMay 27, 2017

Given two string, in which one is pattern (Pattern) and other is searching expression. Searching expression contains ‘#’. The # works in following way: A… Read More »

## Maximum length prefix of one string that occurs as subsequence in anotherMay 11, 2017

Given two strings s and t. The task is to find maximum length of some prefix of the string S which occur in string t… Read More »

## Replace all occurrences of string AB with C without using extra spaceMarch 22, 2017

Given a string str that may contain one more occurrences of “AB”. Replace all occurrences of “AB” with “C” in str. Examples: Input : str… Read More »

## Wildcard Pattern MatchingJune 12, 2016

Given a text and a wildcard pattern, implement wildcard pattern matching algorithm that finds if wildcard pattern is matched with text. The matching should cover… Read More »

## Find all occurrences of a given word in a matrixMay 13, 2016

Given a 2D grid of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8… Read More »

## Aho-Corasick Algorithm for Pattern SearchingFebruary 29, 2016

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 »

## ­­kasai’s Algorithm for Construction of LCP array from Suffix ArrayFebruary 23, 2016

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 »

## Search a Word in a 2D Grid of charactersNovember 19, 2015

Given a 2D grid of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8… Read More »

## Z algorithm (Linear time pattern searching Algorithm)July 26, 2015

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 »