1. Algorithms on Sequences
Part (a)
Sort the sequence of n
elements in increasing order. Then,
for i = 1 to n/2
S'[i] = S[i] + S[n-i+1]
return S'
Running time: sorting takes O(n log n) and the
for loop takes O(n) time. Thus, the running time
of the algorithm is O(n log n).
Part (b)
To show that the algorithm minimizes the maximum sum we will
use contradiction. Let a1,a2,...,an
be the elements of S and let ai+
an-i+1 be the maximum value computed by our
algorithm.
First observe that if the sum ai+ aj
with i >= n/2 and j >= n/2
(i not equal to j) will only
increase the maximum. Thus, the maximum is the sum of two numbers
ai+ aj with i <=
n/2 and j > n/2.
If our algorithm is not correct, then it means that there is
some other sum aj+ an-j+1
in our sequence S' such that each of the sums
ai+ an-j+1 and aj+
an-i+1 is less than our computed maximum ai+
an-i+1. Without loss of generality assume
that j > i, which implies that aj
> ai and an-i+1
< aj+ an-j+1. But aj+
an-i+1 < ai+ an-i+1
implies that aj < ai,
which is a contradiction.
2. Edit Distance between Strings
The dynamic programming solution to the problem of computing
the edit distance between two strings A and B
finds the solution to subproblems and uses these solutions to
find an optimal solution to the problem. The algorithm stores
the solution to the subproblems in an m by n
array of integers, so that array element c[i,j]
is the edit distance between the two strings (a1,a2,...,ai)
and (b1,b2,...,bj).
In particular, the array element c[i,m] is the
edit distance between (a1,a2,...,ai)
and (b1,b2,...,bm).
Now, let us compute the edit distance between (an,an-1,...,a1)
and (bm,bm-1,...,b1).
The value of the solution to this modfied input is equal to the
edit distance between (a1,a2,...,an)
and (b1,b2,...,bm).
Hence, element c'[i,m] of the new table is the
edit distance between (ai,a2,...,an)
and (b1,b2,...,bn).
Therefore, to compute the edit distance between B
and A[i], we first compute the edit distance
between (an,an-1,...,a1)
and (bm,bm-1,...,b1);
this will take O(n2) time. We then
find the minimum value of the last row of the table in linear
time. This will make the total running time of the algorithm equal
to O(n2).
3. Graph Embeddability
Part (a)
We show this by using a mapping known as stereographic projection.
Consider a spherical surface S, touching a plane P at the point
x. The point y (called the point of projection) is on S and diametrically
opposite x. Any point z on P can be projected uniquely onto S at
z' by making y,z and z' collinear. In this way any graph embedded
in P can be projected onto S. Conversely, we can project any graph
embedded in s onto P, choosing y so as not ot lie on any vertex
or edge of the graph.
Part (b)
Any face of G is defined by the path which forms its boundary.
Any such path, T, identified in a particular plar representation
P of G, may be made to define the exterior face of a different
planar representation P' as follows. We form, as we can according
to the previous theorem, a sperical embedding P'' of P. P' is
then formed by projecting P'' onto the plane in such a way that
the point of projection lies in the face defined by the image
of T on the sphere.