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 3998116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:29:08+00:00 2026-05-20T07:29:08+00:00

So as an exercise, I’m building an algorithm to make searching for words (arbitrary

  • 0

So as an exercise, I’m building an algorithm to make searching for words (arbitrary sets of characters) within larger strings as fast as possible. With almost no previous knowledge of existing search algorithms, my approach so far has been the following:

  1. Map out occurrences of pairs of characters within the larger string (Pair -> List of positions).
  2. For each pair, store also the number of occurrences found within the larger string.
  3. Get all character pairs within the search word.
  4. Using the gotten pair that occurs least often in the string, check at each position for the remaining characters of the search term for a match.

That’s the gist of it. I suppose I could use maps with longer characters, but for now I’m just using pairs.

Is there much else I can do to make it faster? Am I approaching this the right way?

  • 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-05-20T07:29:09+00:00Added an answer on May 20, 2026 at 7:29 am

    String-search is a heavily researched topic:

    http://en.wikipedia.org/wiki/String_searching_algorithm

    You are thinking about finding e.g. 2 consecutive characters and storing the frequency of that combination, this is a very expensive operation even if you use balancing datastructures. I dont really see how storing consecutive characters as a preprocessing-step would help you.

    So, there are obviously many many algorithms for string-search. What i find interesting is, that there are some algorithms that dont even need to scan every character in the body-of-text. Example: if you search for the word ‘abbbbbc’ and you find the character ‘d’ as the next character of the body-of-text you can immediately jump ahead 5 characters without the need to even look what they are, then if the next character is a ‘b’ or ‘c’ you obviously have to go back and look if you made a mistake in jumping, but if not then you skipped over 5 characters with no need for comparison. This is difficult to implement however and leads to the theory of finite automata.

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

Sidebar

Related Questions

As a learning exercise I'm building a basic scientific computation environment based on .NET.
Exercise: There's too much repetition in this file. Use strings, formats, and escapes to
Trying to do exercise 1.16 (iterative version of fast-exp) in Structure and Interpretation of
The exercise says Make a function with parameters two int arrays and k which
As a practice exercise at my college we have to make a simple room
As a learning exercise, I am creating a program that converts characters entered through
This is an academical exercise (disclaimer). I'm building an application that will profit from
How do I exercise an action to ensure it redirects to the correct action
This is an exercise for the CS guys to shine with the theory. Imagine
As an exercise for myself, I was translating a sample program into various languages.

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.