0% found this document useful (0 votes)
12 views5 pages

HW8 Handout

This document outlines the homework assignment for CompSci 330 at Duke University, due on November 18, 2024. It includes guidelines on how to approach homework problems, typesetting and submission requirements, collaboration policies, and grading criteria. Additionally, the document presents four specific problems related to algorithms, including flow cycles, curriculum requirements, matrix rounding, and traffic flow optimization.

Uploaded by

benmatz132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

HW8 Handout

This document outlines the homework assignment for CompSci 330 at Duke University, due on November 18, 2024. It includes guidelines on how to approach homework problems, typesetting and submission requirements, collaboration policies, and grading criteria. Additionally, the document presents four specific problems related to algorithms, including flow cycles, curriculum requirements, matrix rounding, and traffic flow optimization.

Uploaded by

benmatz132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CompSci 330 Design and Analysis of Algorithms

Homework 8, Fall 2024 Duke University

TODO: Add your name(s) here

Due Date: November 18, 2024

How to Do Homework. We recommend the following three step process for homework to help
you learn and prepare for exams.
1. Give yourself 15-20 minutes per problem to try to solve on your own, without help or external
materials, as if you were taking an exam. Try to brainstorm and sketch the algorithm for
applied problems. Don’t try to type anything yet.
2. After a break, review your answers. Lookup resources or get help (from peers, office hours,
Ed discussion, etc.) about problems you weren’t sure about.
3. Rework the problems, fill in the details, and typeset your final solutions.

Typesetting and Submission. Your solutions should be typed and submitted as a single pdf on
Gradescope. Handwritten solutions or pdf files that cannot be opened will not be graded. LATEX1
is preferred but not required. You must mark the locations of your solutions to individual problems
on Gradescope as explained in the documentation. Any applied problems will request that you
submit code separately on Gradescope to be autograded.

Writing Expectations. If you are asked to provide an algorithm, you should clearly and unam-
biguously define every step of the procedure as a combination of precise sentences in plain English
or pseudocode. If you are asked to explain your algorithm, its runtime complexity, or argue for
its correctness, your written answers should be clear, concise, and should show your work. Do not
skip details but do not write paragraphs where a sentence suffices.

Collaboration and Internet. If you wish, you can work with a single partner (that is, in groups
of 2), in which case you should submit a single solution as a group on Gradescope. You can use
the internet, but looking up solutions or using LLMs is unlikely to help you prepare for exams. See
the homework webpage for more details.

Grading. Theory problems will be graded by TAs on an S/I/U scale. Applied problems typically
have a separate autograder where you can see your score. See the course policy webpage for details
about homework grading.

1
If you are new to LATEX, you can download it for free at latex-project.org or you can use the popular and free (for
a personal account) cloud-editor overleaf.com. We also recommend overleaf.com/learn for tutorials and reference.

1
Problem 1 (Flow Cycles). Let G = (V, E) be a directed graph with n = |V | vertices and
m = |E| edges. Let s, t be two distinct vertices in G, and let c : E → Z≥0 be an edge capacity
function such that each edge capacity is a non-negative integer, i.e., c(u → v) ≥ 0 is the (integer)
capacity of the edge u → v. Let f : E → Z≥0 be a (s, t)-flow function in G in which one of the
edges v → s ∈ E entering the source vertex s has f (v → s) = 1. Assume that f has non-negative
flow value.
(a) Prove that there must exist another (s, t)-flow f ′ : E → Z≥0 with f ′ (v → s) = 0 and |f | = |f ′ |
(that is, having the same (s, t)-flow value).
(b) Given f , describe an O(m) runtime algorithm to compute f ′ . Briefly explain why the al-
gorithm is correct, referencing the proof of existence from the previous part. Analyze the
runtime of your algorithm.

