Question

In: Computer Science

Problem 1 (4+3 marks). (a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20,...

Problem 1 (4+3 marks). (a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisons made. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort.

Solutions

Expert Solution

1)Merge sort illustration.

5, 13, 2, 25, 7, 17, 20, 8, 4
divide it into two parts
5 13 2 25 7 17 20 8 4
divide each part into two parts
5 13 2 25 7 17 20 8 4

divide each part into one part ,except for 20,8 and 4.Here divide 20 from 8 and 4.


5 13 2 25 7 17 20 8 4
Again divide 8 and 4 into two parts
5 13 2 25 7 17 20 8 4

merge parts
5 13 2 25 7 17 20 4 8
Merging again
5 13 2 25 7 17 4 8 20

merge parts
2 5 13 25 4 7 8 17 20
merge parts into one
2 4 5 7 8 13 17 20 25

2)Heapsort illustration.

A=〈5,13,2,25,7,17,20,8,4〉.
〈5,13,2,25,7,17,20,8,4〉
〈5,13,20,25,7,17,2,8,4〉
〈5,25,20,13,7,17,2,8,4〉
〈25,5,20,13,7,17,2,8,4〉
〈25,13,20,5,7,17,2,8,4〉
〈25,13,20,8,7,17,2,5,4〉
〈4,13,20,8,7,17,2,5,25〉
〈20,13,4,8,7,17,2,5,25〉
〈20,13,17,8,7,4,2,5,25〉
〈5,13,17,8,7,4,2,20,25〉
〈17,13,5,8,7,4,2,20,25〉
〈2,13,5,8,7,4,17,20,25〉
〈13,2,5,8,7,4,17,20,25〉
〈13,8,5,2,7,4,17,20,25〉
〈4,8,5,2,7,13,17,20,25〉
〈8,4,5,2,7,13,17,20,25〉
〈8,7,5,2,4,13,17,20,25〉
〈4,7,5,2,8,13,17,20,25〉
〈7,4,5,2,8,13,17,20,25〉
〈2,4,5,7,8,13,17,20,25〉
〈5,4,2,7,8,13,17,20,25〉
〈2,4,5,7,8,13,17,20,25〉
〈4,2,5,7,8,13,17,20,25〉
〈2,4,5,7,8,13,17,20,25〉


Related Solutions

(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted...
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisons made. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort.
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted...
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisonsmade. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort
Consider the data. xi 1 2 3 4 5 yi 4 7 5 11 13 (a)...
Consider the data. xi 1 2 3 4 5 yi 4 7 5 11 13 (a) Compute the mean square error using equation  s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s = MSE = SSE n − 2  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi − x)2...
Consider the data. xi 1 2 3 4 5 yi 3 7 5 10 13 (a)...
Consider the data. xi 1 2 3 4 5 yi 3 7 5 10 13 (a) Compute the mean square error using equation s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s = MSE = SSE n − 2  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi −...
Month 1 2 3 4 5 6 7 Value 23 13 20 12 18 21 16...
Month 1 2 3 4 5 6 7 Value 23 13 20 12 18 21 16 (b) Develop a three-month moving average for this time series. Compute MSE and a forecast for month 8. If required, round your answers to two decimal places. Do not round intermediate calculation. MSE:   The forecast for month 8:   (c) Use α = 0.2 to compute the exponential smoothing values for the time series. Compute MSE and a forecast for month 8. If required, round...
Month 1 2 3 4 5 6 7 Value 23 13 20 12 18 21 16...
Month 1 2 3 4 5 6 7 Value 23 13 20 12 18 21 16 (b) Develop a three-month moving average for this time series. Compute MSE and a forecast for month 8. If required, round your answers to two decimal places. Do not round intermediate calculation. MSE:   The forecast for month 8:   (c) Use α = 0.2 to compute the exponential smoothing values for the time series. Compute MSE and a forecast for month 8. If required, round...
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1,...
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1, 7}. Answer the following questions, giving reasons for your answers. a) Is ? ⊆ ?? b)Is ? ⊆ ?? c) Is ? ⊂ ?? d) Is ? ⊆ ?? e) Is ? ⊆ ?? 5) Let ? = {1, 3, 4} and ? = {2, 3, 6}. Use set-roster notation to write each of the following sets, and indicate the number of elements in...
Answer all the question below. Table 2: 1 3 5 7 9 11 13 15 17...
Answer all the question below. Table 2: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 12.2373551424579 11.7708440253038 11.3114033194700 11.0981090241345 10.9917532871426 10.9633449623870 10.9328985186904 11.0609123182770 11.1447150124713 11.2994243413533 11.4699411879533 11.5862580969086 11.7887055678588 11.9277833926721 11.9332325617172 12.0027754228957 12.0455191817870 11.9895076044597 12.1161492247957 11.9142999902406 11.9523445384738 11.8444716643177 11.8325572681845 11.6394782554936 11.4409836766153     Visualize data in table 2 in a 2-dimensional plot using Matlab.     Interpolate data in table 2 to determine a value of...
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5....
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5. Explain why Maria has made a good attempt, but her answer is not correct. Explain how to work with what Maria has already written and modify it to get the correct answer. In other words, don’t just start from scratch and show Maria how to do the problem, but rather take what she has already written, use it, and make it mathematically correct. Which...
Consider the following pairs of observations.X 1 4 3 5 7 2 6 20
Consider the following pairs of observations. X 1 4 3 5 7 2 6 20 Y 3 12 10 12 19    7 17   60 A) Calculate the least squares line. B) Determine a 95% confidence interval for the mean value of Y using X = 6 C) Determine a 95% prediction interval for the Y value using X = 6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT