Final 2013 - McMaster CAS Dept.

COMP SCI / SFWR ENG 4O03 / 6O03: McMaster University Final Exam - Day Class
December 17, 2013 (Instructor: Antoine Deza)
DURATION OF THE EXAM: 3 hours - 40 points
Name:
Student Number:
This examination paper includes 2 pages and 6 problems. You are responsible for ensuring that your copy of the
paper is complete. Bring any discrepancy to the attention of your invigilator. McMaster standard (Casio FX-991)
calculator allowed. One letter-size sheet (both sides) of your hand-written notes allowed.
** justify your answers **
Problem 1
Prove or disprove each of the following claims:
(a) Let G be a simple connected directed graph with distinct edge weights and without a negative-weight
cycle, Dijkstra’s algorithm always gives a correct answer.
3p
(b) Let G be a simple connected undirected graph; no maximum-weight edge of a cycle of G can be in
the minimum spanning tree of G.
3p
(c) Let G be a simple connected undirected graph with distinct edge weights and an even number of
cycles; the minimum spanning tree of G is unique.
3p
Problem 2
Given a positive integer n, we consider the following problem: Making change for n cents using the fewest
number of coins. Assume that the value of each coin is a positive integer.
(a) Describe a greedy algorithm to make change consisting of quarters (25 cents), dimes (10 cents),
nickels (5 cents) and pennies (1 cent). Prove that your algorithm yields an optimal solution to the
given make change problem.
3p
(b) Suppose that the available coins are in the denominations that are powers of c; that is, the denominations are c0 , c1 , . . . , ck for some integers c > 1 and k ≥ 1. Show that the greedy algorithm always
yields an optimal solution to the given make change problem.
3p
(c) Give a a positive integer n and a set of coin denominations for which the greedy algorithm does not
yield an optimal solution to the given make change problem. Your set should include a penny so
that there is a feasible solution for every value of n.
3p
Problem 3
We consider the following knapsack problem:
max
7x1 + 4x2 + 8x3 + 9x4
3x1 + 3x2 + 5x3 + 7x4 ≤ 13
(a) Use dynamic programming to solve the problem for xi ∈ {0, 1} (including the optimal solution and
the optimal value).
3p
(b) Use dynamic programming to solve the problem for xi ∈ {0, 1, 2, . . . } (including the optimal solution
and the optimal value).
3p
*** CONTINUED ON NEXT PAGE ***
Problem 4
Find the shortest path from vertex 1 to vertex 3 in the following graph using Dijkstra’s algorithm. Justify
your answer by showing the steps of Dijkstra’s algorithm.
4p
Problem 5
We consider the optical fiber network between 7 Canadian cities: B, C, D, E, F, G, H. The capacity of
the corresponding 13 optical cables between a pair of connected cities is: 40 GB/s (respectively 20, 5, 18,
5, 10, 15, 8, 20, 5, 20, 15, and 30) for B − C (respectively B − D, B − E, C − E, C − F , D − E, D − F ,
D − H, E − F , E − G, F − G, F − H, and G − H). The cities B and C are in Alberta, the cities G and
H are in Ontario, and the cities D, E and F are in Manitoba. We want to know the maximum upload
speed from Alberta to Ontario.
(a) Model the problem as a maxflow problem, and solve it using any method,
4p
(b) Assume, in addition, that the total (upload and download combined) processing power of F (that
is: the capacity of F ) is 70 GB/s. Model the problem as a maxflow problem, and solve it using any
method.
3p
Problem 6
We consider the following linear program (LP):
max
x1 + x2 + x3 + x4 + x5 + x6
0 ≤ x1 + x2 + x4 ≤ 2
0 ≤ x1 + x3 + x5 ≤ 2
0 ≤ x2 + x3 + x6 ≤ 2
0 ≤ x4 + x5 + x6 ≤ 2
(a) Show that the feasible region is unbounded by providing a point p and a vector d such that the
point p + λd is feasible for any λ ≥ 0
2p
(b) Find an optimal solution for the linear program (LP) – justify your answer.
(Note that questions (a) and (b) can be solved independently)
*** END OF EXAM ***
3p