卷別
資料結構與演算法
選擇國立臺灣大學 2024 · 考試 · 第 1 題
考科演算法
(5 points) Consider the following variation of the Selection Problem: Given a sequence of distinct integers and two positive integers and , where each number in falls between 1 and , the goal is to report the smallest numbers in in ascending order. This scenario assumes the conventional single-processor, random access machine (RAM) model, with a machine word size of at least bits. To tackle this problem, five algorithms have been proposed. Please select the correct description(s) below.
- (A)Algorithm A: The algorithm initializes an empty max-heap and sequentially inserts numbers from . During insertion, if the size of the max-heap exceeds , it removes the maximum element from the heap. Finally, the remaining numbers in the heap are sorted by heapsort and reported. If , Algorithm A runs in time in the worst case.
- (B)Algorithm B: The algorithm initially constructs a min-heap and proceeds to extract the minimum element times. If , Algorithm B runs in time in the worst case.
- (C)Algorithm C: The algorithm begins by performing a base- radix sort, followed by reporting the smallest values. If , Algorithm C runs in time in the worst case.
- (D)Algorithm D: The algorithm performs a counting sort by allocating an array of length , traversing through and incrementing for each . It finally reports the smallest values by scanning through the counter array. If , Algorithm D runs in time in the worst case.
- (E)Algorithm E: The algorithm first applies quickselect, i.e., Randomized-Select, to determine the -th smallest number in . Subsequently, it traverses for extracting all numbers smaller than or equal to the -th smallest number. Finally, these numbers are sorted by quicksort and reported. The time complexity of Algorithm E is in expectation.