Why if you change COUNTING-SORT line 10 (see picture) to for j = 1 to A.length...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Why if you change COUNTING-SORT line 10 (see picture) to "for j = 1 to A.length" it makes counting sort not stable, and therefore cannot be used in radix sort in sorting the digits? Counting Sort COUNTING-SORT (A, B, k) 1 let C[0..k] be a new array = 0 to k C[i] = 0 for j = 1 to A.length 2 for i= 3 4 5 6 7 8 9 10 11 12 C[A[j]] = C[A[j]] +1 // C[i] now contains the number of elements equal to i. for i = 1 to k C[i] = C[i] + C[i-1] // C[i] now contains the number of elements less than or equal to i. for j = A. length downto 1 B[C [A[j]]]= A[j] C[A[j]] = C[A[j]] - 1 Why if you change COUNTING-SORT line 10 (see picture) to "for j = 1 to A.length" it makes counting sort not stable, and therefore cannot be used in radix sort in sorting the digits? Counting Sort COUNTING-SORT (A, B, k) 1 let C[0..k] be a new array = 0 to k C[i] = 0 for j = 1 to A.length 2 for i= 3 4 5 6 7 8 9 10 11 12 C[A[j]] = C[A[j]] +1 // C[i] now contains the number of elements equal to i. for i = 1 to k C[i] = C[i] + C[i-1] // C[i] now contains the number of elements less than or equal to i. for j = A. length downto 1 B[C [A[j]]]= A[j] C[A[j]] = C[A[j]] - 1
Expert Answer:
Answer rating: 100% (QA)
Counting Sort is typically used as a stable sorting algorithm meaning that it preserves the relative ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these algorithms questions
-
XYZ Corp. produces 1,000 units of output (along the same isoquant) using various combinations of capital (K) and labor (L). At point A (along the same isoquant), the firm uses 30 units of capital and...
-
Find total number of triangles in 11 12 O 14 13
-
It is now September of 2022, and the daycare center has been successfully operating for 8 months. The demand for daycare has been as strong as anticipated, with enrollment growing by 10 percent per...
-
a) If the block is at rest (and the only forces acting on the block are the force due to gravity and the normal force from the table), what is the magnitude of the force due to friction? b) Suppose...
-
(a) 16-bit sampling provides how many different possible voltages? (b) 24-bit sampling provides how many different possible voltages? (c) For color TV, 3 subpixels, each 8 bits, provides a total of...
-
Each of the following sentences contains at least one error in grammar, capitalization, punctuation, abbreviation, number style, word division, or vocabulary. Rewrite each sentence, correcting all...
-
Consider the game Cram from Exercise 1.4, played on a \(1 \times n\) board for \(n \geq 2\). Let \(D_{n}\) be the Nim value of that game, so that the starting position of the \(1 \times n\) board is...
-
Nonmonetary Exchanges Holyfield Corporation wishes to exchange a machine used in its operations. Holyfield has received the following offers from other companies in the industry. 1. Dorsett Company...
-
On August 31, 2016, the Silva Company sold merchandise to the Bendix Corporation for $500,000. Terms of the sale called for a down payment of $100,000 and four annual installments of $100,000 due on...
-
The cable supports the three loads shown. Determine the sags yB and yD of points B and D. Given: a = 4 ft b = 12 ft c = 20 ft d = 15 ft e = 12 ft f = 14 ft P1 = 400 lb P2 = 250 lb B D. P: P,V
-
Tiny is an isolated community served by one newspaper that can meet the market demand at a lower cost than two or more newspapers could. The Tiny Intelligencer is the only source of news. The graph...
-
Periodic Inventory by Three Methods; Cost of Merchandise Sold The units of an item available for sale during the year were as follows: Jan. 1 Mar. 10 Aug. 30 Inventory Purchase 50 units @ $96 60...
-
Sylvester Indet negotiated a loan from the EZY Bank of Canada for $300,000 to finance the expansion of his business. The repayment terms were fixed at $2,500 per month at 4% per annum. The loan was...
-
A project currently generates sales of $18 million, variable costs equal 60% of sales, and fixed costs are $3.6 million. The firm's tax rate is 35%. Assume all sales and expenses are cash items. a....
-
What are the 3 basic principles in community health nursing?"
-
An 8.24 gram sample of a hydrated salt is heated until it has a constant mass of 6.20 grams. What is the percent by mass of water contained in the original sample? What is the percent composition by...
-
Suppose a business analyst wanted to study the relationship between the annual advertising cost ($million) of a retail company and the number of stores the company owns. She takes a random sample of...
-
The tractor is used to lift the 150-kg load B with the 24-mlong rope, boom, and pulley system. If the tractor travels to the right at a constant speed of 4 m/s, determine the tension in the rope when...
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
On September 14, 2012, Jay purchased a passenger automobile that is used 75 percent in his accounting business. The automobile has a basis for depreciation purposes of $35,000, and Jay uses the...
-
In 2012, Michael has net short-term capital losses of $2,000, a net long-term capital loss of $45,000, and other ordinary taxable income of $45,000. a. Calculate the amount of Michael's deduction for...
-
At the end of the accounting period, a journal entry is made to close variance accounts to_or________________________,and________________________,.
-
How does Porters competitive forces model help companies develop competitive strategies using information systems? Define Porters competitive forces model and explain how it works. Describe what...
-
True or false? Standard cost variances provide definitive evidence that costs are out of control and managers are not performing effectively.
Study smarter with the SolutionInn App