{"id":28224196,"url":"https://github.com/danishayman/boyer-moore-string-matching","last_synced_at":"2025-06-20T03:34:37.883Z","repository":{"id":243389220,"uuid":"812296238","full_name":"danishayman/Boyer-Moore-String-Matching","owner":"danishayman","description":"This Java program implements the Boyer-Moore string matching algorithm using the Bad Character Heuristic.","archived":false,"fork":false,"pushed_at":"2025-04-08T14:28:15.000Z","size":169,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T09:11:31.546Z","etag":null,"topics":["algorithms","booyer-moore","booyer-moore-harspool","data-structures","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danishayman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-08T13:44:15.000Z","updated_at":"2025-04-09T00:48:27.000Z","dependencies_parsed_at":"2025-04-08T15:33:12.080Z","dependency_job_id":"1367f0b8-debb-4361-aa96-33e3952f28e0","html_url":"https://github.com/danishayman/Boyer-Moore-String-Matching","commit_stats":null,"previous_names":["danishayman/cpt212-asg2","danishayman/boyer-moore-string-matching"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/danishayman/Boyer-Moore-String-Matching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishayman%2FBoyer-Moore-String-Matching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishayman%2FBoyer-Moore-String-Matching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishayman%2FBoyer-Moore-String-Matching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishayman%2FBoyer-Moore-String-Matching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danishayman","download_url":"https://codeload.github.com/danishayman/Boyer-Moore-String-Matching/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishayman%2FBoyer-Moore-String-Matching/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259389502,"owners_count":22850020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","booyer-moore","booyer-moore-harspool","data-structures","java"],"created_at":"2025-05-18T09:11:10.831Z","updated_at":"2025-06-12T03:30:26.053Z","avatar_url":"https://github.com/danishayman.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔍 Boyer-Moore String Matching Algorithm in Java\n\nThis Java program implements the Boyer-Moore string matching algorithm using the Bad Character Heuristic. The Boyer-Moore algorithm is an efficient string-searching algorithm that skips sections of the text to reduce the number of comparisons needed.\n\n## 🚀 How It Works\n\n1. **Preprocessing the Pattern** 🛠️\n\n   - The `badCharHeuristic` function creates a table (`badchar[]`) that records the last occurrence of each character in the pattern.\n   - If a character in the text does not match the corresponding character in the pattern, the algorithm uses this table to determine how far to shift the pattern.\n\n2. **Searching the Text** 🔎\n\n   - The `search` function slides the pattern over the text from left to right.\n   - For each position, it compares the characters of the pattern with the corresponding characters in the text from right to left.\n   - If a mismatch occurs, it uses the `badchar` table to determine the next shift.\n   - If the pattern matches the current position in the text, it prints the position and continues to search for other occurrences.\n\n3. **Output** 📊\n   - The program prints the positions where the pattern is found in the text.\n   - If the pattern is not found, it prints a message indicating that the pattern is not in the text.\n\n## 💻 Code Structure\n\nThe implementation consists of several key components:\n\n- `NO_OF_CHARS`: A constant defining the number of possible characters (256)\n- `max()`: A utility function to get the maximum of two integers\n- `badCharHeuristic()`: Preprocesses the pattern to create the bad character table\n- `search()`: The main searching function implementing the Boyer-Moore algorithm\n- `main()`: The driver program with a sample test case\n\n## 🛠️ How to Run\n\n1. **Compile the program using a Java compiler:**\n   ```sh\n   javac BoyerMoore.java\n   ```\n\n2. **Run the compiled program:**\n   ```sh\n   java BoyerMoore\n   ```\n\n## 📝 Example\n\nFor the input text `\"Test. This is a test.\"` and pattern `\"test\"`, the output will be:\n\n```\nPattern found at position: 0\nPattern found at position: 15\n```\n\nIf you change the pattern to a string not present in the text, for example, `\"xyz\"`, the output will be:\n\n```\nPattern not found in the text.\n```\n\n## 🎯 Performance\n\nThe Boyer-Moore algorithm is known for its efficiency:\n- Best case: O(n/m) where n is the text length and m is the pattern length\n- Worst case: O(n*m)\n- Average case: O(n)\n\n## 🤝 Contributing\n\nFeel free to contribute to this project by:\n- Reporting issues 🐛\n- Suggesting improvements 💡\n- Submitting pull requests 🔄\n\n## 📜 License\n\nThis project is open source and available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanishayman%2Fboyer-moore-string-matching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanishayman%2Fboyer-moore-string-matching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanishayman%2Fboyer-moore-string-matching/lists"}