Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

If the outermost while loop of our implementation of inplace quick sort (line 7 of Code Fragment 12.6) were changed to use condition left < right (rather than left <= right), there would be a flaw. Explain the flaw and give a specific input sequence on which such an implementation fails.

Code Fragment 12.6:

1 def inplace quick sort(S, a, b):

2 """Sort the list from S[a] to S[b] inclusive using the quick-sort algorithm."""

3 if a >= b: return # range is trivially sorted

4 pivot = S[b] # last element of range is pivot

5 left = a # will scan rightward

6 right = b-1 # will scan leftward

7 while left <= right:

8 # scan until reaching value equal or larger than pivot (or right marker)

9 while left <= right and S[left] < pivot:

10 left += 1

11 # scan until reaching value equal or smaller than pivot (or left marker)

12 while left <= right and pivot < S[right]:

13 right -= 1

14 if left <= right: # scans did not strictly cross

15 S[left], S[right] = S[right], S[left] # swap values

16 left, right = left + 1, right - 1 # shrink range

17

18 # put pivot into its final place (currently marked by left index)

19 S[left], S[b] = S[b], S[left]

20 # make recursive calls

21 inplace quick sort(S, a, left - 1)

22 inplace quick sort(S, left + 1, b)

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93074799

Have any Question?


Related Questions in Computer Engineering

A different ethanol processing facility costs 800000 to

A different ethanol processing facility costs $800,000 to construct but will instead last forever. Every year (starting the year after  construction), it produces 10,000 barrels of ethanol and can charge a price of $4 pe ...

How do you apply the five components of the information

How do you apply the five components of the information systems to an information systems application like "online bill pay" system offered by many banks.

The marginal revenue and marginal cost functions for a

The marginal revenue and marginal cost functions for a monopolist firm that mines diamonds are given by:

4nbspthe appendix to chapter one will be very useful in

4. The appendix to chapter one will be very useful in answering this question, if you need a refresher or introduction to regression analysis. The following equation is the regression results of a study on infant mortali ...

Question suppose alice bob and carol want to use secret key

Question : Suppose alice, bob and carol want to use secret key technology to authenticate each other. If they all use the same key, K, then bob would impersonate carol to alice. suppose instead that each had their own se ...

Suppose the probability density function for a random

Suppose the probability density function for a random variable X equals the following:  f(x) = cx 3  for {0 (a) Solve for the value of "c" that makes this a valid pdf. (Hint: please refer to the two necessary conditions ...

The contracts manager at a company needs to make a large

The contracts manager at a company needs to make a large legal document available to an overseas customer. However, she has some challenges: The document contains sensitive information; it is too large to send via e-mail ...

Who stole the ice cream during an investigation into the

Who Stole the Ice Cream? ?During an investigation into the mysterious disappearance of ice-cream from a Mr. Softee truck, the following statements were made by the prime suspects. ? Alan: I wouldn't steal ice-cream unles ...

Access your browsers security settings and configure the

Access your browser's security settings and configure the browser to refuse all cookies or to prompt you before allowing a cookie. Restart the browser; then visit several different Web sites. Be sure to visit popular sit ...

Question what will be the source and destination ip

Question : What will be the source and destination IP addresses the response packet after the router forwards it to the private network? The response must be typed, single spaced, must be in times new roman font (size 12 ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As