Question: Let f ( x ) , g ( x ) be two polynomial functions given by f ( x ) = a 0 + a

Let f(x),g(x) be two polynomial functions given by f(x)=a0+a1x+a2x2+cdots+anxn
and g(x)=b0+b1x+b2x2+cdots+bmxm.
(a)(6 pts.) Write an algorithm called PolyAdd (A,n,B,m) in pseudocode to com-
pute h(x)=f(x)+g(x), where f(x) and g(x) are given as arrays A[0..n],B[0..m]
with A[i]=ai and B[i]=bi.(The indexing goes from 0 here instead of 1 ; the
lengths of these arrays are respectively n+1 and m+1. The result h(x) should
be returned as an array C, which stores its coefficients, and its size (max(n,m)).
(b)(4 pts.) Analyze the running time of PolyAdd(A,n,B,m). You may assume
that nm and give your result in terms of n.
(c)(4 pts.) Write an algorithm PolyMult (A,n,B,m) in pseudocode to compute
h(x)=f(x)g(x) where f(x) and g(x) are given as before. An array C[0..n+m]
defining h(x) and its size (n+m) should be returned. Justify the correctness of
your algorithm. (What loop invariant does your algorithm maintain?)
(d)(4 pts.) Analyze the running time of Polylt(A,n,B,m). You may assume
that n=m, and give your result in terms of n.
(e)(6 pts.) Now assume that the first input polynomial f(x) is always sparse, i.e.,
we know that ai will be nonzero for at most K values of i, where K is a constant.
Modify the algorithm from part (c) to create SparsePolyMult (A,n,B,m), which
takes advantage of the sparsity of f. Write pseudocode for this algorithm (or
clearly note how to modify PolyMult (A,n,B,m)). Assuming nm, analyze
the running time of SparsePolyMult (A,n,B,m); the running time should be
O(n).
 Let f(x),g(x) be two polynomial functions given by f(x)=a0+a1x+a2x2+cdots+anxn and g(x)=b0+b1x+b2x2+cdots+bmxm.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!