# Naive Pattern Matching Algorithm C Program

## C Program For Naive Pattern Matching Algorithm

Learn how to implement the Naive Pattern Matching Algorithm in C Programming Language using Functions and For Loop. The pattern matching algorithm is also known as String Searching Algorithm.

#### What is Pattern Matching Algorithm?

The Naive String Matching Algorithm is one of the most simplest method to check whether a string follows a particular pattern or not. It is simple of all the algorithm but is highly inefficient. It checks where the string matches with the input pattern one by one with every character of the string.

The complexity of the Naive String Search Algorithm for average case scenario is O(n +m) whereas for worst case scenario is O(nm).

The following Naive String Search program takes a string from the user and then a pattern that user wants to find in the string. If the pattern is found in the string, it will display the position where the pattern matched in the string.

There are many other algorithms primarily developed for pattern matching or string matching requirements. Some of them are as follows:

1. Boyer Moore Search Algorithm
2. Rabin Karp String Search Algorithm
3. Two Way String Matching Algorithm
4. Backward Non-Deterministic Dawg Matching Algorithm
5. Finite State Automation Algorithm
6. Knuth Morris Prat Algorithm

Must Read: C Program To Find Permutations of a String using Recursion

#### Method 1: C Program For Naive Pattern Matching Algorithm using For Loop

Must Read: C Program To Find Longest Common Subsequence

#### Method 2: C Program For Naive String Matching Algorithm using Function

Must Read: C Program To Compare Two Strings

#### Output

Enter a String: CodingAlpha
Enter a Pattern to Match: in
Pattern Matched at Position: 3

If you have any compilation error or doubts in this Naive Pattern Matching program in C language, let us know about it in the comment section below.

#### Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

### One thought on “Naive Pattern Matching Algorithm C Program”

• March 11, 2017 at 10:22 am