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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:04:03+00:00 2026-06-06T16:04:03+00:00

When you have code: for(int i = 0; i<N; i++) { array[i] += N

  • 0

When you have code:

for(int i = 0; i<N; i++)
{
   array[i] += N
}

Isn’t it comparing the variable i and N every time the loop iterates. For that matter isn’t it adding 1 to i every time the loop iterates as well?

So, isn’t this 3 operations per iteration of the loop?

Why do we usually ignore these operations and say that this code is O(n) ? Does it have something to do with how these operations are using the CPU?

  • 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-06T16:04:05+00:00Added an answer on June 6, 2026 at 4:04 pm

    Big-O notation does not deal with the actual cost of the operation, but how that cost grows with the size of the problem. To that extent, O(n) does not mean that the cost is n, but that the cost grows linearly with the size of the problem. Whatever the cost is for 100 elements, it will be doubled for 200 and tenfold for 1000. In the same way O(n^2) means that the cost grows quadratically, so if the size of the problem doubles the cost of the operation quadruples, if the size increases tenfold, the cost grows hundred-fold.

    Constants don’t really matter here and they are usually factored out. More over, in many analysis the cost is not even expressed on actual time or memory cost, but the cost of other operations. For example, the std::map::find function is said to have O( log N ), regardless of the key type. The reason is exactly the same: O( log N ) means that whatever the cost of finding in a map with N elements is, it will grow logarithmically.

    For a motivating example, consider a rather absurd problem: finding the author of a book from the full book contents, and two implementations. In the first implementation you use a std::map<std::string, std::string> where the first std::string is the contents of the book and the second the name of the author. The second implementation performs hashing of the contents of the book into an integer and stores that into an unordered std::vector< std::pair<int, std::string> >, the int being the hash and the std::string being the author’s name (assume no hash collisions). The cost of finding the author of the book in the map is O( log N ) and the cost of finding the author in the vector is O( N ), which is worse. But, those costs are hiding the complexity of the comparisons, the cost of comparing the whole book contents in the map might be huge compared to the cost of comparing the hash, up to the point that a single comparison of the contents of a book might be more expensive than all of the comparisons needed in the vector case.

    Big-O notation deals only with how the cost grows with the size of the problem and hides the actual cost of each operation. When analyzing the complexity of an algorithm, the individual costs are ignored, but you should still be aware of them, as the Big-O notation does not tell the whole story and the practical cost of running your algorithm will incur in those constant costs that you ignored in the analysis.

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

Sidebar

Related Questions

I have the following code: int sec = 62; string str = string.Format(Time: {0:xxx},
I have two questions regarding array: First one is regarding following code: int a[30];
I have next code: int main() { OwnSelect(23, FD_READ | FD_WRITE); // <---- Several
I have this code: int se = (int) settings.GruppoSegreteria; var acc = db.USR_Accounts.Where( p
I have the following code: int width = 10; int height = 7; bool[,]
I have the following code: int i=1; printf((i==1)? : hello); printf( hello); And I
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
I have the following code int main() { int a=6; void *p; p=&a; p++;
I have the code: unsigned int length = strlen(somestring); I'm compiling with the warning
I have the following code: int i = 5000; Console.WriteLine(waiting + i + miliseconds);

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.