Hiking ISQL

Java Python Hiking I

This is a regular task. You must submit a PDF, which can be produced using the LATEX template on Moodle, exported from a word processor, hand-written or any other method.

There are n people that you need to guide through a difficult mountain pass. Each person has a time in days that it will take to guide them through the pass. You will guide people in groups of up to k people, but you can only move as fast as the slowest person in each group.

For example, if we have 7 people with travel times 3, 6, 4, 2, 1, 8 and 6, with k = 3, we may choose to put them into groups [3, 1], [2, 8] and [6, 4, 6]. The first group will take 3 days, the second will take 8 days and the third will take 6 days, for a total of 17 days. Note that this is not the optimal grouping.

We want to form. groups to guide everyone through the pass in the fewest possible number of days.

(a) Describe how the groups should be formed in the general case (not for the given example), and explain your intuition for why this is optimal.

Hint: Who should be grouped with the slowest person? Think carefully about the case where n is not a multiple of k.

We will now justify the correctness of this algorithm using an exchange argument. We need to show that we can make any grouping better (or at least, not worse) by making it closer to our grouping. We will consider the grouping created by our greedy method, which we’ll call G for greedy. We’re going to compare this to some other grouping, which we’ll call O for other.

Our first step is to ignore any groups that are the same in both G and O. We want to transform. O into G, and there isn’t anything we need to do for these groups. Now, in each grouping, we’ll consider the slowest remaining group, which we’ll call Oslow and Gslow. In the above example, we would have slow = [2, 8] and Gslow = [6, 6, 8].

If Gslow is not a full group, then it follows that there is no way to beat it using two o Hiking ISQL r more groups (why?), so the only interesting cases are when Gslow has k people (and Oslow could have exactly k or fewer than k). The next parts of the task will guide you through the process of constructing a new grouping O′ from O in which Oslow is replaced by Gslow, and the argument that O′ is the same or better than O in terms of days hiked.

(b) Suppose that Oslow has fewer than k people. How can we move one person into Oslow (from some other group of O), without making any group in O slower?

(c) Now suppose instead that Oslow has exactly k people. Identical groups between G and O were already ignored, and since these two groups are of equal size, there must be a person Alice who is in Gslow but not in Oslow, as well as a person Bob who is in Oslow but not in Gslow. If we make the new grouping O′ by swapping Alice and Bob’s positions in O, what happens to the travel times of their respective groups?

Hint. Is Alice among the k slowest people remaining? How about Bob?

By applying these modifications repeatedly (which address all differences between G and O), we can transform. any grouping into our greedy grouping without making it worse, so by the exchange argument, our greedy algorithm must be correct.

◦ This task is continued on Moodle.

Rubric.

(a) Describe a way to form. groups of up to k people that allows all n people to be guided through the path in as few days as possible and give a short informal reason for why this grouping should be optimal.

Expected length: 3 or 4 sentences.

(b) Describe how you can choose a person to move into Oslow without making any group slower. Briefly justify how this does not make any group slower.

Expected length: two or three sentences.

(c) Identify what happens to the travel times of Alice and Bob’s groups if they are swapped in O. Briefly explain why this is the case.

Expected length: two or three sentences         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值