Perform an “average case” time complexity analysis for Insertion-Sort, using the given proposition
and definition. I have broken this task into parts, to make it easier.
Definition 1. Given an array A of length n, we define an inversion of A to be an ordered pair (i, j) such
that 1 ≤ i < j ≤ n but A[i] > A[j].
Example: The array [3, 1, 2, 5, 4] has three inversions, (1, 2), (1, 3), and (4, 5). Note that we refer to an
inversion by its indices, not by its values!
Proposition 2. Insertion-Sort runs in O(n + X) time, where X is the number of inversions.
(a) Explain why Proposition 2 is true by referring to the pseudocode given in the lecture/textbook.
(b) Show that E[X] = 1
4n(n − 1). Hint: for each pair (i, j) with 1 ≤ i < j ≤ n, define a random indicator
variable that is equal to 1 if (i, j) is an inversion, and 0 otherwise.
(c) Use Proposition 2 and (b) to determine how long Insertion-Sort takes in the average case.

Answers

Answer 1

a. Proposition 2 states that Insertion-Sort runs in O(n + X) time, where X is the number of inversions.

b. The expected number of inversions, E[X],  E[X] = 1/4n(n-1).

c. In the average case, Insertion-Sort has a time complexity of approximately O(1/4n²).

How to calculate the information

(a) Proposition 2 states that Insertion-Sort runs in O(n + X) time, where X is the number of inversions. To understand why this is true, let's refer to the pseudocode for Insertion-Sort:

InsertionSort(A):

  for i from 1 to length[A] do

     key = A[i]

     j = i - 1

     while j >= 0 and A[j] > key do

        A[j + 1] = A[j]

        j = j - 1

     A[j + 1] = key

b. The expected number of inversions, E[X], can be calculated as follows:

E[X] = Σ(i,j) E[I(i, j)]

= Σ(i,j) Pr((i, j) is an inversion)

= Σ(i,j) 1/2

= (n(n-1)/2) * 1/2

= n(n-1)/4

Hence, E[X] = 1/4n(n-1).

(c) Using Proposition 2 and the result from part (b), we can determine the average case time complexity of Insertion-Sort. The average case time complexity is given by O(n + E[X]).

Substituting the value of E[X] from part (b):

Average case time complexity = O(n + 1/4n(n-1))

Simplifying further:

Average case time complexity = O(n + 1/4n^2 - 1/4n)

Since 1/4n² dominates the other term, we can approximate the average case time complexity as:

Average case time complexity ≈ O(1/4n²)

Therefore, in the average case, Insertion-Sort has a time complexity of approximately O(1/4n²).

Learn more about proposition on

https://brainly.com/question/30389551


Related Questions

Other Questions
The following reactions (note that the arrows are pointing only one direction) can be used to prepare an activity series for the halogens:Br2(aq)+2NaI(aq)2NaBr(aq)+I2(aq)Cl2(aq)+2NaBr(aq)2NaCl(aq)+Br2(aq)A) Predict whether a reaction will occur when elemental chlorine and potassium bromide are mixed.Express your answer as a chemical equation.B)Predict whether a reaction will occur when elemental iodine and lithium chloride are mixed.Express your answer as a chemical equation. What study type usually has at least two groups with one group receiving an ""intervention"" and the other group receiving a ""placebo""?. a nurse researcher develops a research proposal. which components would be found in an abstract? (select all that apply.) According to forbes, what carl barks creation is the richest character in all of fiction?. You are given the following information: Boston Equity Mutual Fund Total assets $ 760 million Total liabilities $ 5 million Total number of shares 20 million Calculate the net asset value for the Boston Equity mutual fund. Suppose Ernie gives up his job as financial advisor for P.E.T.S., at which he earned $30,000 per year, to open up a store selling spot remover to Dalmatians. He invested $10,000 in the store, which had been in savings earning 5 percent interest. This year's revenues in the new business were $50,000, and explicit costs were $10,000. Calculate Ernie's economic profit Factory reset iphone without passcode or itunes or computer. Gump (2005) studied 300 undergraduates and found a correlation of -0.60 between the number of absences and grades. Write an explanation of what this means so that someone unfamiliar with correlations could understand it. how much energy is transported across a 1.25 cm2 area per hour by an em wave whose e field has an rms strength of 36.8 mv/m ? the wave travels in free space. express your answer using three significant figures. According to the COSO Fraudulent Financial Reporting 1998- 2007 update: A.CEO's and CFO's were named by the SEC for involvement in approximately a car's horn produces a sound wave of constant frequency. as the car speeds up going away from a stationary spectator, the sound wave detected by the spectator Why is cinco de mayo significant to all americans?. An order is placed to buy 100 shares at $61.55. The company then declares a cash dividend of 30 cents per share. What will the order price be adjusted to, before the open on the ex-dividend date? The F. Repens Corporation has taxable income of $250,000 for the current year, including dividends of $60,000 received from 10-percent-owned domestic corporations. How much is the F. Repens Corporation's dividends received deduction for the current year The three major phases of the marketing plan are: Planning, implementation, and control. Calculate the escape speed for a spacecraft from the surface of (a) Mars; and from the surface of (b) Jupiter. ( The escape speed for an object at the surface of Earth is 11.2 km/s )a) velocity of Mars in km/sb) velocity of jupiter in km/sc) Why is the escape speed for a spacecraft independent of the spacecraft's mass? If the pain is sharp, stabbing or dull, using the 1995 & 1997 guidelines, what is the component of the History of Present Illness (HPI)? D Medical Aid 1.1.3 The life domain 'Becoming' entails the following main areas of life: A. Physical, Psychological and Spiritual B. Practical, Leisure and Growth C. Physical, Social and Community D. Being, Becoming and Belonging 1.1.4 The following is an example of non-formal learning. A. An hour long talk on HIV prevention at the local clinic. B. One year Grade 10 NCS at a public school. C. A week-long accredited First Aid course. D. A one day basic course in computer skills at the workplace. 1.1.5 One of the following is NOT a characteristic of most adolescents. A. Not interested in the opposite sex. B. Feel unsure about themselves. C.have mood swings, ranging from happy to sad. D. Questions beliefs and values of adults for what time interval (in minutes) does the exam last as measured by an observer on earth? time is one of the physicians most valuable assets. time is one of the physicians most valuable assets. false true