Data Structures and Algorithms COMP-251
Problem Assignment #5
1. Algorithms on Sequences
You are given a sequence S of n real numbers, where n is even.
(a) Design an algorithm to partition S into n/2 pairs in the following way. For each pair we
compute the sum of its two numbers, obtaining n/2 sums. The algorithm should find the
partition that minimizes the maximum sum.
(b) Prove the correctness of your algorithm.
2. Edit Distance between Strings
Let A = a1, a2,..., an and B = b1, b2,..., bm be two strings of characters. Denote by A[i] the
string ai, ai+1,..., an. Let di be the minimal edit distance between B and A[i]. Design an
O(n2) time algorithm to find the minimum value of di over all i = 1, 2,..., n.
3. Graph Embeddability
(a) Prove that a graph G is embeddable in the plane if and only if it is embeddable on the
sphere.
(b) Prove that a planar embedding of a graph can be transformed into a different planar em-
bedding such that any specified face becomes the exterior face.
-1-
For COMP-252 students only
Problem Assignment #5
1. Quicksort
Construct an example for which quicksort will use Ω(n2) comparisons when the pivot is
chosen by taking the median of the first, last, and middle elements of the sequence.
-2-