0% found this document useful (0 votes)
107 views

HW 3

This document describes the homework assignment for CSE 202 in Winter 2021. It includes 4 ungraded problems analyzing greedy algorithms strategies and their optimality. It also includes 4 graded problems on sentries guarding a border, scheduling tasks with release/due dates, selecting business projects to maximize profit, and properties of minimum spanning trees and shortest paths when costs are squared. An optional extra credit problem on event scheduling across multiple rooms is also described but not graded.

Uploaded by

Ashley Fuller
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

HW 3

This document describes the homework assignment for CSE 202 in Winter 2021. It includes 4 ungraded problems analyzing greedy algorithms strategies and their optimality. It also includes 4 graded problems on sentries guarding a border, scheduling tasks with release/due dates, selecting business projects to maximize profit, and properties of minimum spanning trees and shortest paths when costs are squared. An optional extra credit problem on event scheduling across multiple rooms is also described but not graded.

Uploaded by

Ashley Fuller
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 202 Homework 3

Winter, 2021
Due Tuesday, Feb 2 at 11:59 PM
Greedy algorithms.
All graded parts are worth 20 points.

1 Ungraded Problems
For each of the following problems, two greedy strategies are given. Decide which greedy strategy gives
optimal solutions. Find a counter-example for the other, prove the correct one is correct, and give as
asymptotically efficient an algorithm as possible for the correct strategy.

Weighted average completion time You are given a list of n jobs j1 , ..jn , each with a time t(j) to
perform the
Pjob, and a Pweight w(j). You wish to order the jobs as jσ(1) , , ...jσ(n) in such a way as to
minimize: i w(jσ(i) ) · 1≤k<i t(jσ(k) ); the weighted sum of the time each job has to wait before being
performed.
Greedy Strategy A: Perform the job with the shortest completion time first. If there are ties, use the
one with the highest weight. Repeat on remaining jobs.
Greedy Strategy B: Perform the job with the largest ratio r(j) = w(j)/t(j) first. Repeat on remaining
jobs.
Oxen pairing Consider the following problem: We have n oxen, Ox1 , ..Oxn , each with a strength rating
Si . We need to pair the oxen up into teams to pull a plow; if Oxi and Oxj are in a team, we must
have Si + Sj ≥ P , where P is the weight of a plow. Each ox can only be in at most one team. Each
team has exactly two oxen. We want to maximize the number of teams.
Greedy Strategy A: Take the strongest and weakest oxen. If together they meet the strength require-
ment, make them a team. Recursively find the most teams among the remaining oxen. Otherwise,
delete the weakest ox. Recursively find the most teams among the remaining oxen.
Greedy Strategy B: Take the two weakest oxen. If together they meet the strength requirement, make
them a team. Recursively find the most teams among the remaining oxen. Otherwise, delete the
weakest ox. Recursively find the most teams among the remaining oxen.
Biggest Area Segment Matching You are given a set of n horizontal segments of lengths a1 , . . . , an
and a set of vertical segments of length b1 , . . . , bn . Each horizontal segment ai can be combined with
a vertical segment bj to form a rectangle of area ai · bj . A matching between the lengths assigns each
horizontal length ai a distinct vertical length bji . Give as efficient an algorithm as possible that on input
a1 , . . . , an , b1 , . . . , bn , finds a matching between
P the horizontal and vertical segments that maximizes
the total area of all resulting rectangles, i ai bji .
Greedy strategy A: Pair the largest horizontal segment with the shortest vertical segment; Repeat on
the remaining segments.
Greedy strategy A: Pair the largest horizontal segment with the largest vertical segment; Repeat on
the remaining segments.
Cookies Consider the following problem:
You are baby-sitting n children and have m > n cookies to divide between them. You must give each
child exactly one cookie (of course, you cannot give the same cookie to two different children). Each
child has a greed factor gi , 1 ≤ i ≤ n which is the minimum size of a cookie that the child will be
content with; and each cookie has a size sj , 1 ≤ j ≤ m. Your goal is to maximize the number of content
children, i.e.., children i assigned a cookie j with ci ≤ sj .
Candidate Strategy A: Assign the largest cookie to the greediest child. Repeat.

1
Candidate Strategy B: Look at the greediest child. If the largest cookie makes the child content, give
the child the largest cookie. Otherwise, give the child the smallest cookie.
Homework grade maximization In a class, there are n assignments. You have H hours to spend on all
assignments, and you cannot divide an hour between assignments, but must spend each hour entirely on
a single assignment. The I’th hour you spend on assignment J will improve your grade on assignment
J by B[I, J], where for each J, B[1, J] ≥ B[2, J] ≥ ... ≥ B[H, J] ≥ 0. In other words, if you spend h
Pi=h
hours on assignment J, your grade will be i=1 B[i, J] and time spent on each project has diminishing
returns, the next hour being worth less than the previous one. You want to divide your H hours between
the assignments to maximize your total grade on all the assignments.
Greedy strategy A: Spend each hour on the assignment with the current smallest total grade.
Greedy strategy B: Spend the next hour h on the assignment that has the largest increase in grade for
the additional hour.

