HarshCasper / NeoAlgo

Bringing all Data Structures and Algorithms under one Roof âš¡
MIT License
876 stars 1.05k forks source link

Implementation of Brute force string search algorithm #509

Closed prasadvpatil closed 4 years ago

prasadvpatil commented 4 years ago

🚀 Feature

Align the pattern against the first m characters of the text and start matching the corresponding pairs of characters from left to right until either all m pairs of characters match or a mismatching pair is encountered. In the latter case, shift the pattern one position to the right and resume character comparisons, starting again with the first character of the pattern and its counterpart in the text.

Have you read the Contributing Guidelines on Pull Requests?

Yes

Motivation

Its one of the easy method to implement string search. Helps for beginners to learn and implement basic codes first.

Pitch

We can implement according to the below algorithm.

Brute_Force_String_Match (T[0…n-1], P[0…m-1]) // Implements brute force string match // Input:- An array T[0…n-1] of n characters representing a text and an array P[0…m-1] of m characters representing a pattern // Output:- The index of the first character in the text that starts a matching substring or -1 if the search is unsuccessful

for i from 0 to n-m do
       j = 0
      while j < m and P[ j ] = T [ i + j ] do
            j = j + 1
      if j = m
           return i
return -1
prasadvpatil commented 4 years ago

I would like to work upon this in C @Kajol-Kumari @Abhijit2505 @SKAUL05 @plazzy99

Naman-1234 commented 4 years ago

i will do it in python3,Pls assign it to me.

Kajol-Kumari commented 4 years ago

Hey @prasadvpatil let's not go with the brute force algorithm for this as it's quiet naive! Maybe go for Rabin–Karp or Boyer–Moore string-search algorithm for this.

NitikaGupta16 commented 4 years ago

I will work upon it in C++ @Kajol-Kumari @SKAUL05

github-actions[bot] commented 4 years ago

Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Telegram or ping one of the reviewers. Thank you for your contributions!