Question textRecall the Counting Sort variant that is used as part of Radix sort. We provide it below, as given in the course notes: [table] 1 2 3 4 5 6 7 8 9 10 11 12 1314151617 | function RADIX_PASS(array[1..n], base, digit) // Digit counting counter[0..base-1] = [0,0,...] for i = 1 to n do counter[GET_DIGIT(array[i], base, digit)] += 1 // Position calculation position[0..base-1] = [1,0,...] for v = 1 to base−1 do position[v] = position[v − 1] + counter[v − 1] // Fill the temp array and swap // REPORT COUNTER AND POSITION HERE temp[1..n] = [0,0,...] for i = 1 to n do digit = GET_DIGIT(array[i],base,digit) temp[position[digit]] = array[i ] position[digit] += 1 swap(array, temp) [/table] Here, GET_DIGIT is 1-indexed, so GET_DIGIT(x, 10, 1) returns x % 10. Examples: GET_DIGIT(123, 10, 1) = 3, GET_DIGIT(123, 10, 2) = 2, GET_DIGIT(123, 10, 3) = 1 and GET_DIGIT(123, 10, 4) = 0 Note that some arrays are 1-indexed, and others are 0-indexed, since digits range from 0 to base-1.. Consider the following array of integers: [table] 15 | 872 | 572 | 4037 | 7836 | 4531 | 8981 | 26 [/table] Suppose we call RADIX_PASS(arr, 10, 3), where arr is the array above. Below, enter the values stored in counter and position as computed by the function AT LINE 11, as well as the final result for temp. You may find it useful to perform the counts and position calculations on working paper and copy onto the moodle box. [table] Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 counter | Answer 1 Question 5 | Answer 2 Question 5 | Answer 3 Question 5 | Answer 4 Question 5 | Answer 5 Question 5 | Answer 6 Question 5 | Answer 7 Question 5 | Answer 8 Question 5 | Answer 9 Question 5 | Answer 10 Question 5 position | Answer 11 Question 5 | Answer 12 Question 5 | Answer 13 Question 5 | Answer 14 Question 5 | Answer 15 Question 5 | Answer 16 Question 5 | Answer 17 Question 5 | Answer 18 Question 5 | Answer 19 Question 5 | Answer 20 Question 5 temp index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | | temp | Answer 21 Question 5 | Answer 22 Question 5 | Answer 23 Question 5 | Answer 24 Question 5 | Answer 25 Question 5 | Answer 26 Question 5 | Answer 27 Question 5 | Answer 28 Question 5 | | [/table]多项填空题

题目图片

登录即可查看完整答案

我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!