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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:58:31+00:00 2026-06-10T17:58:31+00:00

I would like to know whether this works in worst case as Θ(n+m) ?

  • 0
  1. I would like to know whether this works in worst case as Θ(n+m)?

n is size of i_StringForSearch, m is size of i_SubStringToFind.

2.Is there any program which is recommended to check time complexity of a given code, I prefer a free tool which is well recognized.

Thank you

public static boolean isSubstring(String i_StringForSearch, String i_SubStringToFind)
    {
        int strForSearchIndex = 0;
        int subStrToFindIndex = 0;
        boolean endOfStringToSearch = false;
        boolean foundSubString = false;
        boolean isThereASequenceOfMatching = false;


        while(!endOfStringToSearch && !foundSubString)
        {
            if(strForSearchIndex == i_StringForSearch.length())
            {
                endOfStringToSearch = true;
            }

            else if(i_StringForSearch.charAt(strForSearchIndex) == i_SubStringToFind.charAt(subStrToFindIndex))
            {
                isThereASequenceOfMatching = true;
                if(subStrToFindIndex == i_SubStringToFind.length() -1 )
                {
                    foundSubString = true;
                }
                subStrToFindIndex++;
                strForSearchIndex++;
            }

            else if(i_StringForSearch.charAt(strForSearchIndex) != i_SubStringToFind.charAt(subStrToFindIndex))
            {
                if(isThereASequenceOfMatching)
                {
                    subStrToFindIndex = 0;
                    isThereASequenceOfMatching = false;
                }
                strForSearchIndex++;
            }
        }

       return foundSubString;
    }
  • 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-10T17:58:32+00:00Added an answer on June 10, 2026 at 5:58 pm
    1. Answering your question: yes, the algorithm is O(n+m). Each
      iteration increases strForSearchIndex, so there are at most n
      iterations. [this is assuming i_StringForSearch.length() is done
      in O(1), which is usually true].

    2. The algorithm is wrong with the counter example of isSubstring("aaab","aab") == false.

    3. You might want to have a look on Knuth Morris Pratt algorithm and/or Rabin-Karp algorithm and/or Aho-Corasick Algorithm

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

Sidebar

Related Questions

I would like to know whether this is actually possible in Android? When Android
I would like to know how css works under the hood. Whether the html
I would like to know whether strace can cause anomaly for the program it
i would like to know whether the following query is optimized? select SUM(payments.paid_amt) as
I would like to know whether I could perform a full outer join between
I am developing a walkie-talkie application for Android, and would like to know whether
I would like to do the following. I don't know whether it's possible to
I would like to know, wether Server.Transfer will work in a Web Farm. Thanking
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at

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.