Notes:


Problem : Complete the Canvas quizzes on greedy algorithms and multi-modal shortest paths.

Problem : Prof. and Mrs. Glenn need to build a fence around their yard to keep the deer from eating their azaleas. The fence will start at one corner of their house and end at another. The perimeter of their yard is marked by trees, and the fence must follow that perimeter. Furthermore, the fencing is sold in lengths of $L$ and, to avoid setting fenceposts, each segment of fencing must start and end at either a corner of the house or a tree; the next segment then starts at the tree where the previous segment ended. Segments less than $L$ are possible, but the scraps may not be reused in other parts of the fence.

Devise a $\Theta(n)$ algorithm to determine the minimum number of fencing segments the Glenns must buy to complete their fence, and prove that your algorithm is correct. The inputs should be as follows:

The output should be the ordered list of $k+1$ segment endpoints, where $k$ is the number of segments used. (Formally, the output should be a subsequence of $d$ starting with 0.0 and ending with the last element of $d$ such that each pair of adjacent elements differs by no more than $L$ and that is as short as possible given those conditions.)

You may use a simple sequential search as part of your algorithm without proving that the sequential search is correct (although that is a good exercise).

diagrams of yard perimeters
If $n = 7$, $d$ = $[0.0, 1.0, 2.1, 3.1, 4.3, 5.2, 5.8, 7.2, 8.4]$, and $L = 3$, then the optimal number of segments is 4, for example $[0.0, 1.0, 3.1, 5.8, 8.4]$ (corresponding to segments indicated by consecutive sides of the same boldness).

Problem : Consider the following job scheduling problem. We are given all at once $n$ jobs with positive lengths $t_1, t_2, \ldots, t_n$ and positive weights $w_1, \ldots, w_n$. We can schedule only one job at a time and once we start a job we must run it to completion. A schedule for a set of jobs is then the starting time for each job $s_1, s_2, \ldots, s_n$. Find an efficient algorithm to find a schedule of the jobs to minimize the total weighted turnaround time, where the turnaround time for a job is the difference between the time the job arrived and when it finished. Since all jobs arrive at the same time $t=0$, the turnaround time for job $i$ simplifies to $s_i + t_i$ and so the problem is to schedule the jobs to minimize $\sum_{i=1}^n w_i\cdot (s_i + t_i)$. Prove that your algorithm is correct (if you use a greedy algorithm you need only prove that the solution resulting from your greedy choice is always optimal, not that your algorithm correctly finds that greedy solution).

Problem : Devise an efficient algorithm for determining the location of food deserts. The input is

The output should be a list of the intersections that are food deserts. Compute the asymptotic running time of your algorithm, explaining your computation. Include in your explanation your choice of representation for the graph and other ADTs used in your solution. You need not prove that your algorithm is correct.

food:7,10; pops:20,25,15,40,10,40,10,20,20,20; edges:(1,2)=3 (1,4)=2, (1,4)=3, (2,3)=4, (2,6)=2, (3,8)=7, (4,5)=4, (4,7)=4, (5,8)=6 (5,9)=3, (6,8)=2, (7,9)=3, (8,10)=4, (9,10)=5
VertexClosest
Food
Dist.Pop.Cumulative
Pop.
7 7 0 10 10
10 10 0 20 30
9 7 3 20 50
4 7 4 40 90
8 10 4 20 110
5 7 6 10 120
1 7 6 20 140
6 10 6 40 180
2 10 8 25 205
3 10 11 15 220

The small number in each vertex is its index; the large number is its population. The table shows vertices sorted by distance to closest food source, with cumulative population. $S$ is $[7, 10]$. When $b = 130$, the output would be $[2, 3]$ or $[3, 2]$ since the closest 130 people live within 6 or closer of an intersection in $S$ and the people who live at $2$ and $3$ are strictly farther than that (8 and 11 respectively). Note that the people at vertex 6 are at the same distance as those at vertices 1 and 5, so they are not in a food desert – the "strictly farther" condition disambiguates cases like this where reordering vertices that are all at the threshold distance (5, 1, and 6 in this example) would result in different sets containing the closest $b$.