Thus, the sum cannot be decreased.

advertisement
EE5900 Advanced Algorithms for Robust VLSI CAD
Homework 1
Due in class: 01/21/2009
Name:
M-number:
1. Given two sorted lists of n numbers each, give the most efficient
algorithm to compute the median of all 2n numbers. Given the most
efficient algorithm to answer the following query: whether there are
two numbers (one number from each list) whose product is equal to a
given number.
2. Given n integers within the range of [1,N] where N=O(n), design a new
data structure where searching a number can be performed faster than
Θ(logn) time in the worst case. Hint: Use x mod √𝑁
3. Given a random variable X and a convex function f, prove that f(E[X])
<= E[f(X)] where E[] denotes the expected value.
4. Given a graph, find the maximum spanning tree. Assuming that all
edge weights are integers smaller than a constant, compute the singlesource shortest paths.
Ans: Negate the weight and compute the minimum spanning tree. Add
additional node to make weight to be 1, merge nodes with 0 weight edge,
and then perform BFS.
5. Given a graph with positive weight on each edge, a simple path is a
path without any cycle. Given two nodes a and b and a positive number
k, whether there is a simple path with total weight at most k. Is this
problem NP-complete? Given two nodes a and b and a positive number
k, whether there is a simple path with total weight at least k. Is this
problem NP-complete.
Ans: The first problem is a shortest path problem. The second problem
is in NP. Given an instance of Hamiltonian path problem, assign each edge
weight to be 1. The second problem is NP-complete.
6. Given n tasks where a task ti needs pi time to execute, we are to
schedule them non-preemptively. Denote the completion time of ti by
1
ci. Denote the average completion time by ∑𝑐𝑖 . Design a dynamic
𝑛
programming algorithm to find a schedule minimizing the average
completion time. Is there any faster algorithm?
7. In this course, Professor Hu will assign the student grades according to
the distribution as what he did for VLSI Design. It is possible for him
assign three letter grades, namely, A, AB and B based on the numerical
grades of students. Suppose that there are n students and their
numerical grades are denoted by x1,x2,…,xn. He will use three
numerical values s1,s2,s3 corresponding to the A, AB and B,
respectively, in grade assignment. Each student will be assigned to the
letter grade whose corresponding s value is closest to the student’s
numerical grade. He would like to find s1,s2,s3 such that ∑𝑖 |𝑥(𝑖,𝑘) −
𝑠𝑘 | is minimized where 𝑥(𝑖,𝑘) means that 𝑥𝑖 is assigned to (closest to)
𝑠𝑘 and k=1,2,3. Design an efficient algorithm to compute these three s
values.
Ans: Suppose that x1,x2,…xn are assigned to the grade s1. ∑𝑖 |𝑥(𝑖,𝑘) −
𝑠1 | is minimized when s1 is the median of the numbers. Suppose to the
contrary, there is s1’ which gives even smaller values. Suppose that
s1’>s1 and s1’=s1+Δ𝑠. For the numbers to the left of s1, the sum is
𝑛
increased by + Δ𝑠. For the numbers to the right of s1’, the sum can be
2
𝑛
decreased by at most − Δ𝑠. Thus, the sum cannot be decreased. In an
2
optimal solution, for each group of grades, s is set to the median of that
group.
Sort the numerical grades of students. Denote by f(1,t,3) the optimal
sum for x1,x2,…,xt if four letter grades are given. We are to compute
f(1,n,3). f(1,n,3)=min f(1,t,2)+f(t+1,n,1). This means that the last group
is assigned with A and the first two groups are optimally assigned.
f(i,j,1) for all i,j can be computed in O(n2) time. f(i,j,2) for all i,j can
also be computed in O(n2) time. Thus, the total time is O(n2).
Download