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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:02:22+00:00 2026-05-25T12:02:22+00:00

I have been thinking over this problem for a few days now and am

  • 0

I have been thinking over this problem for a few days now and am hung up on calculating the number of times the second nested for-loop will run. I believe that I have the correct formula for determining the running time for the other two for-loops, but this third one has me hung up. I have the first loop running n-1 times. The equation to determine the number of times loop #2 runs is; The summation of 1 to n-1. If anyone could help me understand how to find the number of times loop #3 runs it would be greatly appreciated.

    for ( int i=1; i<=n-1; i++ ) {
        for ( int j=i+1; j<=n; j++ ) {
            for ( int k=1; k<=j; k++ ) {
            }
        }
    }
  • 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-05-25T12:02:22+00:00Added an answer on May 25, 2026 at 12:02 pm

    The third loop runs C times:

    C = Sum( Sum ( Sum ( 1 , k = 1 .. j ) , j = i+1 .. n ) , i = 1 .. n-1 )
      = Sum( Sum (           j            , j = i+1 .. n ) , i = 1 .. n-1 )
      = 2 + 3 + 4 + ... + n
          + 3 + 4 + ... + n
        ...
                        + n
      = 2*1 + 3*2 + 4*3 + 5*4 + ... + n*(n-1)
      = (1*1 + 1) + (2*2 + 2) + (3*3 + 3) + ... + ((n-1)*(n-1) + n-1)
      = (1^2 + 2^2 + ... (n-1)^2) + (1 + 2 + 3 + ... + (n-1))
      = (n-1)*n*(2*n-1)/6 + (n-1)*n/2 
      = (n-1)*n*(2*n+2)/6
      = O(n^3)
    

    Here I used the formulas:

    1^2 + 2^2 + ... + m^2 = m*(m+1)*(2*m+1)/6
    

    and

    1 + 2 + ... + m = m*(m+1)/2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been thinking the design over for a couple days now and I'm
This is probably a silly question but I have been thinking it over for
I've been thinking about the number of projects we have in-house that are still
I have a question that may have been answered over 9000 times before but
Have been getting pretty bald over this situation! I am using MS VS 2010
Good morning I have been running a few tests over the past couple of
So I've been stewing over this for a long time, thinking about it. Here's
I have been thinking quite a bit here lately about screen scraping and what
I have been thinking of maybe writing a little tool that logs into SO
I have been thinking of starting a site of my own for long time.

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.