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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:20:12+00:00 2026-05-18T01:20:12+00:00

I have asked the same question before, but did not get what I want.

  • 0

I have asked the same question before, but did not get what I want. So have to post it again.

I have a very long string which does not have any space within it. Now I am trying to search for repeated substring (any type, no specific pattern) in this long string. The length of the repeat could be a range between (min, max), i.e (min = 3. max = 5).

For example:
String s = “atggucttuaccccggucttaacccc”;
in which “gguctt” and “acccc” are the two different repeated substrings (I do not know this before I run the code).

So I am wandering, in C#, is there any fast way to determine the repeats and the position where the repeats occur?

Thanks in advance.

  • 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-18T01:20:12+00:00Added an answer on May 18, 2026 at 1:20 am

    You are essentially looking to search the string for a substring, but the substrings are composed of every possible substring in the string.

    I would begin by iterating through chunk lengths, from 2 (or whatever the smallest match should be), to half the string’s length (a string longer than half the strings length couldn’t be repeated).

    For each chunk size, I would iterate through the string taking chunks of the appropriate size and using a string matching algorithm like Boyer-Moore (or the built in string searching algorithm) to see if the string is repeated. Note that it is only necessary to search the remainder of the string, if there were a repeat earlier in the string, it would have been matched what that region was the chunk. You can also limit the search region to eliminate the last (chunk_size – 1) chars in the string, as a match couldn’t possibly begin after there (although your string searching algo might do this for you). I would also maintain a hashtable of all of the already checked chunks to avoid having to check them again, this would be particularly important for the first few iterations where the chunk size is small.

    In pseudocode:

    match_min = 2
    match_max = 5
    
    search_cache = Hashtable()
    for (chunk_size = match_min; chunk_size < min(match_max+1, len(str)/2); chunk_size++){
      for (start = 0; start < len(str) - chunk_size; start++){
        sub = str.substring(start, start + chunk_size)
        // We want to know if sub repeats
        if (sub not in search_cache)
          search_cache[sub] = str.substring(start + chunk_size, len(str) - chunk_size + 1).find(sub)
        if (search_cache[sub] != -1)
          print "MATCH FOUND %s at %d-%d" % (sub, start, search_cache[sub])
      }
    }
    

    This will only find one match for each chunk (and some chunks will appear to match themselves), but could be easily modified to find all matches (just make the find function return all matches, and modify how the print statement works).

    The efficiency of this would be roughly O(c*m*n) where c is a constant representing the efficiency of your string searching algo (the amortized cost of doing a string search), m is the size of the string, and n is (max – min). It is also a function of the amount of repetition in the string, as if the entropy is low, the search_cache would save you more time. Approximating c as O(n) makes the function roughly O(n^2).

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

Sidebar

Related Questions

I asked the almost the same question before also, but i have not yet
May be it's the same question i have i asked before but the issue
I have asked a similar question before, but I didn't have a firm grasp
I have asked this question before - but I have spent some time thinking
I've asked the same question before for Flex, but due to some restrictions, I'm
I have asked (and answered) a very similar question before. That question was able
I've asked a question about this class before, but here is one again. I've
I've asked a similar question before, but I've done some more research and this
OK, I had asked a similar question before and had got an answer but
This is a continuation question from a previous question I have asked I now

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.