東京大学 情報理工学系研究科 コンピュータ科学専攻 2022年8月実施 専門科目 問題2
Author
Description
We consider a division of a set of mutually distinct
Let
The following pseudo code shows an algorithm that computes an approximation of
Answer the following questions.
(1) Calculate
(2) Show
(3) Show that
(4) Show that the while loop in the above code will be repeated at most
(5) Describe data structures needed to make the above algorithm run in
以下是中文翻译:
我们考虑将一组相互不同的
设
下面的伪代码展示了一种计算
回答以下问题。
(1) 计算
(2) 证明
(3) 证明不论第 2 行选择何种划分
(4) 证明不论第 2 行选择何种划分
(5) 描述所需的数据结构以使上述算法运行在
Kai
(1)
To find
The total sum of the set
We need to divide this into two subsets such that the maximum sum is as small as possible. We can consider the following possible divisions:
-
: - Maximum sum = 9
-
: - Maximum sum = 10
-
: - Maximum sum = 11
The minimum maximum sum among these divisions is 9. Therefore:
(2)
Let
where
For any division
Let
because the total sum is distributed across
Since
(3)
The algorithm attempts to balance the largest and smallest subset sums by moving the top element from the stack with the largest sum to the stack with the smallest sum until no improvement can be made.
Let
When the algorithm moves an element from the subset with the largest sum to the subset with the smallest sum, the maximum possible increase in the smallest sum is bounded by the value of the largest element moved. This adjustment ensures that the final maximum sum
Thus:
(4)
Each iteration of the while loop in the pseudo-code moves an element from the stack
(5)
To achieve an
-
Initialize: Use two priority queues, one for the stack with the maximum sum and one for the stack with the minimum sum.
- Insert each stack's sum along with its identifier into the respective priority queues. Both insertion and deletion in a priority queue take
time.
- Insert each stack's sum along with its identifier into the respective priority queues. Both insertion and deletion in a priority queue take
-
Update: During each iteration of the while loop:
- Extract the maximum from the "max" priority queue and the minimum from the "min" priority queue.
- Perform the pop operation from the stack with the maximum sum and push the element onto the stack with the minimum sum.
- Update the priority queues with the new sums. This step also takes
time.
Since each operation inside the while loop is
Knowledge
贪心算法 集合划分 复杂度分析
重点词汇
- division: 划分
- priority queue: 优先队列
- minmax: 最小最大化
参考资料
- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press. Chapter 16: Greedy Algorithms.
- Kleinberg, J., & Tardos, É. (2005). Algorithm Design. Pearson. Chapter 6: Greedy Algorithms.