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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:32:24+00:00 2026-06-14T15:32:24+00:00

Got a question on this step count problem. I think I have the basic

  • 0

Got a question on this step count problem. I think I have the basic idea but struggling to get the math straight on paper. First the pseudo code:

for i = 1 to n
    x = x + 1
    j = n
    while (j>1)
        j = j/2

and my interpretation:

n/2 + 1

n/2

n/2

n/2 <– top part of summation for line 4 (the while loop)

Σ logn+2

i=1 <– bottom part of summation for line 4 (the while loop)

n/2 <– top part of summation for line 5 (body of the while loop)

Σ logn+1

i=1 <– bottom part of summation for line 5 (body of the while loop)


So the first three lines in step count aren’t bad to see, but then the two summations inside the loop are a bit tricky to me. So for the first one logn + 2 I can split into two steps:

n/2

Σ 2

i=1

and

n/2

Σ logn

i=1

so I’m used to dealing with straight summation of n, not n/2. But I’ll give it a quick shot.

2*((n^2+n)/2) or rather just drop the fraction for this one so it’s straight: n^2+n.

Then for the logn piece:

logn*((n^2+n)/2) = ? Now I’m not really sure here. Not sure this even simplifies down at all. If anyone has any suggestions on this I’d appreciate it, but I think what I got there is it for this half. So I combine the two together to get my final answer for the first summation line 4 of the pseudo code:

logn * (n^2+n)/2 + n^2 + n

And for the second summation I think it would then be:

logn * n^2 + n

(can borrow a bit from what I had already completed above. Just dropped the part where I had 2 * (n^2+n)/2 and instead I’ll simply have two sets of the half which combine to make one n^2+n if that makes any sense I think?

Please let me know if I’ve totally lost it. Thank you!!

  • 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-14T15:32:25+00:00Added an answer on June 14, 2026 at 3:32 pm

    I think you’re analysis is a bit off. First, notice that what happens in the body of the for loop is independent of the value of i or x. So the for loop executes n times and the same number of steps happen in the for loop body each time. The body of the while loop executes floor(log2(n)) times. That’s about all the analysis that’s needed. The result is n*floor(log2(n)). (If by “step” you mean statement executions, you need to modify this a bit to account for the number of statements in each loop body.)

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

Sidebar

Related Questions

I got this question in a programming test. Do you think this question is
Today I got this question for which I think I answered very bad. I
I just got this question on an interview and had no idea how to
This is a follow-up on my previous question . Once I got the problem
I have a very similar question to this question , but I am still
I got this question from my cousin: What will be the best way to
This question got me thinking about bare strings. When PHP sees a string that's
This question got me thinking about the max_size method in vector class. It is
So I got this question in data structures class' homework, I'm translating so I
I got a few question about this IDE. First, when boot up vs2010, it

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.