Suppose that we are given a sequence A of n positive real numbers (a, a2,.., an)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose that we are given a sequence A of n positive real numbers (a, a2,.., an) to sort. a) (2 points) Can you use Count Sort AS IS to sort A? Explain b) (28 points) How can you adapt Counting Sort to sort the sequence A? Clearly state your assumptions and describe clearly using pseudocode your new Counting Sort algorithm COUNTING-SORT (A, B, k) 1 2 3 4 5 6 7 8 9 10 11 12 let C[0..k] be a new array for i 0 to k C[i] = 0 for j 1 to A.length 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 Suppose that we are given a sequence A of n positive real numbers (a, a2,.., an) to sort. a) (2 points) Can you use Count Sort AS IS to sort A? Explain b) (28 points) How can you adapt Counting Sort to sort the sequence A? Clearly state your assumptions and describe clearly using pseudocode your new Counting Sort algorithm COUNTING-SORT (A, B, k) 1 2 3 4 5 6 7 8 9 10 11 12 let C[0..k] be a new array for i 0 to k C[i] = 0 for j 1 to A.length 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)
The given pseudocode represents the Counting Sort algorithm Counting Sort is a noncomparisonbased so... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
3. A two stock (A & B) portfolio is formed. The expected returns are ra = 10% and rb = 15%. The standard deviation for Stock A is 12% and 15% for Stock B. If the correlation coefficient of the two...
-
What is a branch delay slot and why does it arise? [7 marks] How can branch delays be avoided? If a processor exhibited one branch delay slot how would you reorder (and possibly modify) the...
-
KE- Data table Industry averages Debt ratio Times interest eamed ratio Fixed-payment coverage ratio Debt analysis Springfield Bank is evaluating Creek Enterprises, which has requested a $3,560,000...
-
Find the center of mass of a water molecule, referring to FIGURE 9-43 for the relevant angles and distances. The mass of a hydrogen atom is 1.0 u, and the mass of an oxygen atom is 16 u, where u is...
-
A 20-cm-radius ball is uniformly charged to 80 nC. a. What is the balls volume charge density (C/m 3 )? b. How much charge is enclosed by spheres of radii 5, 10, and 20 cm? c. What is the electric...
-
Based on the following pedigree for a trait determined by a single gene (affected individuals are shown as filled symbols), state whether it would be possible for the trait to be inherited in each of...
-
PAR AND NO-PAR, COMMON AND PREFERRED STOCK Hernandez Company had the following stock transactions during the year: (a) Issued 25,000 shares of $1 par common stock for $25,000 cash. (b) Issued 20,000...
-
1. Why have neo-classical economists generally argued that international economic relations are not zero-sum in character? What theoretical frameworks have they used to support this argument? It's...
-
Erica and Bob participate in a friendly Hackathon that allows each to solve one question a day out of the three offered. There will be one easy, one medium and one hard question, with points awarded...
-
Tropetech Inc.'s FCFs are expected to grow at a constant rate of 3.54% per year in the future. The market value of Tropetech Inc.'s outstanding debt is $87,744 million, and its preferred stocks'...
-
Two boats start together and race across a 4 4 - km - wide lake and back. Boat A goes across at 4 4 km / h and returns at 4 4 km / h . Boat B goes across at 2 2 km / h , and its crew, realizing how...
-
You are considering the purchase of an electrical heater over a gas fired heater. The specs on it say that it has a resistance of 32 when it is operating on a 110 V outlet. Calculate the total energy...
-
Which of the following statements is not correct for a diver performing a dive on Earth? a. The gravitational attraction of the diver toward Earth and Earth toward the diver are equal in magnitude....
-
Using KVL, find the magnitude and direction of the current in R. = ||v I I. 22 = 16V E E = 12V R 252 23952 R M 352 Ry 152
-
What are the memory locations that has the value 0X55? LDI R19,0x7 LDI R16,0x55 LDI YL,LOW($140) LDI YH,HIGH($140) ST Y+, R16 DEC R19 BRNE L1 L1:
-
o. Consider a homogeneous mixture composed of graphite and uranium with 1.5% enrichment What is the optimum moderator-to-fuel ratio that yields the largest alde of koo at room temperature? Ignore...
-
Why do bars offer free peanuts?
-
Prove that matrix inverses are unique, that is, if B and C are inverses of A, then B = C.
-
Let G = (V, E) be an undirected graph. For any k 1, define G (k) to be the undirected graph (V (k) , E (k) ), where V (k) is the set of all ordered k-tuples of vertices from V and E (k) is defined...
-
Define lcm (a 1 , a 2 , . . . ,a n ) to be the least common multiple of the n integers a 1 , a 2 , . . . ,a n , that is, the smallest nonnegative integer that is a multiple of each a i . Show how to...
-
For the probability distribution in Exercise 14, find the sampling distribution of the sample mean for all samples of size \(n=2\). (Hint: The sample means will be the same as given in Figure 3.7,...
-
Minitab can also be used to create a graphical summary of a given variable. The graphical summary can be found by selecting the Stat menu; under Basic Statistics a. Using Minitab, create a graphical...
-
Often we may be interested in comparing the amount of variability between two different data sets. This can be done using the sample coefficient of variation \((C O V)\), which is a percentage that...
Study smarter with the SolutionInn App