広島大学 先進理工系科学研究科 情報科学プログラム 2021年8月実施 専門科目II 問題2
Author
祭音Myyura
Description
集合の中で 番目に小さい要素を探すアルゴリズムを Select(A, p, r, i) に示す。
Select(A, p, r, i) は配列 の部分配列 から のうち 番目に小さい要素を返す。
ただし、集合の要素は配列 に整列せずに置かれているとする。
また、配列 の先頭要素を で表す。
(1) 配列 に対して Select(A, 1, 10, 3) が返す値を書け。
(2) (1) の配列 に対して Select(A, 1, 10, 3) を呼び出すと、Select が再帰的に呼び出される。
最初の呼び出しを含めて、Select の呼出しごとのパラメーター の値を書け。
ただし、配列 についてはすべての要素を書くこと。
(3) 空欄 , , を適切に埋める。
(4) 昇順に整列された 要素の配列 をパラメーターにして Select(A, 1, n, 1) が呼び出されたとき、Partition の 4 行目の比較が行われる回数を数えよ。
(5) 個の要素の集合に対する Select の期待計算時間をビッグオー記法で示し、その理由を簡潔に説明せよ。
Select(A, p, r, i) is an algorithm to find the -th smallest element in a set.
Select(A, p, r, i) returns the -th smallest element in the subarray to of array .
We assume that the set is not sorted and resides in array .
The first element of array is represented by .
(1) For array , show the return value of Select(A, 1, 10, 3).
(2) When we call Select(A, 1, 10, 3) for array shown in (1), Select is called recursively
Describe the values of parameters for each recursive call of Select, including the first call. All elements of array should be described.
(3) Fill blanks , , and , appropriately.
(4) Count the number of comparisons on the 4th line of Partition, when Select(A, 1, n, 1) is called with sorted array of elements in ascending order.
(5) Show the expected time complexity of Select for a set of elements, using big- notation. Explain the reason of the complexity, briefly.
题目描述
Select(A,p,r,i) 用于在未排序数组 的子数组 至 中找出第 小的元素并返回;数组首元素记为 。算法及其调用的 Partition 见题中图示。
-
对
写出
Select(A,1,10,3)的返回值。 -
对第 1 问的数组调用
Select(A,1,10,3)时会产生递归调用。列出包括首次调用在内的每次Select调用中参数 的值;其中数组 必须写出全部元素。 -
适当填写算法中的空白 、、。
-
若 是已按升序排列的 元素数组,调用
Select(A,1,n,1)时,计算Partition第 4 行所执行的比较总次数。 -
用大 记号写出
Select在 元素集合上的期望运行时间,并简要说明理由。
考点
- 快速选择:跟踪分区后的数组与递归参数,补全秩的更新规则,并分析特定枢轴序列下的比较次数及期望复杂度。
Kai
(1)
(2)
(3)
- blank :
- blank :
- blank :
(4)
When array is in ascending order, the function Partition(A, p, r) will always return since all elements in are less than .
Hence the number of comparisions on the 4th line of Partition is
(5)
Let denote the expected time complexity of Select for a set of elements.
Then,