Practical No. 6 String Pattern Matching_ Implement Algorithms to Find a Pattern in a Given String
Practical No. 6 String Pattern Matching_ Implement Algorithms to Find a Pattern in a Given String
6
String Pattern Matching: Implement algorithms to find a pattern in a given string.
Input:
Text: "abracadabra"
Pattern: "abra"
Output:
Pattern found at indices: [0, 7]
Explanation:
Complexity:
● Time Complexity:
○ Worst Case: O(m⋅n)O(m \cdot n)O(m⋅n), where mmm is the
pattern length and nnn is the text length.
● Space Complexity:
○ O(1)O(1)O(1), as no extra space is used apart from the result list.
Practical Application: