Problem 1: Consider the points {1, 2, . . . , n} on the real line; and suppose there is a particle with charge qj at each of these points j. (Each charge can be either positive or negative.) The total net force on particle j, by Coulomb’s Law, is equal to, Fj =

Cqi qj − (j − i)2


Cqi qj (j − i)2

Design an algorithm that computes all the forces Fj in O(n log n) time. Problem 2: Recall that a priority search tree is a binary tree in which every node has both a search key and a priority, arranged so that the tree is simultaneously a binary search tree for the keys and a min-heap for the priorities. A heater is a priority search tree in which the priorities are given by the user, and the search keys are distributed uniformly and independently at random in the real interval [0, 1]. Intuitively, a heater is a sort of dual treap. The following problems consider an n-node heater T whose node priorities are the integers from 1 to n. We identify nodes in T by their priorities; thus, ‘node 5’ means the node in T with priority 5. The min-heap property implies that node 1 is the root of T . Finally, let i and j be integers with 1 ≤ i < j ≤ n. (a) Prove that in a random permutation of the (i + 1)-element set {1, 2, ..., i, j}, elements i and j are adjacent with probability 2/(i + 1). (b) Prove that node i is an ancestor of node j with probability 2/(i + 1). (Hint: Use part (a)!) (c) What is the probability that node i is a descendant of node j? (Hint: Dont use part (a)!) (d) What is the exact expected depth of node j? (e) Describe and analyze an algorithm to insert a new item into a heater. Express the expected running time of the algorithm in terms of the rank of the newly inserted item.

Problem 3: Let G = (V, E) be a weighted directed graph; the weight of each edge is non-negative. For any edge e ∈ E, let G \ e denote the graph obtained by deleting e from G. Suppose the shortest path σ from vertex s to vertex t in G passes through every vertex of G. Describe an algorithm to compute the shortest-path distance from s to t in G \ e, for every edge e of G, in O(E log V ) time. Your algorithm should output a set of E shortest-path distances, one for each edge of the input graph. (Hint: If we delete an edge of the original shortest path, how do the old and new shortest paths overlap?) Problem 4: Let G = (V, E) be an undirected graph with 2n vertices. A perfect matching of G is a set M ⊆ E of n vertex-disjoint edges, i.e., each vertex appears only once in M . Suppose we

Due November 3, 2009

Page 1

We define a variable xe for each edge e ∈ E and define a 2n × 2n matrix A(x) as follows: A(x) = (aij )2n×2n where xe if e = (i. It is known (called Tutte’s theorem) that G has a perfect matching if and only if det A(x) is not identically 0. −xe if e = (j. Describe a Monte Carlo algorithm to test whether G has a perfect matching. j). j} ∈ E. 2009 Page 2 .A SSIGNMENT 4 C OURSE : CPS230 orient each edge of G arbitrarily. the algorithm should return the correct answer with probability least 1 − 1/n.   Due November 3. Prove the correctness of your algorithm. and let G denote the resulting directed graph. i). and analyze its running time. aij =  0 if {i.