$30.00
Description

(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], nd it (atleast one of them if there are many common elements) in O(p + q + r) time.


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.


Generalisation : Given a matrix A[1 n][1 m] where each row is sorted and there is an element common in all rows, nd its position.
Naive algorithm generalising problem 1 will be O(nm^{2}). Can you obtain a O(nm) algorithm?
3. (a) Two arrays A[1 p] and B[1 q] are strictly increasing.Find the number of common elements in both. That is number of t such that t = A[i] = B[j] for some i; j.


How is the solution altered if A[1] A[2] A[p] and B[1] B[2] B[q], that is, the arrays are nondecreasing rather that strictly increasing.


If A(x) = a_{n}x^{n} + + a_{1}x + a_{0}, then the derivative of A(x); A^{0}(x) = na_{n}x^{n} ^{1} + + a_{1}. 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.

Let A(x) = a_{n}x^{n} + + a_{0}; p = n=2 and q = bn=2c. Then a variation of Horner’s rule states that
A(x) = ( (a_{2p}x^{2} + a_{2p} _{2})x^{2} + )x^{2} + a_{0} + (( (a_{2q} _{1}x^{2} + a_{2q} _{3})x^{2} + )x^{2} + a_{1})x
Show how to use this formula to evaluate A(x) at x = v and x = v.

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

Given n points (x_{i}; y_{i}); 1 i n, devise an algorithm which computes both the interpolating polynomial A(x) and its derivative at the same time. How e cient is your algorithm?

Given n points (x_{i}; y_{i}), our task is to nd the coe cients 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

A(x) = ^{P}_{1} _{i n}
Q
(x x )
i6=j;1 j n
j
^{y}i
(x_{i} x_{j} )

Verify that A(x) satis es the n points.

Analyse and prove that the naive algorithm for Lagrange interpolation takes O(n^{3}) time.

Let G_{j} _{1}(x) interpolate j 1 points (x_{k}; y_{k})1 k j such that G_{j} _{1}(x_{k}) = y_{k}. Also

let D_{j} _{1}(x) = (x x_{1}) (x
x_{j}
_{1}). Then we can compute G_{j}(x) by the formula
G_{j}(x) = (y_{j}
G_{j}
_{1}(x_{j}))(D_{j} _{1}(x)=D_{j} _{1}(x_{j})) + G_{j} _{1}(x)
Using this formula, the algorithm for computing the interpolating polynomial takes O(n^{2}) time . Verify and prove the same.

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.

Give a lineartime algorithm that takes as input a directed acyclic graph G = (V; E) and two vertices s and t, and returns the number of simple paths from s to t in G. For example, the directed acyclic graph of Figure 1 contains exactly four simple paths from vertex p to vertex v: pov, poryv, posryv and psryv. (Your algorithm needs only to count the simple paths, not list them.)
Page 2
Figure 1: A DAG

Let G = (V,E) be a directed graph in which each vertex u 2 V is labeled with a unique integer L(u) from the set f1; 2; ::::; jV jg. For each vertex u 2 V , let R(u) = fv 2 V : u /vg be the set of vertices that are reachable from u. De ne min(u) to be the vertex in R(u) whose label is minimum, i.e., min(u) is the vertex v such that L(v ) = minfL(w) : w 2 R(u)g. Give an O(V + E) time algorithm that computes min(u) for all vertices u 2 V .

Let P be a simple, but not necessarily convex, polygon and q an arbitrary point not necessarily in P. Design an e cient algorithm to nd a line segment originating from q that intersects the maximum number of edges of P. In other words, if standing at point q, in what direction should you aim a gun so the bullet will go through the largest number of walls. A bullet through a vertex of P gets credit for only one wall. An O(n log n) algorithm is possible.

Consider an n n array A containing integer elements (positive, negative, and zero). Assume that the elements in each row of A are in strictly increasing order, and the elements of each column of A are in strictly decreasing order. (Hence there cannot be two zeroes in the same row or the same column.) Describe an e cient algorithm that counts the number of occurrences of the element 0 in A. Analyze its running time.

Design an incremental algorithm that constructs a permutation given it’s inversion vector. What is the complexity of your algorithm? Can you design an O(nlogn) solution for the same?
Page 3



in a topdown fashion.





in a bottomup fashion.




Show that if heapsort is performed after building the heap in bottom up fashion, it’s complexity is 2nlog(n+1)2n (for n=2^{k}1, k 1). Construct an input that makes this many comparisons (building worst case examples).


The transitive closure G^{t} of a directed graph G is a directed graph with the same vertices as G, that contains any edge u ! v if and only if there is a directed path from u to v in G. A transitive reduction of G is a graph with the smallest possible number of edges whose transitive closure is G^{T} .The same graph may have several transitive reductions.


Describe an e cient algorithm to compute the transitive closure of a given directed graph.



Prove that a directed graph G has a unique transitive reduction if and only if G is acyclic.



Describe an e cient algorithm to compute a transitive reduction of a given directed graph.


Suppose we are given a directed acyclic graph G with a unique source s and a unique sink t. A vertex v 2= s,t is called an (s,t)cut vertex if every path from s to t passes through v, or equivalently, if deleting v makes t unreachable from s. Describe and analyze an algorithm to nd every (s,t)cut vertex in G.
Figure 2: A directed acyclic graph with three (s,t)cut vertices
Page 4