- Answer the problems on the exam pages.
- There are seven problems (some with multiple parts) for 100 total points. Actual scale was A = 93, C = 63.
- If you need extra space use the back of a page.
- No books, notes, calculators, or collaboration.

Q1: 10 points Q2: 10 points Q3: 10 points Q4: 10 points Q5: 20 points Q6: 20+10 points Q7: 10 points Total: 100+10 points

Question text is in black, solutions in blue

For Questions 1-4, the graph G has node set {a, b, c, d, e, f} and nine edges: (a, b), (a, c), (a, d), (b, c), (b, e), (c, f), (d, e), (d, f), and (e, f). Recall that "graph" refers to an undirected graph with no self-loops.

**Question 1 (10):**Find a graph with six nodes and nine edges that is*not*isomorphic to G. Prove that the two graphs are not isomorphic.The easiest solution to this is to choose any such graph with a degree sequence different from G's which is (3, 3, 3, 3, 3, 3). For example, you could have an isolated node and nine of the ten edges involving the other nodes, which has degree sequence (5, 5, 5, 4, 4, 0). Isomorphic graphs must have the same degree sequence.

Several people chose a graph with the same degree sequence, the complete bipartite graph K

_{3,3}. There are a number of ways to show that this graph is not isomorphic to G: it is bipartite while G contains triangles, and it is non-planar (proved in lecture or by quoting Kuratowski's Theorem) while G is planar (by Question 2).**Question 2 (10):**Is G a planar graph? Prove your answer. What is the number of regions in a planar embedding of H, given by Euler's Formula?G is planar, as is easily shown by giving a planar embedding. We can start with the Hamilton circuit a-b-e-f-c-a and place the edges (b, c) and (c, f) inside it and the edge (a, d) outside it. Euler's formula is V - E + F = 2, so since V = 6 and E = 9, F must be 5. The faces of the planar embedding given above are a-b-c, b-e-f-c, d-e-f, a-c-f-d, and the exterior face a-b-e-d.

**Question 3 (10):**Does G have an Euler path and/or Euler circuit? Does H have a Hamilton path and/or Hamilton circuit? Justify your answers.G has six odd-degree nodes, so it cannot have an Euler circuit (which would require none) or an Euler path (which would require two). It has the Hamilton circuit listed in Question 2 above, and deleting any single edge of this circuit gives a Hamilton path.

**Question 4 (10):**What is the chromatic number of G? Prove your answer. (The chromatic number is defined to be the "vertex-chromatic" rather than the "edge-chromatic" number.)G has a chromatic number of 3. A legal 3-coloring could have a and e red, b and f blue, and c and d green. There can be no 2-coloring because G contains several odd cycles, such as a-b-c-a.

**Question 5 (20):**For this problem we will assume that the HAM-CIRCUIT problem is NP-complete, meaning that if there is a polynomial-time algorithm that inputs a graph and decides whether it has a Hamilton circuit, then P = NP. Here are two questions about related problems:- (a, 10) The HAM-PATH problem is to input a graph and decide
whether it has a Hamilton path. Prove that if there is a
polynomial-time
algorithm for HAM-PATH, then P = NP. (You may use the assumption
about HAM-CIRCUIT. Hint (corrected): Apply the HAM-PATH tester to
a different graph.)
I had actually intended to ask the easier problem of building a circuit tester with a path tester -- for this you build G' by adding a new node with edges to all the nodes of G, and note that G' has an H-circuit if and only if G has an H-path.

For the problem as posed, one solution uses the path tester to tell whether there is a circuit in G that contains a fixed edge (x, y). To do this we build G' by adding a new node x' with an edge only to x, and a new node y' with an edge only to y. Then if G' has an H-path, it goes from x' to y', and G contains an h-path from x to y that can be extended to a circuit. To test whether G has

*any*H-circuit, we run this "circuit containing (x, y)" test separately either (1) for every edge (x, y) in G, which is O(n^{2}) tests, or (2) for every edge (x, y) in G where x is any fixed node, which is O(n) tests. Clearly this is polynomial time if the assumed H-path tester is polynomial time. So if the path-tester exists, the polynomial-time circuit-tester exists and P = NP.A more elegant solution (which a student in COMPSCI 311 came up with when this problem was posed there) takes G and builds a single graph G' that has an H-path if and only if G has an H-circuit. Take any node x of G and "clone" it, making two nodes x and y that each have edges to exactly the neighbors of x in G. Then add a node x' with an edge only to x, and a node y' with an edge only to y. Any H-path in G' must go from x' to y' and thus include a path from x to y, which corresponds to an H-circuit in G.

- (b, 10) The LSP (Longest Simple Path)
problem is to input a
graph G and a number k, and decide whether G contains a simple
path of k or more edges. (A simple path is one that never re-uses
a node.) Prove that if there is a polynomial-time algorithm for
LSP, then P = NP. You may use the assumption about HAM-CIRCUIT
and the result of part (a), whether you solved part (a) or not.)
This is very easy given part (a), because a graph has an H-path if and only if it has a simple path with n-1 edges. (Such a path must visit all n vertices, which makes it a Hamilton path.) So if we have the LSP tester, we input the pair (G, n - 1) to it and report the result as that of our path-tester. Thus if the polynomial-time LSP tester exists, so does a poly-time H-path tester and thus (by part (a)) a poly-time H-circuit tester and (by the assumption) P = NP.

