Brute Force Pattern 

Brute force pattern matching algorithm is one of the simplest and straightforward methods for finding occurrences of a pattern within a text. It works by systematically comparing the pattern with all possible substrings of the text to determine if a match exists.

Here's a step-by-step explanation of the Brute force pattern matching algorithm:

The Brute force algorithm has a time complexity of O(n * m), where n is the length of the text and m is the length of the pattern. In the worst-case scenario, where there are no matches, it would require comparing all possible substrings, resulting in a time complexity of O(n^2).

While the Brute force algorithm is simple to understand and implement, it may not be efficient for large texts or patterns. Therefore, more advanced pattern matching algorithms, such as Knuth-Morris-Pratt (KMP) or Boyer-Moore, are often preferred for practical applications due to their improved efficiency.

Brute force pattern matching algorithm in Python

Here's an implementation of the Brute force pattern matching algorithm in Python:

def brute_force_pattern_matching(text, pattern):

    n = len(text)

    m = len(pattern)  

    matches = []    

    for i in range(n - m + 1):

        j = 0

        while j < m and text[i + j] == pattern[j]:

            j += 1

        if j == m:

            matches.append(i)   

    return matches

# Example usage:

text = "ABCABDABABCABCD"

pattern = "AB"

result = brute_force_pattern_matching(text, pattern)

print("Pattern matches found at positions:", result)