CS6212
Youssef

June 6, 2011

 

Homework 3

Due Date: June 20, 2011


Problem 1: (20 points)

Let a1 < a2 < a3 < a4 < a5 < a6 be 6 numbers, and let

 

p1 = 1/20

p2 = 3/20

p3 = 1/20

p4 = 4/20

p5 = 1/20

p6=3/20

q0 = 0

q1 = 2/20

q2 = 1/20

q3 = 1/20

q4 = 1/20

q5 = 1/20

q6 = 1/20

where pi is the probability of accessing ai for i=1,2,3,4,5,6, q0 is the probability of searching for an item < a1, q6 is the probability of searching for an item > a6, and qi the probability of searching for an item between ai and ai+1 for i = 1, 2, 3, 4, 5. You are to construct an optimal binary search tree.

a)     Write down a table for the wij's, and a table for the Cij's and their corresponding rij's as defined in the algorithm for optimal binary search trees.

b)     Contruct the optimal binary search tree.


Problem 2: (20 points)

Let A[1..n] be an array of positive numbers, and let k be an integer, k=1,2,...,n. A linear k-partition of A is any sequence of subarrays of the form A[1..n1], A[n1+1..n2], ... , A[nk-1+1..n], for some n1, n2, ... , nk-1 where 1<= n1 < n2 < n3 < ... < nk-1 < n. The weight of a subarray is the products of the numbers in that subarray, and the weight of a linear k-partition is defined to be the sum of the weights of the k subarrays of the partition.

Give a dynamic programming algorithm to compute the maximum-weight k-partition of A. (Hint: Take Wir as the weight of the maximum-weight r-partition of the array A[1..i], and develop a recurrence relation for Wir.) Analyze the time complexity of your algorithm.


Problem 3: (20 points)

You are a consultant for the president of a corporation, which is planning to form a high-caliber advisory committee made up of a cross section of the company. The company has a hierarchical structure; that is, the supervisor relation forms a tree rooted at the president, where each node represents the immediate supervisor of its children nodes. The personnel office has ranked each employee x with a competence rating C(x), which is a real number. In order to form a small but most competent advisory committee, the following conditions must be met:

a)     Develop a dynamic programming algorithm to make up the committee that maximizes the sum of the competence ratings of its members. (Note that there is no restriction on the number of members on the committee.) Analyze the time complexity of your algorithm.

b) Develop a greedy algorithm for the same problem, and show by a counter example that the greedy solution is not necessarily optimal.


Problem 4: (20 points)

Give a single-source shortest path algorithm for weighted graphs where all the edges have the same weight, such that your algorithm uses a graph traversal technique and is faster than the greedy based single-source shortest path algorithm. Analyze the time complexity of your algorithm.


Problem 5: (20 points)

Let G = (V,E) be the following undirected graph: V = {1,2,3,4,5,6,7,8,9,10,11,12,13}, and E = {(1,2) , (1,3) , (2,4) , (3,4) , (4,5) , (4,7) , (5,6) , (6,7) , (8,6), (10,6) , (8,9) , (10,9) , (7 , 11) , (7,12), (11,13), (12,13)}.

a)     Do a depth-first search on G from node 1, showing the depth-first search tree and the backward edges. Compute the DFN and L of every node.

b)     Identify the articulation points of G.

c)     Do a breadth-first search on G starting from node 1, and show the tree edges and the crossed edges.