0% found this document useful (0 votes)
10 views6 pages

HW9 Handout

This document outlines Homework 9 for CompSci 330 at Duke University, due on December 3, 2024. It includes a recommended three-step process for completing the homework, typesetting and submission guidelines, writing expectations, collaboration rules, and grading criteria. Additionally, it presents four problems related to algorithm design, including the Kite problem, Contracts problem, Cycle Interrupting problem, and an applied problem involving DroneFrequency.

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)
10 views6 pages

HW9 Handout

This document outlines Homework 9 for CompSci 330 at Duke University, due on December 3, 2024. It includes a recommended three-step process for completing the homework, typesetting and submission guidelines, writing expectations, collaboration rules, and grading criteria. Additionally, it presents four problems related to algorithm design, including the Kite problem, Contracts problem, Cycle Interrupting problem, and an applied problem involving DroneFrequency.

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/ 6

CompSci 330 Design and Analysis of Algorithms

Homework 9, Fall 2024 Duke University

TODO: Add your name(s) here

Due Date: Tuesday, December 3, 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 (Kite). A kite is a graph on an even number of vertices, say 2n, in which n of the
vertices form a clique and the remaining n vertices are connected in a “tail” that consists of a path
joined to one of the vertices of the clique. An example of a kite with 6 vertices is diagrammed
below.

Given a graph and a goal g, the Kite problem asks whether there is a subgraph which is a kite
and which contains 2g nodes. Prove that Kite is NP-complete. Your reduction may be from any
problem covered in lecture or recitation stated to be NP-hard.

2
Problem 2 (Contracts). You work for a company that takes consulting jobs but has more con-
tracts on offer than they can manage. Specifically, you have n contract offers numbered 1, 2, . . . , n,
each of which earns a value of vi dollars and requires a work time of wi person-hours. Given these,
a financial goal g, and a time bound t, the Contracts P problem asks whether there is a set of
contracts
P C with total work time at most t (that is, i∈C wi ≤ t) and value at least g (that is,
v
i∈C i ≥ g).
For example, if the following three contracts are available, then given t = 10 and g = 600, the
answer would be true, because choosing contracts 1 and 2 would suffice. However, if t = 10 but
g = 700, the answer would be false because no set of contracts with total work time at most 10
gets total value at least 700.

Contract (i) Value vi Work wi


1 200 4
2 400 5
3 500 9

Prove that this problem is NP-complete. Your reduction may be from any problem covered in
lecture or recitation stated to be NP-hard.

3
Problem 3 (Cycle Interrupting). Let G = (V, E) be a connected undirected graph. Say that
a subset of vertices I ⊆ V is called cycle interrupting in G if every cycle in G contains at least
one vertex of I. For example, in the graph below, the dashed vertices 1 and 4 constitute a cycle
interrupting set of size 2.

1 3 5

2 4 6

The Cycle Interrupting problem asks, given an undirected graph G and an integer k as input,
whether G contains a cycle interrupting set of size at most k. Prove that this problem is NP-
complete. Your reduction may be from any problem covered in lecture or recitation stated to be
NP-hard.

4
Problem 4 (Applied) The DroneFrequency problem is as follows: You are tasked with
designing a signal coordination system for a fleet of drones. Each drone operates in a circular patrol
zone. Two drones whose patrol zones intersect cannot use the same communication frequency to
avoid signal interference. There are three available frequencies, denoted as F1 , F2 , F3 . Given the
pairs of drones whose zones intersect, the goal is to determine whether it is possible to assign each
drone of the three frequencies without violating the closeness constraint.
It can be shown that DroneFrequency is NP-Complete, though that is not the purpose of this
applied problem. The underlying structure of problem is common in the real world: assign few
resources to all entities subject to pairwise constraints. Thus we desire solving this problem and
others that are NP-hard, even if we expect the asymptotic runtime of our algorithm to be worse than
polynomial. As we have throughout the entire course, instead of designing a new algorithm from
the ground up, we reduce a given problem to another for which results are already known.
3-SAT, and the more general SAT problem (determine if a Boolean formula with n variables and m
operations has a satisfying assignment), have been studied extensively since the 60s, with the aim
of describing algorithms that are efficient in practice, even in light of the reasonable assumption
that no worst-case polynomial-time algorithm exists (i.e., P ̸= NP). See the Wikipedia page on
SAT solvers for more information2 . Thus, for this problem, you will implement a polynomial-time
reduction from DroneFrequency to 3-SAT. The implementation details are as follows.
A 3-SAT instance is a Boolean formula Φ that is the conjunction of clauses with at most three
literals each. For example,

Φ = (x1 ∨ x2 ∨ x3 ) ∧ (x2 ∨ x3 ∨ x4 ) ∧ (x4 ∨ x2 )

is a valid 3-SAT instance; in fact, Φ is a YES instance since it has a satisfying assignment: x1 = T ,
x2 = F , x3 = T , x4 = F . We represent a Boolean function as follows: The literals xi and xi are
each represented by i and −1, respectively, and each clause is represented as an array of at most
three integers. For example, the formula Φ above is represented by array

[ [1, 2, −3], [−2, 3, 4], [−4, −2] ].

Towards obtaining a SAT-solver-based algorithm for DroneFrequency, you will implement an ef-
ficient reduction to 3-SAT: Your task is to implement a O(n + m)-time algorithm that, given a
number of drones n and a list m of pairs of drones whose zones intersect, construct a boolean
formula Φ (using the integer representation above) that is satisfiable if and only if there is a valid
assignment of frequencies to the drones. For full credit, your solution will need to have an empirical
runtime that is within constant factors of an O(n + m)-time implementation. (As a consequence,
your formula should have size O(n + m).)
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 drones.py to the Gradescope item ”Assignment
9 - Applied (Python).” The file should define (at least) a top level function reduce to 3sat
that looks like:
2
In particular, see the Davis-Putnam-Logemann-Loveland (DPLL) algorithm for an elegant (worst-case
exponential-time) algorithm for SAT from 1961. Some Duke trivia: Loveland is Professor Emeritus here and was
Prof. Owen Astrachan’s PhD advisor.

5
def reduce_to_3sat(n:int, pairs:[(u:int,v:int)])
that returns an integer-representation of a Boolean formula corresponding to the input as
described above, where the drones in the pairs are represented by integers 0 to n − 1.
• Java. You should submit a file called Drones.java to the Gradescope item ”Assignment 9
- Applied (Java).” The file should define (at least) a top level function reduceTo3SAT that
looks like:

public List<int[]> reduceTo3SAT(int n, int[][] pairs)

where pairs is a 2D array such that, for all i, pairs[i] is a 2-length array such that
pairs[i][0] and pairs[i][1] are integers between 0 to n − 1 that represent drones too
close to be assigned the same frequency. The method should return an integer-representation
of a Boolean formula corresponding to the input as described above.

You might also like