卷別
資料結構與演算法
選擇國立臺灣大學 2024 · 考試 · 第 3 題
(5 points) A Dynamic Array (abbreviated as DArray) is a type of array that permits the insertion and deletion of elements at the end to dynamically adjust its size. DArray maintains three crucial attributes, including the underlying array , the logical data size , and the actual array capacity . The invariant holds at any given moment. The operation appends the element to the end of . In case , it triggers a call to before appending , where allocates a new and larger array, moves all the data to it, increases the value of , sets up , and finally frees the old array. Two implementations of are provided: increases by a constant (e.g., 10) while doubles each time.
To initialize DArray , we set to 0, to 1, and allocate a size 1 array to . Assuming that both allocating and freeing arrays of length take time, and moving a single element takes time, please select the correct description(s) below.
- (A)DArray is not suitable for random access because its memory may be relocated.
- (B)DArray can only be allocated in the heap memory due to its dynamic memory nature.
- (C)If is considered, the amortized time complexity of is .
- (D)If is considered, the amortized time complexity of is .
- (E)In the operation, if , is decreased by one. If, at this stage, , we create a new array with a size of , transfer the data to , set up as the new data array for , and subsequently free the old array. Then, the amortized time complexity of mixed Insert and Delete operations can be , where can be either or .