GATE | GATE-CS-2014-(Set-3) | Question 21

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.
(A) 6
(B) 7
(C) 8
(D) 9


Answer: (B)

Explanation:

P(X) = x5 + 4x3 + 6x + 5

     =x ( x4 + 4x2 + 6 ) +5

     =x ( x ( x3 + 4x ) + 6 ) + 5

     =x ( x ( x ( x2 + 4 ) ) + 6 ) + 5

     =x ( x ( x (x (x) + 4 ) ) + 6 ) + 5

Let T be a temporary variable to store intermediate results.

1. T = (x) * (x)
2. T = T + 4
3. T = (x) * (T)
4. T = (x) * (T)
5. T = T + 6
6. T = (x) * T
7. T = T + 5

Thus, we need 7 operations if we are to use only one temporary variable.

Please comment below if you find anything wrong in the above post.

Quiz of this Question

My Personal Notes arrow_drop_up