You are on page 1of 4

COMPSCI 4O03/6O03 - SFWRENG 3O03/4O03: McMaster University FINAL EXAM

(Day Class) December 21, 2015 (Instructor: Antoine Deza)


SOLUTIONS

Problem 1
Prove or disprove each of the following claims:

(a) Given two positive integers m and n (m n), we consider the following problem: Tiling an m n
room, using the fewest number of square tiles. A greedy algorithm, which uses the largest fitting
square tile first, yields an optimal solution to the given tiling problem.
Solution:
False. Consider m = 7 and n = 6, the greedy algorithm gives a solution of one 6 6 tile and six
1 1 tiles, using 7 tiles in total. But a better solution is one 4 4 tiles, two 3 3 tiles and two
2 2 tiles, using 5 tiles in total.

(b) Let G be a simple connected undirected graph with distinct edge weights; the second smallest weight
edge is always included in the minimum spanning tree of G.
Solution:
True. Prove by contradiction. Assume that the second smallest weight edge (u, v) is not included
in the minimum spanning tree. Add the edge (u, v) into the minimum spanning tree to form a cycle.
Then there are at least three edges in the cycle, and we can find an edge with a larger weight than
(u, v) in the cycle. Deleting that weight, we get a new minimum spanning tree which has smaller
weight than the original tree. This contradicts the fact that we had the minimum spanning tree in
the first place.

(c) There exist 7 distinct and strictly positive integers v1 , v2 , v3 , w1 , w2 , w3 , and W such that the
following 0/1-knapsack problem has 3 distinct optimal solutions :

max v1 x1 + v2 x2 + v3 x3 such that w1 x 1 + w2 x 2 + w3 x 3 W and x1 , x2 , x3 {0, 1}

Solution:
False. We can consider the 8 possible solutions and notice that only one optimal solution can
be drawn from {(1, 0, 0), (0, 1, 0), (0, 0, 1)} are otherwise two vi would be equal. Similarly only one
optimal solution can be drawn from {0, 1, 1), (1, 0, 1), (1, 1, 0)}. In addition, if (0, 0, 0) or (1, 1, 1) is
an optimal solution, then it is the unique optimal solution.

Problem 2
RentCar is developing a replacement policy for its car fleet for a 4-year planning horizon. At the start of
the first year, the RentCar must purchase a car. At the start of each of the 4 subsequent years, a decision
is made as to whether a car should be kept in operation or replaced. The car must be in service for at
least 1 year and no more than 3 years. The following table provides the replacement cost as a function of
the year when a car is acquired and the number of years in operation. The problem is to determine the
best decision that minimizes the cost incurred over the period of 4 years.

Page 1 of 2
Equipment Replacement cost ($) for given years in operation
acquired at start of year 1 2 3
1 4000 5400 9800
2 4300 6200 8700
3 4800 7100
4 4900
(a) Model this decision as a shortest path problem. Your solution should be a graph.
Solution:
Nodes 1 to 5 represent the start of years 1 to 5. The length of each arc represents the replacement
cost. The solution of the problem is equivalent to finding the shortest path between nodes 1 and 5.

(b) Solve it by using Dijkstras algorithm. Show details of each iteration in a table.
Solution:

1 2 3 4 5
0
4000 5400 9800
5400 9800 12700
9800 12500
12500

The shortest path is 1 3 5, with total cost $12500. The solution means that a car acquired at
the start of year 1 should be replaced at the start of year 3, and then the replacement car will be
kept in service until the end of year 4.

Problem 3
Given two strings x[1 . . . m] and y[1 . . . n], find a longest substring (contiguous characters) common to
both x and y. Note that this is not the same as the Longest Common Subsequence problem, in which
characters are not necessarily contiguous. As an example, say that x = tofoodie and y = toody. The
longest common substring is ood with 3 characters.
(a) Give a dynamic programming formulation of this problem. Your solution should be a dynamic
programming rule which can be used to solve the problem.
Solution:
Let A[i, j] be the length of the longest matching string suffix between x1 . . . xi and a segment of t
between t1 . . . tj . (
0, if x[i] 6= y[j];
A[i, j] =
A[i 1, j 1] + 1, if x[i] = y[j].

Page 1 of 2
(b) Use (a) to solve the problem for x = tofoodie and y = toody.
Solution:

i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8


t o f o o d i e
j=1 t 1 0 0 0 0 0 0 0
j=2 o 0 2 0 1 1 0 0 0
j=3 o 0 1 0 1 2 0 0 0
j=4 d 0 0 0 0 0 3 0 0
j=5 y 0 0 0 0 0 0 0 0
The longest common substring is ood with 3 characters.

Problem 4
Three types of packages are to be delivered by two trucks. There are two packages of each type. The
capacities of the two trucks are 5 and 2 packages respectively.

(a) Model this as a maxflow problem that can be used to determine whether all the packages can be
loaded and no truck carries two packages of the same type. Your solution should be a graph.
Solution:
Let 1,2,3 represent the types of packages, and let A, B represent the trucks.

<1

1
2 )
1 6 BA
5
1
2 / 2 (
s 6 t
1 2
1
2 )
1 6 B

"
3

If the maxflow from s to t is at least 6, then all the packages can be loaded with the given constraints.
Otherwise, the problem is not feasible.

(b) Solve the maximum flow problem using Ford-Fulkerson algorithm, and determine from the solution
whether all the packages can be loaded.

Page 1 of 2
Solution:

<1

1/1 )
1/2 6 BA
1/1
3/5
1/1
/ 2 (
s 2/2 6 t
0/1
2/2
1/1 )
2/2 6 B
1/1

"
3
The value of maxflow is 5, since it is less than 6, therefore it is not possible to load all the packages.

Problem 5
Let P = {x IRn : aTi x bi for i = 1, 2, . . . , m} be a polytope defined by m inequalities in dimension n.
For simplicity, we assume that P is bounded and nonempty. For a given k {1, 2, . . . , m}, let xk be an
optimal solution of the following linear programming problem (LPk )

max bk aTk x
aTi x bi for i = 1, 2, . . . , m

Prove or disprove the following claim:

(a) (bk > aTk xk for all k {1, 2, . . . , m}) = (P is full dimensional).
Solution: Pm
True. Let x
= 1 one can check that aTi x
m k=1 xk ; < bi for i = 1, 2, . . . , m.

Hints: (i) One way to prove that P is not full dimensional is to exhibit a hyperplane H = {x IRn :
T x = } satisfying P H (with || = 6 0). (ii) One way to prove that P is full dimensional is to exhibit
satisfying aTi x
a point x < bi for i = 1, 2, . . . , m.

*** END OF EXAM *** Page 2 of 2

You might also like