Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. The minimum number of arithmetic operations required to evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given value of X, using only one temporary variable is _____.
    1. 0
    2. 3
    3. 5
    4. 7
Correct Option: D

P (x) = x5 + 4x3 + 6x + 5
= x3 (x2 + 4) + 6x + 5
Now using only one temporary variable ‘t’
(i) t = x * x (Evaluate x2 and store in memory)
(ii) t = t + 4 (Evaluate (x2 + 4) and store in memory)
(iii) t = x2 (Retrieve x2 from memory)
(iv) t = t * x (Evaluate x3 and store in memory)
(v) t = t * (x2 + 4) (Evaluate x3 (x2 + 4) and store in memory)
(vi) t = 6 * x (Evaluate 6x and store in memory)
(vii) t = t + 5 (Evaluate (6x + 5) and store in memory)
(viii) t = t + x3 (x2 + 4) (Retrieve x2 (x2 + 4) from memory and evaluate {x3 (x2 + 4) + 6x + 5}
For the above steps, total number of arithmetic operation is 7
i.e., 4 multiplications and 3 additions.



Your comments will be displayed only after manual approval.