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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:31:31+00:00 2026-06-05T19:31:31+00:00

I have gone through Google and Stack Overflow search, but nowhere I was able

  • 0

I have gone through Google and Stack Overflow search, but nowhere I was able to find a clear and straightforward explanation for how to calculate time complexity.

What do I know already?

Say for code as simple as the one below:

char h = 'y'; // This will be executed 1 time
int abc = 0; // This will be executed 1 time

Say for a loop like the one below:

for (int i = 0; i < N; i++) {
    Console.Write('Hello, World!!');
}
  • int i=0; This will be executed only once.

The time is actually calculated to i=0 and not the declaration.

  • i < N; This will be executed N+1 times
  • i++ This will be executed N times

So the number of operations required by this loop are {1+(N+1)+N} = 2N+2. (But this still may be wrong, as I am not confident about my understanding.)

OK, so these small basic calculations I think I know, but in most cases I have seen the time complexity as O(N), O(n^2), O(log n), O(n!), and many others.

  • 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-05T19:31:33+00:00Added an answer on June 5, 2026 at 7:31 pm

    How to find time complexity of an algorithm

    You add up how many machine instructions it will execute as a function of the size of its input, and then simplify the expression to the largest (when N is very large) term and can include any simplifying constant factor.

    For example, lets see how we simplify 2N + 2 machine instructions to describe this as just O(N).

    Why do we remove the two 2s ?

    We are interested in the performance of the algorithm as N becomes large.

    Consider the two terms 2N and 2.

    What is the relative influence of these two terms as N becomes large? Suppose N is a million.

    Then the first term is 2 million and the second term is only 2.

    For this reason, we drop all but the largest terms for large N.

    So, now we have gone from 2N + 2 to 2N.

    Traditionally, we are only interested in performance up to constant factors.

    This means that we don’t really care if there is some constant multiple of difference in performance when N is large. The unit of 2N is not well-defined in the first place anyway. So we can multiply or divide by a constant factor to get to the simplest expression.

    So 2N becomes just N.

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

Sidebar

Related Questions

I've gone through all of the solutions I could find on Stack Overflow and
I have gone through https://developers.google.com/+/api/#calls but couldn't figured out the way to post on
I've have gone through stackoverflow for days and googled a lot but can still
I want to fetch google images against any query. I have gone through the
Have gone through hibernate api specification on FlushMode but didn't get the exact difference.
I have gone through this and this , but the question I am asking
I have gone through the google documentations for Oauth and AuthSub methods for authenticating
I have gone through certain related answers but dont seem to get correct answer
I've gone through Google and Stackoverflow and have yet to resolve my issue with
I have gone through various articles, but I still do not know why instanceof

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.