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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:36:52+00:00 2026-06-06T14:36:52+00:00

I have forgotten stuff on how to compute time complexities of algorithms. I am

  • 0

I have forgotten stuff on how to compute time complexities of algorithms. I am not looking for a Book or 30 page blog to refresh that knowledge. Taking this below algorithm could you please correct in the way i compute the Time Complexity. Thanks

Linear Search

bool SeqSearch(int[] arr, int sValue) {
    for (int index = 0; index < arr.Length-1; index++)
    if (arr[index] == sValue)
        return true;
    return false;
}

Steps and Logic used

  1. Loop through all elements – N
  2. Comparison for each index – 1 or is it N
  3. Return true or false – 1

Finally

I forgot do we add these up or do we multiply them? I assumed we had to add so ended up with
N+N+1 so this must be a Big Oh! of N. O(N)

Questions

  1. Do i multiply the time taken for each steps or add them up
  2. For a comparison it is not possible to determine when it will end. So what is time taken ( i assumed 1 because it may be found at first index, N otherwise as last index)
  3. Assignments and Return are constant time 1 ?

note: Please Please do not refer me to a website. SO will stay long and people who have the same/similar question will certainly find the answer to this post useful. I can’t trust when the other website will be taken down etc. Also i am not bothered of efficiency, time complexity but the process/steps used to find it.

Resource

http://faculty.simpson.edu/lydia.sinapova/www/cmsc250/LN250_Weiss/L03-BigOh.pdf

I just wanted to put this link to pdf that explains clearly how to account for what statements and when. Just like i wanted.

  • 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-06T14:36:53+00:00Added an answer on June 6, 2026 at 2:36 pm

    Think in terms of primitive operations (memory accesses and arithmetic/logic operations).

    Count them for your algorithm given the size of the input, N (arr.Length in your case).

    Then see how that total number of operations relates to N, whether it’s just some constant or a polynomial of N (e.g. N3) or a logarithm of N or an exponent of N or something else.

    If it turns out something like N+1 or 2*N, you should neglect the small constant because you’re primarily concerned about what happens when N is large and about the overall behavior.

    That’s the basics.

    Here’s the approximate time complexity for the worst case (when sValue isn’t in arr[]):

    int index = 0; is 1

    index < arr.Length-1; is 1 (but could be up to, say, 10), repeated arr.Length times

    index++ is 1 (but could be up to, say, 3), repeated arr.Length times

    if (arr[index] == sValue) is 1 (but could be up to, say, 10), repeated arr.Length times

    return value; is 1

    So you have something like 1 + 1 * arr.Length + 1 * arr.Length + 1 * arr.Length = 1 + 3 * arr.Length + 1. You simplify that down to arr.Length, hence O(N).

    On average you’ll only have arr.Length / 2 iterations. Hence on average you have 1 + 1 * arr.Length / 2 + 1 * arr.Length / 2 + 1 * arr.Length / 2 + 1 = 2 + 1.5 * arr.Length. Again, O(N).

    But you should really read about this stuff.

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

Sidebar

Related Questions

I have forgotten the syntax for a generic method: public static void swap <T>
have written this little class, which generates a UUID every time an object of
Have a painfully simple blog Post creator, and I'm trying to check if the
have 2 questions : A computer with 32-bit address uses 2-level page table (9
really sorry about being totally thick today but I have forgotten how to do
I'm an intermittent programmer and seem to have forgotten a lot of basics recently.
We have a system that uses password authentication to access a database, the usernames
This may seem silly but I seem to have forgotten the order of replacement
I have observed some unexpected or at least not-perfectly-matching-my-needs behaviour of textboxes bound to
I am in the process of relearning Delphi as have not programmed much of

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.