2 Problems
Sentries You are a general and want to post sentries to guard the entire border, which is roughly a straight
line, starting at position 0 and going to position L. There are n towers where you can place sentries,
with the i’th tower at position Di along the border, and having visibility vi in either direction. You
want to place sentries in towers so that they can observe the entire border, so every location is visible
to some sentry, in a way that minimizes the number of towers used. Give an efficient algorithm for this
problem; you can assume towers are listed in increasing order of Di . (As usual, your solution should
include a mathematical formulation of the problem, correctness proof, running time analysis, etc.)
One task a day You have a list of n tasks, such as homework assignments, each with a release date ri and
a due date di . You also have a list of D days that you have free to do the tasks. Each task will take
a complete, uninterupted day to perform. You want to find a schedule that maximizes the number of
tasks done by their due dates. You cannot do more than one task a day, and you cannot schedule a
task before its release date. Give an efficient algorithm for this problem.
Business plan Consider the following problem. You are designing a business plan for a start-up company.
You have identified n possible projects for your company, and, for i = 1, . . . , n, let ci > 0 be the
minimum capital required to start the project i, and pi > 0 be the profit after the project is completed.
You also know your initial capital C0 > 0. You want to perform at most k ≤ n projects before the IPO
and want to maximize your total capital at the IPO. Your company cannot perform the same project
twice. In other words, you want to pick a list of up to k 0 distinct projects, i1 , . . . , ik0 , with k 0 ≤ k.
Pj
Your accumulated capital after completing the project ij will be Cj = C0 + h=1 pih . The sequence
must satisfy the constraint that you have sufficient capital to start the project ij+1 after completing
the first j projects, i.e., Cj ≥ cij+1 for j = 1, . . . , k 0 . You want to maximize the final amount of capital
Ck0 . Give an algorithm to find an optimal solution.
Minimum Spanning Tree (KT 4.2) Suppose we are given an instance of the Minimum Spanning Tree
problem on a graph G, with edge costs c(e) that are all positive and distinct. Let T be a minimum
spanning tree for this instance. Now, suppose we replace each edge cost c(e) by its square c(e)2 , thereby
creating a new instance of the problem with the same graph but different costs. Decide whether you
think the following statement is true or false. If it is true, give a short explanation. If it is false, give
a counterexample.

“T must still be a minimum spanning tree for this new instance.”

Now suppose we are given an instance of the Shortest s − t Path problem on a directed graph G, with
edge costs c(e) that are all positive and distinct. Let P be a minimum cost s − t path for this instance.

2
Now, suppose we replace each edge cost c(e) by its square c(e)2 , thereby creating a new instance of the
problem with the same graph but different costs. Decide whether you think the following statement is
true or false. If it is true, give a short explanation. If it is false, give a counterexample.

“P must still be a minimum cost s − t path for this new instance.”

Optional problem You will not receive a grade on this problem, and we will not provide a solution. It
is listed here so you can submit your solution, should you decide to work on it. But, if you submit a
solution, be sure we will read it.
Recall the event scheduling problem with multiple rooms: you are given a list of events E1 , . . . , En ,
each with a start and end time Ei = [si , fi ), and need to assign them to rooms {1, . . . , k} so that events
scheduled in the same room do not overlap. All events should be assigned to a room. The goal is to
minimize the number k of rooms needed.
The following greedy algorithm was proposed in class (Jan 21, Brendon) to solve the problem:
• Run the single room interval scheduling algorithm to maximize the number of events scheduled
in room 1.
• Remove those interval from the set, and proceed to schedule the remaining events in the other
rooms.
• Continue until all events are assigned to a room.

It is easy to see that if you use an arbitrary algorithm to solve the (single room) scheduling subproblem,
this method does not provide an optimal solution. For example, on input Ei = [i, i + 2] for i = 1, 2, 3, 4,
one may schedule E1 , E4 in room 1, which is the largest number of events that can be scheduled in a
single room. But after these choice, E2 and E3 will require two additional rooms because they overlap
with each other. This solution is not optimal becuase it uses a total of 3 rooms, while it is possible to
use only 2. (E1 , E3 in one room, and E2 , E4 in the other.)
This problem asks to determine if the above algorithm is correct (i.e., it produces an optimal solution)
when the single room scheduling problem is solved using the specific algorithm presented in class (and
in the textbook.) Namely, events are schedule in a room by sorting them in order of finish time fi , and
then scheduling them in order, while skipping events that create conflicts. Determine if the resulting
multi room scheduling algorithm is correct or not, and provide either a proof or a counterexample.

You might also like