2
Problem 2 (New Curriculum). The Trinity Curriculum Development Committee (TCDC)
recently submitted a new curriculum, which was approved by the Arts & Sciences Council. The
new curriculum requires a student to take a number of classes ri from m different categories Gi in
order to graduate. Let n be the number of courses.
For example, suppose there are n = 5 courses A, B, C, D, E and m = 2 categories:
• You must take at least r1 = 2 courses from the subset G1 = {A, B, C}.
• You must take at least r2 = 2 courses from the subset G2 = {C, D, E}.
Then a student who has only taken courses B, C, D cannot graduate, but a student who has taken
either A, B, C, D or B, C, D, E can graduate.
Describe and analyze an algorithm to determine whether a given student can graduate. The input
to your algorithm is the list of the m categories (each specifying a subset Gi of the n courses and
the number of courses ri that must be taken from that subset) and the list of courses that the
student has taken. Justify the correctness of your reduction and analyze the runtime.

3
Problem 3 (Matrix Rounding) Suppose we are given an array A[1..m][1..n] of non-negative
numbers that are not integers. We want to round A to an integer matrix, by replacing each entry
x in A with either ⌊x⌋ or ⌈x⌉, without changing the sum of entries in any row or column of A. For
example:
   
1.3 3.3 2.4 1 4 2
3.8 4.1 2.1 → 4 4 2
7.9 1.6 0.5 8 1 1

a. Describe and analyze an efficient reduction-based algorithm that either rounds A in this
fashion, or reports correctly that no such rounding is possible. Justify that your algorithm is
correct, and analyze the runtime. [Hint: There is a correct reduction involving a flow network
with one vertex per row and one vertex per column, plus O(1) more total.]
b. Justify that a matrix can be rounded if and only if the sum of entries of each column is
an integer and the sum of entries of each row is an integer. Note that this result is not an
immediate consequence of part (a)! Part (a) states it is possible to compute a solution when
one exists, whereas this part asks you to characterize exactly when they do exist (and thus
for what kind of inputs your algorithm will report one).
[Hint: Consider a particular fractional flow on your graph. Recall properties of flow networks
with integer capacities.

4
Problem 4 (Applied) You are a city planner trying to optimize traffic flow in the city’s trans-
portation network. Imagine a city with a complex network of roads and highways but with only one
entry point s and one exit point t. You are asked to increase the traffic capacity driving from s to t
but are only allotted with the money to widen one road such that its capacity would increase.
Assume now the city road map is converted into a directed graph (not necessarily acyclic) with
nodes labeled as integers and with non-negative integer capacities on the edges. Your function will
take in two parallel lists edges and capacities, where each edge is a tuple. For example, (2, 4) is an
edge that goes from starting node 2 to destination node 4. You are also given the label of a source
vertex and a target vertex.
We say that an edge is a priority edge for routing traffic flow from source s to target t if increasing
the capacity on that edge by 1 (with no other changes to the graph) would increase the value of
the maximum flow from s to t.
Given the above inputs, you should design and implement an algorithm that returns a
list of all priority edges in the graph (or an empty list if there are none). The list can
be in any order. For full credit, your solution will need to have an empirical runtime that is within
constant factors of running Ford-Fulkerson using BFS.2
[Hint: Recall the correspondence between the value of a maximum (s, t)-flow and the capacity of a
minimum (s, t)-cut.
Language-specific details follow. You can use whichever of Python or Java you prefer. You will
receive automatic feedback when submitting, and you can resubmit as many times as you like up
to the deadline.
• Python. You should submit a file called flow.py to the Gradescope item ”Assignment 6
- Applied (Python).” The file should define (at least) a top level function find edges that
looks like:
– def find_edges(edges:[(u:int,v:int)], capacities:[int], s:int, t:int)
and returns a list of tuples (u,v) that are priority edges or an empty list []
• Java. You should submit a file called Flow.java to the Gradescope item ”Assignment 6 -
Applied (Java).” The file should define (at least) a top level function findEdges that looks
like:
– public List<int[]> findEdges(int[][] edges, int[] capacities, int s, int t)
where edges is a 2D array where edges[i] is an edge from edges[i][0] to edges[i][1]
and capacities[i] is the capacitiy of edges[i]. Return either a list of edges or an empty
list []

2
Picking the shortest augmenting path in Ford-Fulkerson is known as the Edmonds-Karp algorithm, who showed
it runs in min{m min{|f ∗ |, n2 }) time.

You might also like