CIS 502 - Algorithms
Fall 2015 Homework 4 2
3
Problem 1 Problem 13, page 324, of textbook.
Solution: This is an example where it is easier to reduce the problem to a known dynamic
programming problem than give a solution from scratch. There are not many s
CIS502 - HW5
Model Solutions
Problem 6.5
Define OP T [j] to be the optimal quality for y1 . . . yj . Let quality[i, j] denote the quality of the
word yi . . . yj . Then
OP T [j] = max OP T [i] + quality[i + 1, j]
0<i<j
Set OP T [1] = quality[1, 1].
Return
CIS 502 - Algorithms
Fall 2015 Midterm 2
Problem 1:(30 points) Given n numbers x1 , . . . , xn , the numbers xi1 , xi2 , . . . , xik define a subsequence if 1 i1 < i2 < < ik n. Length of the subsequence xi1 , xi2 , . . . , xik is k. For example
given 1.1,
CIS 502 - Algorithms
Fall 2016 Homework 7
Due Nov 4th. We will upload the solutions to Canvas on Nov 5th.
You can collaborate with anyone with this homework. Please submit one copy of the answer between
all your collaborators.
However do remember that thi
CIS 502 - Algorithms
Fall 2016 Homework 7 Solutions
Problem 1 Problem 22, page 428, of textbook.
Solution: An example for part (a) is:
1 1 1
1 0 0
1 0 0
For part (b), we construct a bipartite graph (L, R, E) where the set L corresponds to the
columns or p
CIS 502 - Algorithms
Fall 2016 Homework 6 Solutions
Problem 1 Problem 19, page 329, of textbook.
Solution: Let F easible[i, a, b] be a boolean variable indicating if it is feasible to express s1 , . . . , si
(the first i bits of s) as an interleaving of x
CIS502 - HW2
Model Solutions
Problem 3.4
Algorithm
Construct a graph by making each butterfly a node. Draw an edge between
them if the label is either same or different. Label these edges as either S
for same or D for different. Run BFS from an arbitrary
502Midterm2Review
I.
NP
NP-hard vs. NP vs. NP Complete
Satisfiable vs. Unsatisfiable
Map Reduction vs. Turing Reduction
SAT problem
3SAT Problem
Coloring problem:
2-Color Bipartite
3-Color 3SAT
4+-Color (-1)-Color
Vertices Cover Problem:
Subset Sum Proble
CIS 502 - Algorithms
Fall 2014 Midterm 2
Problem 1:(45 Points)
Suppose that we are given a directed graph G = (V, A) where arc (i, j) has weight wij which
can be either negative or positive. We are also given a special node s.
(a) (15 points) Suppose that
CIS 502 - Algorithms
Fall 2014 Short Answers
Problem 1: (20 Points) You are given an array A[1], . . . , A[n] which contain both negative and
positive values. Assume A[0] = A[n + 1] = 0.
(a) (10 points) Find an interval [i, j] such that j A[t] is maximize
Pseudocode 101
What is pseudocode? Pseudocode is a simplied, half-English, half-code outline of a computer program.
Why use it?
Because it can help you to clarify your thoughts, and design a routine properly, before
you start to write any code.
One of th
204
Chapter 4 Greedy Algorithms
We are given a set X V of k terminals that must be connected by
edges. We say that a Steiner tree on X is a set Z so that X Z V, together
with a spanning subtree T of G[Z]. The weight of the Steiner tree is the
weight of th
CIS502 - HW3
Model Solutions
Problem 4.7
Run the jobs by decreasing fi (job with the largest fi is scheduled first). The time to generate the
schedule is O(n log n), the time required to sort a list of n numbers.
To prove optimality, we use an exchange st
CIS502 - HW1
Model Solutions
Problem 1.5
There always exists a perfect matching with no strong instabilities. A simple
algorithm is to modify the preference list to break ties arbitrarily. If m has no
preference between wi and wj with i < j, modify the pr
CIS502 - HW4
Model Solutions
Problem 5.2
The solution to this problem is very similar to one of nding the number of inversions as discussed
in class. In this algorithm, we count an inversion when an element from the left side must go to
the right side. In
Suppose m n, and let L denote the maximum length of any string in A B . Suppose
there is a string that is a concatenation over both A and B , and let u be one of minimum
length. We claim that the length of u is at most n2 L2 .
For suppose not. First, we s