Solutions to Practice Midterm for CMPSCI 611, Fall 2005
Questions in black, solutions in blue.
Q1: 20 points Q2: 25 points Q3: 15 points Q4: 20 points Q5: 20 points
This is not a matroid in general, though it is a subset system.
The easiest way to show this is to give
an example where there are two maximal independent sets of different sizes,
so that neither the Exchange Property or the Cardinality Property hold.
Let G be a graph with four vertices {a,b,c,d} and five edges, all but
(a,d). The set of edges {(a,b), (b,c), (c,d)} and {(a,b), (a,c), (b,d), (c,d)}
are each maximal independent because neither has a triangle but
adding any edge of E to either creates a triangle. These two sets have
different sizes.
This is also a subset system but not a matroid. We find a counterexample to the cardinality property as in (a). We can actually use the same graph, renaming a as s and d as t. Then either of the two triangles are maximal independent sets, as is {(s,b), (c,t)}, because they do not have paths from s to t but any new edge creates such a path. There are maximal independent sets of size 2 and of size 3, so this is not a matroid.
Replace each vertex v of G, other than s and t, with two vertices v and v'.
Edges of G into its v still go into the new v, but edges out of v in G now come
out of v'. We make an edge of capacity 1 from v to v', and leave all other
capacities the same (1).
Now suppose there is a flow of size k in N'. As in N, this can be written as
the sum of k edge-disjoint paths. But no two paths could use the same
vertex v (other than s or t) because then both would have to use the only edge
out of v in N', to v', and it has capacity only 1.
If we have k vertex-disjoint paths from s to t in G, we make a flow in N'
in the obvious way. For each v that a path uses other than s or t, we route the
flow across the edge from v to v', and the capacity of 1 lets us do this.
N'' is just like n except that the edge from v to v' in N'' has capacity h(v). Then a flow through N'' must have some flow x across the edge from v to v', and therefore uses x edges into v and x edges out of v' (since all those edges have capacity 1). When we write the flow as the sum of k paths, exactly x of these paths in G use the vertex v, and x ≤ h(v) because of the capacity constraint on the edge in N'' from v to v'.
Replace each edge of capacity k in G by a path of k edges in H, introducing k-1 new vertices for the intermediate vertices in this path. H may then have as many as n + e(n-1) = O(ne) vertices and e + n(e) = O(ne) edges. The breadth-first search will take time proportional to the number of edges in H, which is O(ne). Dijkstra's algorithm took O(ne) by the most naive implementation of the priority queue, but O(e log n) if we used simple heaps. So Dijkstra is faster asymptotically.
Let G be the labeled graph that is the diagram of the NFA, where the edge (i,j) is labeled with the set Aij. By the Path-Matrix Theorem, this entry is the "sum", over all paths in G, of the "product" of the entries along the path. Along a given path, when we take the concatenation of the sets for each edge in order, we get a set of strings of length k where the i'th letter of each string is taken from the set for the i'th edge of the path. This is exactly the set of strings of length k that the NFA could read while taking that path. The union over all paths is the set of strings of length k that the NFA could read while moving from state i to state j. This set of strings is the value of the (i,j) entry of Ak.
Raising an n by n matrix to the k'th power takes O(n3log k)
operations on individual entries by standard matrix multiplication. (And
we have no subtraction available with which to use Strassen or other methods.)
An operation on the entry involves unioning or concatenating sets of strings,
which are linear-time operations in the number of strings in the result.
How large could one of these sets be?
The worst case would be if all strings of length k were in the result.
There are |Σ|k strings of length k, so our bound on the
total running time is O(n3(log k)|Σ|k). The only
way this is polynomial in k is if Σ is a one-letter alphabet.
I see I've answered the wrong question here! The space is what
I asked about, and what we need is the space to hold O(n2) matrix
entries. By the discussion above, one matrix entry might need
|Σ|k bits, if we do the simplest thing and use a bitvector
to say whether each of the possible strings is in the set. This makes the
total space O(n2|Σ|k), which is polynomial in n
but is exponential in k unless Σ has only one letter.
This is very similar to the CKY algorithm for determining whether a string
is in a given context-free language. For each i and j with
1 ≤ i ≤j ≤n, and each element a of G, we define a boolean variable
A(i,j,a) that is true iff it is possible to multiply the elements wi
through wj to get the result a. We then evaluate each of these
O(k2n) booleans by dynamic programming, computing then in increasing
order of the parameter j-i.
We first calculate all the kn values A(i,i,a), which take only O(1) time
each because we just need to look up whether wi is equal to a.
Now assume that we have already calculated A(i,j,a) for every i and j with
j-i ≤ t, and fix a particular i and j with j-1 = t+1. For each a, the
boolean A(i,j,a) is true iff there exists a number k such that:
Searching for this situation with a simple loop takes O(kn2)
time to compute each entry, making our time O(k3n3)
in all. Depending on the relationship between n and k, there are better ways
to go about it -- for example, if n is large we might want to precompute the
set of (b,c) pairs with bc=a for each a.
Last modified 24 October 2005