Concept:
To find the number of operations using a temporary variable, we need to simplify the equation to obtain bracket pairs and arithmetic signs.
Explanation:
P(X) = X5 + 4X3 + 6X + 5
P(X) = X (X4 + 4X2 + 6) + 5
P(X) = X (X (X3 + 4X) + 6) + 5
P(X) = X (X (X (X2 + 4)) + 6) + 5
P(X) = X (X (X (X (X) + 4)) + 6) + 5
Method 1 -
Let T be a temporary variable to store intermediate results.
- T = (X) * (X)
- T = T + 4
- T = (X) * (T)
- T = (X) * (T)
- T = T + 6
- T = (X) * T
- T = T + 5
Hence, 7 operations are used with one temporary variable.
Method 2 -
Counting number of bracket pairs gives the number of multiplication operations = 4
Counting number of + signs gives the number of addition operations = 3
Total operations = 7