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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:01:26+00:00 2026-06-12T18:01:26+00:00

for (int i = 0; i < n; i++ ) { for (int j

  • 0
for (int i = 0; i < n; i++ ) {
    for (int j = 0; j < n; j++ {
        Simple Statement
    }
}
for (int k = 0; i < n; k++ {
    Simple Statement
    Simple Statement
    Simple Statement
    Simple Statement
    Simple Statement
}
    Simple Statement*25

For the nested loop, I find a time complexity of 1 (for int i = 0) + n + 1 (for i < n) + n (for i++) * [ 1 (for int j = 0 ) + 1 + n ( for j < n) + n ( for j++) ] + n (for the simple statement). This is (1+n+1+n)(1+1+n+n)+n = (2 + 2n)(2+2n)+n = 4n^2 + 9n + 4.

For the following loop, I find a time complexity of 1 (for int k = 0) + n + 1 (for i < n) + n (for k++) + 5n (for the five simple statements). This is 1+n+1+n+5n = 7n+2. For the next 25 simple statements, I find they have a time complexity of 25.

So the total time complexity is 4n^2 + 8n + 4 + 5n + 2 + 25 = 4n^2 + 16n + 31, however, my book says the time complexity is n^2 + 5n + 25.

What have I done wrong?

Edit: It is now apparent that the book is telling the time complexity of only the simple statements. I suppose now my question is this (as it was in the title): What is the time complexity of the algorithm?

  • 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-12T18:01:27+00:00Added an answer on June 12, 2026 at 6:01 pm

    Your book is counting only the number of SimpleStatements executed.

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

Sidebar

Related Questions

I have this simple piece of code : int a = 1, b =
I have the following simple class class base { public: int x; base &set(int
This should be relatively simple. What I have: int progress; // iteration we are
I am doing very simple int division and I am getting odd results. This
I have a simple 2D array: int[,] m = { {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} }; How
I have a simple function: void licz() { int result = 0; for (int
I've got the following simple code: @for (int j = 0; j < file.Items.Count;
how call TRACE in c++?please explain for example with this simple code int x
I'm having trouble finding a simple statement to skip the duplicates for this recursive
I have a simple SQL statement that is to get the first rowid from

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.