BNDM Algorithm
Definition:
The BNDM (Backward Nondeterministic Dawg Matching) algorithm is an efficient string matching algorithm derived from the Backward Dawg Matching (BDM) algorithm. It uses bitwise operations to simulate a nondeterministic automaton, matching the pattern in reverse order while scanning the text.
Characteristics:
-
Bitwise Automaton Simulation:
- BNDM represents the search pattern as a bitmask and simulates a nondeterministic automaton using bitwise operations. This reduces the number of character comparisons and enables efficient pattern matching.
-
Reverse Pattern Matching:
- The algorithm scans the pattern in reverse, comparing it against the text from right to left, which helps in faster identification of mismatches and skips.
-
Efficient for Short Patterns:
- BNDM is particularly efficient for short patterns, often outperforming other string matching algorithms like Boyer-Moore and Knuth-Morris-Pratt for small pattern sizes.
-
Extension of BDM:
- It improves upon the BDM algorithm by handling more general cases and providing better performance for non-trivial patterns.
Time Complexity:
-
Best Case:
In the best-case scenario, wherewis the word size of the machine, the algorithm takes advantage of the word-level parallelism and makes few character comparisons. -
Average Case:
On average, BNDM performs linear scans through the text, making it highly efficient for typical use cases, especially with short patterns. -
Worst Case:
In the worst case, when the text and pattern have poor alignment, BNDM may require multiple full scans of the text, leading to quadratic complexity, wherenis the text length andmis the pattern length.