Skip to content

[OTHER] #7442

Description

@wdlpazlmj

What would you like to share?

What would you like to Propose?

Add an implementation of the Aho-Corasick string matching algorithm.

Problem statement: Given a text and a list of patterns, find all occurrences of all patterns in the text efficiently. This algorithm is useful when multiple keywords need to be searched in a single pass.

Issue details

The implementation can be added under the string/search-related package and should include unit tests.

Expected behavior examples:

Input:

  • text: ahishers
  • patterns: ["he", "she", "his", "hers"]

Expected matches:

  • his at index 1
  • she at index 3
  • he at index 4
  • hers at index 4

Suggested implementation details:

  • Build a trie from all patterns.
  • Compute failure links using BFS.
  • Traverse the input text once and report matched patterns.
  • Expected time complexity: O(n + m + z), where n is the text length, m is the total length of all patterns, and z is the number of matches.
  • Expected space complexity: O(m).

Additional Information

This would be a useful addition for educational coverage of multi-pattern string matching algorithms.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions