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

  • Home
  • SEARCH
  • 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 760297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:42:01+00:00 2026-05-14T15:42:01+00:00

What is the complexity of the algorithm is that is used to find the

  • 0

What is the complexity of the algorithm is that is used to find the smallest snippet that contains all the search key words?

  • 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-14T15:42:02+00:00Added an answer on May 14, 2026 at 3:42 pm

    As stated, the problem is solved by a rather simple algorithm:

    Just look through the input text sequentially from the very beginning and check each word: whether it is in the search key or not. If the word is in the key, add it to the end of the structure that we will call The Current Block. The Current Block is just a linear sequence of words, each word accompanied by a position at which it was found in the text. The Current Block must maintain the following Property: the very first word in The Current Block must be present in The Current Block once and only once. If you add the new word to the end of The Current Block, and the above property becomes violated, you have to remove the very first word from the block. This process is called normalization of The Current Block. Normalization is a potentially iterative process, since once you remove the very first word from the block, the new first word might also violate The Property, so you’ll have to remove it as well. And so on.

    So, basically The Current Block is a FIFO sequence: the new words arrive at the right end, and get removed by normalization process from the left end.

    All you have to do to solve the problem is look through the text, maintain The Current Block, normalizing it when necessary so that it satisfies The Property. The shortest block with all the keywords in it you ever build is the answer to the problem.

    For example, consider the text

    CxxxAxxxBxxAxxCxBAxxxC

    with keywords A, B and C. Looking through the text you’ll build the following sequence of blocks

    C
    CA
    CAB - all words, length 9 (CxxxAxxxB...)
    CABA - all words, length 12 (CxxxAxxxBxxA...)
    CABAC - violates The Property, remove first C
    ABAC - violates The Property, remove first A
    BAC - all words, length 7 (...BxxAxxC...)
    BACB - violates The Property, remove first B
    ACB - all words, length 6 (...AxxCxB...)
    ACBA - violates The Property, remove first A
    CBA - all words, length 4 (...CxBA...)
    CBAC - violates The Property, remove first C
    BAC - all words, length 6 (...BAxxxC)
    

    The best block we built has length 4, which is the answer in this case

    CxxxAxxxBxxAxx CxBA xxxC

    The exact complexity of this algorithm depends on the input, since it dictates how many iterations the normalization process will make, but ignoring the normalization the complexity would trivially be O(N * log M), where N is the number of words in the text and M is the number of keywords, and O(log M) is the complexity of checking whether the current word belongs to the keyword set.

    Now, having said that, I have to admit that I suspect that this might not be what you need. Since you mentioned Google in the caption, it might be that the statement of the problem you gave in your post is not complete. Maybe in your case the text is indexed? (With indexing the above algorithm is still applicable, just becomes more efficient). Maybe there’s some tricky database that describes the text and allows for a more efficient solution (like without looking through the entire text)? I can only guess and you are not saying…

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

Sidebar

Related Questions

In researching complexity for any algorithm that traverses a binary search tree, I see
Can you suggest an algorithm that find all pairs of nodes in a link
Could you please help me find out the time complexity of the Fleury' algorithm
Since some time, I'm using an algorithm that runs in complexity O(V + E)
I'm solving some problem that involves Rabin–Karp string search algorithm. This algorithm requires rolling
I wonder what's the algorithm of make_heap in in C++ such that the complexity
From Wikipedia: The complexity of the algorithm is O(n(logn)(loglogn)) bit operations. How do you
Our system complexity has risen to the point that we need to make permission
Find out the time complexity (Big Oh Bound) of the recurrence T(n) = T(⌊n⌋)
A term that I see every now and then is Cyclomatic Complexity. Here on

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.