Course Home | Assignments | Peer Assessment Procedures | Schedule & Lecture Notes

Saint Louis University

Computer Science 314
Algorithms

Michael Goldwasser

Fall 2014

Dept. of Math & Computer Science

Homework Assignment 03

Dynamic Programming, Greedy Algorithms


Overview

Topics: Dynamic Programming and Greedy Algorithms
Related Reading: Chapters 15, 16 of CLRS
Due: 10:00am, Monday, October 6, 2014

Please make sure to strictly adhere to the stated course procedures regarding the format of your submitted homework. In particular, your name should not appear on anything other than the cover page, and your solution for each problem must be in a separate packet, labeled appropriately with your assigned codename.

You must also adhere to the policies on academic integrity, paying particular attention to the limits on collaboration.


Problems to be Submitted

  1. Work entirely on your own

    Exercise 15.1-2 (on page 370 of CLRS).

  2. Work entirely on your own

    Exercise 16-2 (on page 447 of CLRS).

    Although the book asks you to design and analyze two algorithms, I'll help you out by giving you both algorithms. Your only responsibility is to provide a rigorous proof of optimality for each.

    1. Run the tasks in nondecreasing order of their processing times.

    2. During any fixed unit of time, run a portion of a released, yet unfinished, task having the smallest remaining processing time (where the remaining processing time is equal to the original processing time minus any time that the task has been processed thus far).

    Note as well that minimizing the average completion time is equivalent to minimizing the sum of the completion times, since the number of jobs is fixed. So you are welcome to argue about the sum of the completion times as a convenient metric.

  3. Work entirely on your own

    Consider the following optimization problem. Someone is in charge of collecting all of the flags left interspersed on the ski slope. They must do so by skiing to and grabbing each flag. The person may grab more than one flag on a single run down the hill, but given that you cannot ski uphill, it may take more than one ski run to gather all the flags. We would like to be able to suggest a plan that uses as few runs as possible.

    We model the problem as follows. The slope itself will be viewed as an n-by-n grid. The top of the ski-slope will be the top-left corner of the grid, and the hill is sloped so that a skier can move either downward or rightward at each individual step, until eventually ending up at the bottom-right corner of the grid. The flags will be placed at certain grid locations and the collector will be informed of the overall number of flags and the grid coordinates of each flag before beginning.

    Someone has suggested the following greedy approach: When planning the first run, calculate a path that maximizes the number of flags that will be collected on that run (let's not worry about precisely how we calculate this local solution -- just assume that we have a way to find such a path and use it). With those flags removed, repeat this approach, choosing a second run that maximizes the number of remaining flags that can be collected, and so on until collecting all flags. If there is ever a tie in choosing the path with the most flags, you may assume an arbitrary such path will be chosen.

    An example of this approach is diagrammed as follows:


    Although the 3 runs produced by the algorithm on this example are optimal, the algorithm does not always achieve a solution with the fewest number of overall runs. Demonstrate the suboptimality of the strategy as follows:

  4. You may discuss ideas with other students (but your writeup must be independent)

    Consider the skiing problem introduced in the previous exercise. Another greedy algorithm has been suggested for minimizing the number of runs. Each run is built with the following rules. Starting at the top-left corner, the next step will be rightward if there remains one or more flags somewhere further right in the current row, or trivially if the run has already reached the bottom row. Otherwise the next step taken is downward.

    Give a rigorous proof that this rule succeeds in producing a solution with a minimal number of runs for any problem instance.

  5. You may discuss ideas with other students (but your writeup must be independent)

    Provide a dynamic programming solution to this Adventures in Moving programming contest problem.

    In describing your solution, you should make particular note of the following:


Extra Credit

  1. You may discuss ideas with other students (but your writeup must be independent)

    Show that the Adventures in Moving problem can be solved more efficiently using a greedy rule for deciding how much gas to buy when at a station. Give a clear statement of your rule, a justification of its optimality, and an analysis of the running time of the complete algorithm.


Michael Goldwasser ©2014
CSCI 314, Fall 2014
Last modified: Wednesday, 24 September 2014
Course Home | Assignments | Peer Assessment Procedures | Schedule & Lecture Notes