- (a, 10) The HAM-PATH problem is to input a graph and decide
whether it has a Hamilton path. Prove that if there is a
polynomial-time
algorithm for HAM-PATH, then P = NP. (You may use the assumption
about HAM-CIRCUIT. Hint (corrected): Apply the HAM-PATH tester to
a different graph.)
**Question 6 (20+10):**In this problem we consider distributing n identical treats to four distinguished dogs: Ali (a), Bingley (b), Cardie (c), and Duncan (d), where*each dog receives at least one treat*. Let f(n) be the number of such distributions.- (a, 10) Prove that for any n, f(n) is equal to the number
of strings of length n - 4 over the alphabet {a, b, c, d}, where
the individual letters come in alphabetical order. (That is,
all the a's come before all the b's, the b's before the c's, and
the c's before the d's. Another way to say this is to say that
the string must be in the regular language
a
^{*}b^{*}c^{*}d^{*}.)We need a bijection from distributions of treats to strings. If a distribution sends w treats to Ali, x to Bingley, y to Cardie, and z to Duncan, our string will be a

^{w-1}b^{x-1}c^{y-1}d^{z-1}. This string has length n-4 because w + x + y + z = n, and clearly the letters are in alphabetical order. Given a string a^{w}b^{x}c^{y}d^{z}, with w + x + y + z = n - 4, we can give w + 1 treats to Ali, x + 1 to Bingley, y + 1 to Cardie, and z + 1 to Duncan, distributing n treats with at least one to each dog as w, x, y, and z are all non-negative integers. - (b, 10) Using part (a) or otherwise, find a formula for
f(n) as a function of n. You may use ordinary arithmetic
operations, the factorial operation, and the binomial
coefficient operator C(x, y). Evaluate your formula for n = 3,
n = 5, n = 7, and n = 9.
The strings can be counted by the standard "stars and bars" argument. We have n-4 letters (stars) and three barriers between letter types (bars) which can be arranged in C(n-1, 3) ways. Then for n = 3 we have C(2, 3) = 0, for n = 5 we have C(4, 3) = 4, for n = 7 we have C(6, 3) = 20, and for n = 9 we have C(8, 3) = 56.

- (c, 10XC) Find the number of ways to distribute 13
treats to the four dogs such that each dog gets at least one
treat and no two dogs get the same number of treats. (As
before, the treats are identical and the dogs are distinguished.)
If the dogs were also identical, we would be looking for a partition of 13 into four non-negative, distinct parts, or equivalently a partition of 9 into four distinct parts. There are exactly three such partitions, and I required you to argue that they were the only ones. Looking at 13, we can divide into cases depending on the largest element of the partition. This cannot be greater than 7 because the other three elements must be at least 1, 2, and 3 respectively. If it is 7, we must have 7-3-2-1. If it is 6, we must have 6-4-2-1, and if it is 5, we must have 5-4-3-1. It cannot be 4 because the only way to have distinct positive parts would be 4-3-2-1 which has too small a sum.

Once we have solved this problem, the answer to the given problem is 4! = 24 times greater, because each distribution to identical dogs corresponds to exactly 4! distributions to distinguished dogs. So the answer is 3 times 4! or 72.

Many of you started with the n = 13 case of part (b), which is C(12, 3) = 220 distributions, and tried to subtract the ones that had two or more dogs getting the same number of treats. I don't recall whether anyone got the right answer this way, but several of you were at least close. There are four partitions of 13 with exactly three equal elements: 10-1-1-1, 7-2-2-2, 4-3-3-3, and 4-4-4-1. Each of these gives four distributions to distinguished dogs, so we subtract 16 from our original 220. Then we look at all the partitions with exactly two equal elements, which we can find by a case analysis on the pair: 9-2-1-1, 8-3-1-1, 7-4-1-1, 6-5-1-1, 8-2-2-1, 6-3-2-2, 5-4-2-2, 6-3-3-1, 5-3-3-2, 4-4-3-2, and 5-5-2-1, eleven in all. Each of these yields twelve distributions to distinguished dogs, so we subtract 132 from our remaining 204 to get 72. There are no partitions of 13 with either four equal elements or two pairs of equal elements, so we have checked all the cases where any elements are equal.

