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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:18:33+00:00 2026-05-11T10:18:33+00:00

I’m trying to figure out how to give a worst case time complexity. I’m

  • 0

I’m trying to figure out how to give a worst case time complexity. I’m not sure about my analysis. I have read nested for loops big O is n^2; is this correct for a for loop with a while loop inside?

// A is an array of real numbers. // The size of A is n. i,j are of type int, key is // of type real.  Procedure IS(A)     for j = 2 to length[A]      {                    key = A[ j ]                   i = j-1       while i>0 and A[i]>key        {              A[i+1] = A[i]                                i=i-1                        }                    A[i+1] = key       } 

so far I have:

j=2 (+1 op)    i>0 (+n ops)    A[i] > key (+n ops)  so T(n) = 2n+1?   

But I’m not sure if I have to go inside of the while and for loops to analyze a worse case time complexity…

Now I have to prove that it is tightly bound, that is Big theta.

I’ve read that nested for loops have Big O of n^2. Is this also true for Big Theta? If not how would I go about finding Big Theta?!

**C1= C sub 1, C2= C sub 2, and no= n naught all are elements of positive real numbers

To find the T(n) I looked at the values of j and looked at how many times the while loop executed:

values of J:   2, 3, 4, ... n   Loop executes: 1, 2, 3, ... n 

Analysis:
Take the summation of the while loop executions and recognize that it is (n(n+1))/2 I will assign this as my T(n) and prove it is tightly bounded by n^2. That is n(n+1)/2= θ(n^2)

Scratch Work:

Find C1, C2, no є R+ such that 0 ≤ C1(n^2) ≤ (n(n+1))/2 ≤ C2(n^2)for all n ≥ no  To make 0 ≤ C1(n) true, C1, no, can be any positive reals    To make C1(n^2) ≤ (n(n+1))/2, C1 must be ≤ 1   To make (n(n+1))/2 ≤ C2(n^2), C2 must be ≥ 1   

PF:

Find C1, C2, no є R+ such that 0 ≤ C1(n^2) ≤ (n(n+1))/2 ≤ C2(n^2) for all n ≥ no Let C1= 1/2, C2= 1 and no = 1.   
  1. show that 0 ≤ C1(n^2) is true C1(n^2)= n^2/2
    n^2/2≥ no^2/2
    ⇒no^2/2≥ 0
    1/2 > 0
    Therefore C1(n^2) ≥ 0 is proven true!

  2. show that C1(n^2) ≤ (n(n+1))/2 is true C1(n^2) ≤ (n(n+1))/2
    n^2/2 ≤ (n(n+1))/2 n^2 ≤ n(n+1)
    n^2 ≤ n^2+n
    0 ≤ n

    This we know is true since n ≥ no = 1
    Therefore C1(n^2) ≤ (n(n+1))/2 is proven true!

  3. Show that (n(n+1))/2 ≤ C2(n^2) is true (n(n+1))/2 ≤ C2(n^2)
    (n+1)/2 ≤ C2(n)
    n+1 ≤ 2 C2(n)
    n+1 ≤ 2(n)
    1 ≤ 2n-n
    1 ≤ n(2-1) = n
    1≤ n
    Also, we know this to be true since n ≥ no = 1

    Hence by 1, 2 and 3, θ(n^2 )= (n(n+1))/2 is true since
    0 ≤ C1(n^2) ≤ (n(n+1))/2 ≤ C2(n^2) for all n ≥ no

Tell me what you thing guys… I’m trying to understand this material and would like y’alls input!

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T10:18:34+00:00Added an answer on May 11, 2026 at 10:18 am

    You seem to be implementing the insertion sort algorithm, which Wikipedia claims is O(N2).

    Generally, you break down components based off your variable N rather than your constant C when dealing with Big-O. In your case, all you need to do is look at the loops.

    Your two loops are (worse cases):

    for j=2 to length[A]     i=j-1     while i > 0         /*action*/         i=i-1 

    The outer loop is O(N), because it directly relates to the number of elements.

    Notice how your inner loop depends on the progress of the outer loop. That means that (ignoring off-by-one issues) the inner and outer loops are related as follows:

      j's     inner value    loops -----    -----   2        1   3        2   4        3   N       N-1 -----    ----- total    (N-1)*N/2 

    So the total number of times that /*action*/ is encountered is (N2 – N)/2, which is O(N2).

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

Sidebar

Ask A Question

Stats

  • Questions 254k
  • Answers 254k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is one of those issues that once I understood… May 13, 2026 at 10:05 am
  • Editorial Team
    Editorial Team added an answer You can't rely on for (v in someObject) ... to… May 13, 2026 at 10:05 am
  • Editorial Team
    Editorial Team added an answer What about something like: Action<PersistenceSpecification<Entry>> testAction = pspec => pspec… May 13, 2026 at 10:05 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.