对于给定的 X 值,仅使用一个临时变量计算多项式 P(X) = X 5 + 4X 3 + 6X + 5 所需的最少算术运算次数。
(一) 6
(乙) 7
(三) 8
(四) 9答案:(乙)
解释:
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.
如果您发现上面的帖子有任何错误,请在下面发表评论。
这个问题的测验