Question
The minimum number of arithmetic operations required to evaluate the polynomial for a given value of , using only one temporary variable is _____.
Official answer and solution
- Official answer
- 7
- From
- Official GATE 2014 answer key
Solution
Formulate Horner-like polynomial factorization using a single temporary variable to count operations.
We evaluate using only the input and one temporary variable .
-
Factor the polynomial to maximize reuse of :
-
Trace operations sequentially with single temporary variable :
- Operation 1 (multiplication): ()
- Operation 2 (addition): ()
- Operation 3 (multiplication): ()
- Operation 4 (multiplication): ()
- Operation 5 (addition): ()
- Operation 6 (multiplication): ()
- Operation 7 (addition): ()
-
Total count:
- 4 multiplications (steps 1, 3, 4, 6)
- 3 additions (steps 2, 5, 7)
Total = arithmetic operations.
Hence, the minimum number of arithmetic operations required is .
7
Recomputing powers of X from scratch, requiring substantially more multiplications.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 3
- Question
- 21 of 65, printed as CS Q.11
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.