You have now built a naive pattern search, congratulations!

The algorithm begins by iterating through the text and setting a variable match_count equal to 0.

Then, for each index of the text, the algorithm iterates through the pattern to check for matching characters, and if found, increments match_count. Otherwise, the search breaks the pattern iteration and moves onto the next index in text.

Each time the pattern iteration is completed, the match_count is compared to the length of the pattern to determine if a match is found.

Now there is only one thing left to do, test the algorithm on more inputs!


Some additional texts and patterns have been added to the code. Invoke pattern_search with text2 and pattern2, text3 and pattern3, and text4 and pattern4. Observe your amazing algorithm handle everything thrown at it!

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?