Coders Packet

Efficient String searching using C++

By Shaik Jafar

This project gives the positions in the string ( input by the user ) at which a pattern string ( input by the user ) is matched, using C++ programming language.

In this project, the user is asked to input two strings (a string and a pattern to be searched ).

Then the output will be the number of positions at which the given pattern is matched in the string followed by the 0 based indices or positions as space seperated integers.

Note:This is implemented using C++ PROGRAMMING LANGUAGE.

This implementation is supposed to be the most efficient as it tracks the given pattern string in linear time.


1 <= |P| <= |T| <= 10^5

Sample input:

Enter the Main string


Enter the pattern string to be searched


Sample output:

There are 3 matched strings !!

At the indices(0 based) 0 9 12


Here, the pattern AABA occured at postions 0,9,12 in the string AABAACAADAABAABA.

Download Complete Code


No comments yet