Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:36:02+00:00 2026-06-05T02:36:02+00:00

If I have string A and I have many other strings and I want

  • 0

If I have string A and I have many other strings and I want to see if any of those other strings are in A.

What algorithm could do this in as few iterations possible?

Ex:

‘Hello, my name is Bob.’

And I want to see if ‘name is b’ is contained, which it is starting at [11].

I’m not looking to use a regular expression library.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:36:04+00:00Added an answer on June 5, 2026 at 2:36 am

    The most efficient algorithm for this is the Aho-Corasick algorithm, which given a string of length n and set of strings of total length m can find all matches in time O(n + m + z), where z is the total number of matches reported. It’s based on finite automata and is a generalization of the KMP string matching algorithm.

    One cool aspect of this algorithm is that if you have a fixed set of keywords and a bunch of text strings you want to search, then the algorithm can be sped up by doing O(m) preprocessing to build up the matcher. You can then find all matches in a string of length n in time O(n + z).

    If, on the other hand, you have a fixed string and then want to match a varying set of pattern strings against it, consider looking into suffix trees, which give the same runtime guarantees but are faster if the text is fixed.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big txt file ,with many strings ,say string-I-want-to-change,now I need to
I have many string and i put it in a list.All the strings have
Possible Duplicate: Non repeating random number array I have a String array with many
I want to find out how many lines a string will have when set
Possible Duplicate: Concatenate many rows into a single text string? I have a query
Now I have a string which has many substring like href=http://www.AAA.com and other characters,
I have tried many other questions on this site today but none of them
I have many to many relationship in entity framework. See image... I want to
I've got a class with many string arrays. I'd like to have one generic
I create a single mutable string object. Now I have released the object many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.