- (a, 10) Prove that for any n, f(n) is equal to the number
of strings of length n - 4 over the alphabet {a, b, c, d}, where
the individual letters come in alphabetical order. (That is,
all the a's come before all the b's, the b's before the c's, and
the c's before the d's. Another way to say this is to say that
the string must be in the regular language
a
**Question 7 (20):**The following are ten true-false questions, with no explanation needed or wanted, and no penalty for guessing. They count two points each. Some of the problems use the graph G with the following weights on the edges: (a, b, 1), (a, c, 1), (a, d, 1), (b, c, 2), (b, e, 2), (c, f, 3), (d, e, 4), (d, f, 4), and (e, f, 5).- (a) If we take an undirected tree with n nodes, and
change each edge to a pair of directed edges (in opposite
directions), then the resulting directed graph has an Euler
circuit of length 2n - 2.
TRUE. We have a strongly connected directed graph where every node has an in-degree equal to its out-degree. Every such graph has an Euler circuit, and the number of edges is 2n - 2 because the original tree had n - 1 undirected edges.

- (b) Any correct comparison-based algorithm to find the
median of n items can be interpreted as a decision tree with
at least n! leaves.
FALSE. This would be true for sorting, which has n! different possible outputs, but the median problem has only n. We discussed linear-time algorithms for median, and if this statement were true there would be an Ω(n log n) lower bound for the time.

- (c) It is not the case that every two nodes in the
weighted version of graph G are within distance 5 of one another.
FALSE. We can carry out a uniform-cost search from each node to see that every other node is within distance 5. Or we could take the 6 by 6 single-step distance matrix and square it, to see that there is a one-step or two-step path of length at most 5 between every pair of distinct nodes.

- (d) The minimum spanning tree in the weighted version
of graph G has total weight 7.
FALSE. Using Kruskal's algorithm, we take the three edges of weight 3, then the edge (b, e) of weight 2, then the edge (c, f) of weight 3, to get an MST of weight 8. (We don't take (b, c) because it would form a cycle with the already taken (a, b) and (a, c).)

- (e) Thre is a minimum spanning tree of the weighted
version of graph G that does not contain the edge (c, f).
FALSE. Kruskal's algorithm has no ties to break in choosing its first four edges above, and if it then took any other edge than (c, f) the resulting spanning tree would have total weight greater than 8.

- (f) Let H be a flow network and let (X, Y) be a
partition of the vertices of H such that the source is in X
and the sink is in Y. Let f be a flow in H such that every
edge from a vertex in X to a vertex in Y is saturated by f.
Then f must be a maximum flow.
FALSE. There could be an edge from a node in Y to a node in X, with positive flow under f, such that we could increase the net flow over f's by decreasing the flow on this edge.

- (g) Let H be a flow network and let f be a flow in H
such that for every vertex x in H except for the sink, there is
at least one edge out of x that is not saturated by f. Then f
cannot be a maximumm flow.
FALSE. Here's a counter example, where each edge has first its capacity and then its flow under the maximum flow f. Source is a and sink is z. We have (a, b, 2, 1), (b, c, 1, 0), (b, e, 1, 1), (c, d, 1, 0), (d, b, 1, 0), and (e, 2, 1, 0). The only saturated edge is (b, e), and since this edge forms a cut by itself the flow is maximum. But there is at least one other unsaturated edge out of each node, except for z.

- (h) Let B be a bipartite graph, with n nodes in a set
X, n nodes in a set Y, and every edge with one endpoint in X
and the other in Y. There are n! bijections from X to Y, any
of which might be a perfect matching in B. Tucker presents no
method for finding a perfect matching in B that is
substantially faster than trying all n! of these bijections.
FALSE. Tucker discusses finding a perfect matching in a bipartite graph by using the polynomial-time network flow algorithm, which is much faster than trying each of the exponentially many bijections.

- (i) The number of anagrams of the work RHINOCEROS is
C(10, 2) times C(8, 2).
FALSE. That is the number of ways to place the two R's and then the two S's. But for each such placement there are 6! total anagrams by placing the other six letters in the six remaining positions.

- (j) The sum for i from 1 to n of C(n, i) is 2
^{n}.FALSE. It is 2

^{n}- 1. The sum from 0 to n of C(n, i) is 2^{n}.

- (a) If we take an undirected tree with n nodes, and
change each edge to a pair of directed edges (in opposite
directions), then the resulting directed graph has an Euler
circuit of length 2n - 2.

Last modified 14 November 2018