You are on page 1of 3

Advanced Data Structures & Algorithms

Session: Jan-May, 2017, (Course ID: CS5800)


Assignment 2: Incremental Design
Name : Roll No :
Date of Submission :

1. Horners method evaluates a polynomial of degree n at a value incrementally. Extend


it to evaluate the polynomial and its derivative at the same point. Compare and contrast
naive and efficient method.

2. (a) Given that there is a number present in all the three sorted arrays x[1]
x[p], y[1] y[q], z[1] z[r],find it (atleast one of them if there are many
common elements) in O(p + q + r) time.

(b) Suppose we do not know in advance that such a common element exists. Determine
whether or not it exists and locate it(atleast one) when it does.

3. Generalisation : Given a matrix A[1 n][1 m] where each row is sorted and there is
an element common in all rows, find its position.
Naive algorithm generalising problem 2 will be O(nm2 ). Can you obtain a O(nm) algo-
rithm?

4. (a) Two arrays A[1 p] and B[1 q] are strictly increasing.Find the number of com-
mon elements in both. That is number of t such that t = A[i] = B[j] for some i, j.

(b) How is the solution altered if A[1] A[2] A[p] and B[1] B[2] B[q],
that is, the arrays are non-decreasing rather that strictly increasing.

5. If A(x) = an xn + + a1 x + a0 , then the derivative of A(x), A0 (x) = nan xn1 + + a1 .


Devise an algorithm which produces the value of a polynomial and its derivative at a point
x = v. Determine the number of required arithmetic operations.

6. Let A(x) = an xn + + a0 , p = n/2 and q = bn/2c. Then a variation of Horners rule


states that

A(x) = ( (a2p x2 + a2p2 )x2 + )x2 + a0 + (( (a2q1 x2 + a2q3 )x2 + )x2 + a1 )x


Show how to use this formula to evaluate A(x) at x = v and x = v.

7. Given the polynomial A(x) as above in problem 6, devise an algorithm which computes
the coefficients of the polynomial A(x + c) for some constant c.

8. Given n points (xi , yi ), 1 i n, devise an algorithm which computes both the interpo-
lating polynomial A(x) and its derivative at the same time. How efficient is your algorithm?

9. Given n points (xi , yi ), our task is to find the coefficients of the unique polynomial A(x)
of degree n 1 which goes through these n points. Mathematically the answer to this
problem was given by Lagrange
Q 
P (xxj )
A(x) = 1in i6=j,1jn (xi xj ) yi

(a) Verify that A(x) satisfies the n points.

(b) Analyse and prove that the naive algorithm for Lagrange interpolation takes O(n3 )
time.

(c) Let Gj1 (x) interpolate j 1 points (xk , yk )1 k j such that Gj1 (xk ) = yk . Also
let Dj1 (x) = (x x1 ) (x xj1 ). Then we can compute Gj (x) by the formula

Gj (x) = (yj Gj1 (xj ))(Dj1 (x)/Dj1 (xj )) + Gj1 (x)

Using this formula, the algorithm for computing the interpolating polynomial takes
O(n2 ) time . Verify and prove the same.

10. A group of n persons have an independent information for gossip known only to himself.
Whenever a person calls another person in the group, they exchange all the gossip information
they know at that time of calling. What is the minimum number of calls they have to make
in order to ensure that everyone of them knows all the information.

11. You are given equations of n lines as input. The equation of a line is of the form
y = mx + c where m is the slope and c is the y-intercept. Design an O(nlogn) algorithm that
counts the number of intersection points that lie on the right side of the line x = 0 (y-axis).
You can make the following assumptions:
No line is parallel to the x-axis or y-axis.

Page 2
No two lines are parallel to each other.
No three lines intersect at the same point. Hence, there are exactly n(n1)/2 intersection
points in the configuration.
All the intersection points lie in the bounding box [100, 100] [100, 100]. In other
words, the x and y coordinates of any intersection point have an absolute value of at most
100.

Page 3

You might also like