Prove the following loop invariants about the Counting Sort algorithm, below. Note that you do not...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Prove the following loop invariants about the Counting Sort algorithm, below. Note that you do not need to prove that this algorithm is correct. Input: data: array of n integers that are between 1 and r Input: : size of data Input: r: range of data Output: permutation of data such that data[1] data 2... datan 1 Algorithm: Counting Sort 2 count = Array(r) s Initialize count to 0 4 for i=1 to n do scount data] = count/data[i] +1 e end for j=2 tor do | count] =count]+countj - 1] 9 end 10 output= Array (n) 11 for i=1 to n do 12 output count(data[i] = data[i] 13 count/data[i]=count data-1 14 end 15 return output 1. Prove that count equals the number of times j appears in data[1..i), for every from 1 up to r, after each iteration of the for loop in lines 4-6. 2. Prove that count equals the number of values in data that are less than or equal to j after every iteration of the for loop in lines 7-9. Hint: first, prove that count is the number of times j appears in data after the loop in lines 4-6. Prove the following loop invariants about the Counting Sort algorithm, below. Note that you do not need to prove that this algorithm is correct. Input: data: array of n integers that are between 1 and r Input: : size of data Input: r: range of data Output: permutation of data such that data[1] data 2... datan 1 Algorithm: Counting Sort 2 count = Array(r) s Initialize count to 0 4 for i=1 to n do scount data] = count/data[i] +1 e end for j=2 tor do | count] =count]+countj - 1] 9 end 10 output= Array (n) 11 for i=1 to n do 12 output count(data[i] = data[i] 13 count/data[i]=count data-1 14 end 15 return output 1. Prove that count equals the number of times j appears in data[1..i), for every from 1 up to r, after each iteration of the for loop in lines 4-6. 2. Prove that count equals the number of values in data that are less than or equal to j after every iteration of the for loop in lines 7-9. Hint: first, prove that count is the number of times j appears in data after the loop in lines 4-6.
Expert Answer:
Related Book For
Algebra And Trigonometry Graphs And Models
ISBN: 9780134179049
6th Edition
Authors: Marvin Bittinger, Judith Beecher, David Ellenbogen, Judith Penna
Posted Date:
Students also viewed these computer network questions
-
In a Hopfield neural network configured as an associative memory, with all of its weights trained and fixed, what three possible behaviours may occur over time in configuration space as the net...
-
Could you please help complete the following java code. Help is needed where //*** is throughout the code. import java.util.Arrays; import java.util.Random; import java.util.Scanner; // // Project 3...
-
The Ramirez Company current dividend was $1.90. Its dividend will grow by 6%, 7%, 8% and 9% for the first 4 years. And then, dividends to grow at a rate of 5% forever. It's required return is 15%. 1-...
-
Choose a current topic related to Object Oriented Systems Analysis and Design. Make sure your topic is related to Object Oriented Systems Analysis and Design.
-
Find Vbd in the circuit shown. + 4V- 12 V 2 V
-
You are the finance director of the Australian listed company, Yidaki Ltd that has A$ as the functional currency. Yidaki Ltd purchases goods from Hong Kong and has borrowings from a US bank. The...
-
Tuff Wheels was getting ready to start its development project for a new product to be added to its small motorized vehicle line for children. The new product is called the Kiddy Dozer. It will look...
-
The Power of Trade and Comparative Advantage: Work It Out 3 ? Here's another specialization and exchange problem. This problem is wholly made-up, ? so that you won't be able to use your intuition...
-
(a) A homogeneous solid body of arbitrary shape is initially at temperature T, throughout. At t = 0 it is immersed in a fluid medium of temperature T. Let L be a characteristic length in the solid....
-
Example 2/ vapor compression refrigeration cycle has 3 TR used R717 as working fluid with evaporator pressure 5 bar and condenser pressure 70 bar. This cycle working with liquid suction heat...
-
Calculate the cost of equity, the cost of debt and the weighted average cost of capital (WACC) of the project risk free rate is 3%, beta factor is 2.49, 75% equity and 25% debt, market return is 9%
-
Suppose the expected return for the general market is 7% and the risk premium in the market is 10%. If the required rate of return for a particular stock is 12% then what is the Beta of the stock?...
-
A company will need $220,000 cash to modernize machinery in 7 years time. A financial institution will invest the company's money in a fund at 4% interest compounded quarterly. Determine the cash...
-
Using the provided MATLAB finite element code, find the displacements and stresses in the two truss structures given in Figure 3. Plot the deformed structure with MATLAB. For truss structure (b),...
-
akcreate the locus (root locus) of the roots of the characteristic equation of the system given below b) Indicate whether the s-10 test point is on the root locus or not c) Find the K value of the...
-
Calculate the differential equation y''= 3x + y 2 + y + y', y (0) = 2, y (1) = 4 by shooting / estimation method using h = 1/3, y (1/3 ) and y (2/3) u just need to calculate.
-
Write out the formula for the total costs of carrying and ordering inventory, and then use the formula to derive the EOQ model. Andria Mullins, financial manager of Webster Electronics, has been...
-
Find each of the following. Do not use a calculator. log 5 125
-
Express as a product. ln a
-
Find d when a 1 = 8 and a 11 = 26.
-
With the availability of free credit reports, consumers are encouraged to check their report every 4 months-one report from each of the three major bureaus. In the past, consumers also were...
-
A leading financial publication reported that the average baby boomer credit user will pay approximately $1,200 in interest annually. If, instead of paying interest, this amount was saved every year,...
-
Some credit card issuers are beginning to assess fees and other charges on convenience users. Ask your friends and peers if they think a convenience credit card user should be charged for the...
Study smarter with the SolutionInn App