Explain the flaw and give a specific input sequence

Assignment Help Computer Engineering
Reference no: EM132087326

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)

Reference no: EM132087326

Questions Cloud

How is ld instruction converted in machine language : LC3 -Convert the above in machine language. How is LD instruction converted in machine language?
Identify the osi model default layer : The OSI model is a useful tool in troubleshooting a network because it enables you to isolate a problem to a particular software module or piece of hardware.
What is the final temperature of the mixture : What is the final temperature of the mixture? Assume that tea has the same thermal properties as water.
Mathematical definition of electrical power : Using the mathematical definition of electrical power help me show that the kilowatt-hour is a unit of energy.
Explain the flaw and give a specific input sequence : If the outermost while loop of our implementation of inplace quick sort were changed to use condition left
Determining the average acceleration : Calculate how much time it takes for the bus to slow down from 19.0 m/s to a complete stop.
What are some practical applications of this : Why can water stay in bucket if you spin it upside down, if you spin the bucket fast enough? What are some practical applications of this?
How the items mentioned previously could be used together : Write the code for manipulating abstract syntax trees if cfront had been written in C++. Why do you suppose Stroustrup chose to write it in C instead?
Impact on the heat balance as a doubling : Methane has a current concentration of 1.7 ppm in the atmosphere and its doubling at a faster rate than is CO2, would a doubling of methane

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd