The bad_character_heuristic() reassigned the for-loop variable i
inside the loop body, which has no effect on iteration in Python.
As a result the bad-character shift was dead code and the search
degenerated into brute-force O(n*m) checking every position,
while still claiming O(n/m) in the module docstring.
Convert the loop to a while loop so the shift actually applies,
guaranteeing at least one position of progress per iteration via
max(i + 1, mismatch_index - match_index).
Verified: all doctests pass, 2000 randomized comparisons against
brute-force search pass, and the example from the issue now takes
9 iterations instead of 29.
Fixes TheAlgorithms#14844
Describe your change:
In strings/boyer_moore_search.py, bad_character_heuristic() reassigned the for-loop variable i inside the loop body:
In Python, reassigning the loop variable does not change the iteration, so the bad-character shift was dead code. The search checked every position sequentially — brute-force O(n·m) — while the module docstring advertises Boyer-Moore O(n/m).
Fix: convert the loop to a while loop so the shift actually applies, using i = max(i + 1, mismatch_index - match_index) to guarantee forward progress (the max also covers the case where the mismatched character is absent from the pattern, where match_index == -1 makes the raw difference negative or a no-op shift).
Verification:
Fixes #14844