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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:29:51+00:00 2026-05-22T23:29:51+00:00

I have read that : Searching for a substring, pat[1..m], in txt[1..n], can be

  • 0

I have read that :

Searching for a substring, pat[1..m], in txt[1..n], can be solved in O(m) time (after the suffix tree for txt has been built in O(n) time).

but at each point, we will have to choose which branch to take, so like in n-ary tree, at each node, we will have to compare with all max n pointers in that node to decide which branch to take. Will this not bring n factor in complexity of this algorithm, somehow in picture

Then how above it says that substring can be found in O(m)?

What am I missing here?

  • 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-22T23:29:52+00:00Added an answer on May 22, 2026 at 11:29 pm

    Then how above it says that substring can be found in O(m)?

    By omission. You are correct that the runtime of searching in suffix trees is more complex than merely O(m).

    However, it can indeed be sped up to O(m) if we trade off space requirements: we need to get the search at each node down to O(1) and we can do this by using an appropriate data structure (e.g. an array) which gives us the appropriate sub-tree for each letter in constant time.

    For instance, assume that you’re using C++ for the implementation and your character (char) can contain 256 different values. Then the implementation of a node could look as follows:

    struct node {
        char current_character;
        node* children[256];
    };
    

    Now, current_character refers to the character of the branch leading to the current node, and children is an array of child nodes. During the search, assume that you are currently at node u, and the next character in the input text is c. Then you will choose the next node as follows:

    node* next = u->children[c];
    if (next == 0) {
        // Child node does not exist => nothing found.
    }
    else {
        u = next;
        // Continue search with next …
    }
    

    Of course, this is only viable for very small alphabets (e.g. DNA for genomic sequences). In most common cases, the worst-case runtime of a suffix tree is indeed higher than O(m).

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

Sidebar

Related Questions

I have read that in Java interfaces can't be instantiated ( in the documentation,
I have read that you can do it, but would this really improve performance
I have read that LinkedHashMap has faster iteration speed than HashMap because its elements
I've been searching alot and I can't seem to find a solution. I have
I read that docs.jquery.com uses wiki to do the API documentation. I have been
I have read that using fulltext searching is faster then using LIKE %%. I
I have been searching all day for a solution to this and have read
I have read that GLSL (specifically v1.0.17: my application is running under WebGL) compilers
I have read that you should keep the number of connections in your database
I have read that for enabling the auto return I have to enable this

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.