Generation

generate functionMon, 03 Apr 2023

BoyerMoore algorithm to find all exact occurrences of a pattern pat[1 . . . m] in any given text txt[1 . . . n]. In this exercise, we will allow the pattern pat[1 . . . m] to contain at most 1 wildcard character. Here we will use dot (·) to represent this wildcard. Besides potentially one wildcard (·) in the pattern, all other characters in the pattern and all characters of the text are drawn from the 26-letter lowercase English alphabet. What purpose does the wildcard serve? The wildcard character dot (·) in the pattern can match any character in the alphabet. Your goal is to implement a version of the Boyer-Moore algorithm with all its shift rules and optimizations that can identify all occurrences in a given text of a given pattern (which can contain at most 1 wildcard (dot) in it). text = bbbbbababbbbbabb pattern = bb.bb, the output should be (all positions below are 1-indexed): 1 9 12

Example: text = bbbbbababbbbbabb pattern = bb.bb

Questions about programming?Chat with your personal AI assistant