我的算法设计课作业中出现了这个脑筋急转弯:
Given a list of N distinct positive integers, partition the list into two
sublists of n/2 size such that the difference between sums of the sublists
is maximized.
Assume that n is even and determine the time complexity.
乍一看,解决方案似乎是
- 通过归并排序对列表进行排序
- 选择n/2位置
- 对于所有大于该位置的元素,添加到高数组中
- 对于所有小于该位置的元素,添加到低数组中
这将具有时间复杂度O((n log n)+ n)
是否有更好的算法选择来解决这个问题?