19,065 views

7 Answers

0 votes
0 votes
6 should also be an answer.

We are given X [a constant] and only one temporary variable to store data that are required later.

Because the purpose of temporary variables are to store information calculated using work variables for reuse later, any average programmer would interpret it as “only one temporary variable beside a work variable????”. And they would solve it like this.

(1)  temp = X;

(1)  temp  = temp*temp;       // +1 operation [$X^2$], this is stored for reuse

(2)  A = temp+4;       // +1 operation [$X^2+4$]

(2)  A = temp*(A);    // +1 operation [$X^2(X^2+4)$], and used here

(3)  A = A + 6;           // +1 operation [$X^2(X^2+4)+6$]

(4)  A = X*(A);          // +1 operation [$X(X^2(X^2+4)+6)$]

(5)  A = A+5;            // +1 operation [$X(X^2(X^2+4)+6)+5$]

6 arithmetic operations overall.

So in conclusion the question could have been more informative on the constraints.
0 votes
0 votes
The minimum number of arithmetic operations required to evaluate is 7
Answer:

Related questions

67 votes
67 votes
4 answers
1
35 votes
35 votes
5 answers
4
go_editor asked Sep 28, 2014
8,749 views
Let $S$ be a sample space and two mutually exclusive events $A$ and $B$ be such that $A \cup B = S$. If $P(.)$ denotes the probability of the event, the maximum value of ...