Question

Design a brute-force algorithm for multiplying two polynomials, both are expressed as functions of x, and...

Design a brute-force algorithm for multiplying two polynomials, both are expressed as functions of x, and show that its time efficiency of O(n^2).

Homework Answers

Answer #1

suppose polynomials are presented as array
Poly1[] = {a0,a1,..... an-2, an-1}
Ploy2[] = {b0,b1,..... bn-2, bn-1}


The first input array represents a0 + a1x1 + a2x2 +....+ an-1xn-1
The second array represents b0 + b1x^1 + b2x2 +....+ bn-1xn-1

Algorithm to multiply both polynomial poly1 and poly2
solution is to consider every term of first polynomial and multiply it with every term of second polynomial.
multiply(Poly1[0..n-1], Poly2[0..n-1])
step 1) Create a result array output[] of size 2*n-1.
step 2) Initialize all entries in output[] as 0.
step 3) Traverse array Poly1[] and do following for every element poly1[i]
Traverse array Poly2[] and do following for every element Poly2[j]
output[i+j] = output[i+j] + Poly1[i] * Poly2[j]
step 4) Return output[].

Time complexity = O(n^2)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How many comparisons (both successful and unsuccessful) will be made by the brute-force algorithm in searching...
How many comparisons (both successful and unsuccessful) will be made by the brute-force algorithm in searching for each of the following patterns in the binary text of one thousand zeros? a.00001     b.10000     c.01010
Design and Analysis of Algorithms: Gadget Testing A company wants to determine the highest floor of...
Design and Analysis of Algorithms: Gadget Testing A company wants to determine the highest floor of its n-story headquarters from which a gadget can fall without breaking, so they’ll test this by dropping gadgets and seeing when they break. The company only has one gadget to test with, and if the gadget breaks, it cannot be repaired – that is, by the time the gadget breaks, they better have the answer to your question. Hint:Solve a simpler problem with a...
Derive the expectation value of x^2, that is . Show that it can be expressed as...
Derive the expectation value of x^2, that is . Show that it can be expressed as (v + 1/2)h/[(2pi)√(mk)] Use the wave functions derived for the harmonic oscillator together with the Hermite polynomials and the recursion formula or other suitable methods. b) Use the assumption that the amplitude of the vibration can be expressed as √(< ?^2 >) to calculate the amplitude (around equilibrium) of the stretching mode vibration for the hydrogen atom in the HCl molecule in its vibrational...
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n...
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n integers. output: Two different indices i and j such that A[i] = A[j], if such indices exist. Otherwise, return NONE. Your algorithm must take O(n log(n)) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(n log(n)).
1 Approximation of functions by polynomials Let the function f(x) be given by the following: f(x)...
1 Approximation of functions by polynomials Let the function f(x) be given by the following: f(x) = 1/ 1 + x^2 Use polyfit to approximate f(x) by polynomials of degree k = 2, 4, and 6. Plot the approximating polynomials and f(x) on the same plot over an appropriate domain. Also, plot the approximation error for each case. Note that you also will need polyval to evaluate the approximating polynomial. Submit your code and both plots. Make sure each of...
UNSORTED VERSION: Write a Java program that uses “brute force” to find the closest pair, given...
UNSORTED VERSION: Write a Java program that uses “brute force” to find the closest pair, given N distinct integer points in 1-dimension. That is, all points are integers on the x-axis, and are in an array. This algorithm should go through all pairs (without sorting the elements of the array), one pair at a time, to find the current closest pair. For example, assume we had the following integers: 4, 2, -2, -1 in an array. We would then generate...
Design a recursive divide-and-conquer algorithm A(n) that takes an integer input n ≥ 0, and returns...
Design a recursive divide-and-conquer algorithm A(n) that takes an integer input n ≥ 0, and returns the total number of 1’s in n’s binary representation. Note that the input is n, not its binary representation. For example, A(9) should return 2 as 9’s binary representation is 1001, while A(7) should return 3 since 7 is 111 in binary. Note that your algorithm should have a running time of O(log n). Justify your answer. You need to do the following: (1)...
JAVA - algorithm analysis and sorting Question 1 Which of the following features grows fastest? 1....
JAVA - algorithm analysis and sorting Question 1 Which of the following features grows fastest? 1. N2 2. log N 3. N log N 4. N 5. 10 Question 2 Given the following code segment: for( int i = 1; i < n; i++ ) for( int j = 1; j < i; j++ ) k = k + i + j; What is the runtime of the code segment? 1. None of the above 2. O(i*N) 3. O(N2) 4....
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
Book name is Starting Out with Programming Logic and Design (5th Edition) Chapter 6: Functions Algorithm...
Book name is Starting Out with Programming Logic and Design (5th Edition) Chapter 6: Functions Algorithm Workbench 1. Design a simple function named timesDozen that accepts an Integer argument into a parameter named nbr. When the function is called, it should return the value of its argument multiplied times 12. 2. Assume that a program has two String variables named alpha and bravo. Write - a pseudocode statement that assigns an all uppercase version of alpha to the bravo variable.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT