Skip to content

Improve Boyer-Moore String Search (Bad Character Rule) Implementation - #13039

Open
itspavant wants to merge 1 commit into
TheAlgorithms:masterfrom
itspavant:improve-boyer-moore
Open

Improve Boyer-Moore String Search (Bad Character Rule) Implementation#13039
itspavant wants to merge 1 commit into
TheAlgorithms:masterfrom
itspavant:improve-boyer-moore

Conversation

@itspavant

Copy link
Copy Markdown

Describe your change:

  • Fix a bug or typo in an existing algorithm
  • Add or change doctests
  • Documentation change

This PR improves the Boyer-Moore string search (bad-character rule) implementation:

  • Added a functional API boyer_moore_search(text, pattern) alongside the class wrapper for compatibility.
  • Precomputed a bad-character table for O(1) lookup per mismatch.
  • Corrected shifting logic with a while-loop (avoiding overwriting i).
  • Handled edge cases (empty text, empty pattern, pattern longer than text).
  • Allowed overlapping matches.
  • Expanded doctests to include typical and edge cases.
  • Preserved BoyerMooreSearch class for backward compatibility.
  • Improved documentation and clarity.

As per guidelines, no issue was raised before this PR since algorithm contributions should go directly as PRs.
This contribution is part of Hacktoberfest 2025 🎉


Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, separate algorithms would be separate PRs.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 1, 2025
@itspavant

Copy link
Copy Markdown
Author

Dear Maintainers,

Kindly please review the PR and let me know, if you need any more modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant