Question
(1) Suppose you want to have a program that evaluates polynomials. (a) Heres (presumably) the simplest possible program. Input: polynomial p(x) = a0 + a1x
(1) Suppose you want to have a program that evaluates polynomials. (a) Heres (presumably) the simplest possible program. Input: polynomial p(x) = a0 + a1x + a2x 2 + + anx n n, the degree , a real number Output: p() (the value of p at x = ) Return( a0 + a1 + a2 2 + + an n ) How many additions and multiplications occur when this code is run? What is the asymptotic time complexity? (Important: exponentiation does not count as an atomic operation; you need to count the number of multiplications needed.) (b) The above is pretty wasteful; why should the computer calculate 12 and later 13 from scratch? Write pseudocode that saves compuation time by looping through the terms of the polynomial, calculating successive powers of more efficiently. What is its asymptotic time complexity?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started