Question

The minimum number of arithmetic operations required to evaluate the polynomial P(X)=X5+4X3+6X+5P(X) = X^5 + 4X^3 + 6X + 5 for a given value of XX, 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 P(X)=X5+4X3+6X+5P(X) = X^5 + 4X^3 + 6X + 5 using only the input XX and one temporary variable TT.

  1. Factor the polynomial to maximize reuse of XX:

    P(X)=X(X4+4X2+6)+5=X((X2+4)X2+6)+5.P(X) = X(X^4 + 4X^2 + 6) + 5 = X((X^2 + 4)X^2 + 6) + 5.
  2. Trace operations sequentially with single temporary variable TT:

    • Operation 1 (multiplication): T=X×XT = X \times X (T=X2T = X^2)
    • Operation 2 (addition): T=T+4T = T + 4 (T=X2+4T = X^2 + 4)
    • Operation 3 (multiplication): T=T×XT = T \times X (T=X3+4XT = X^3 + 4X)
    • Operation 4 (multiplication): T=T×XT = T \times X (T=X4+4X2T = X^4 + 4X^2)
    • Operation 5 (addition): T=T+6T = T + 6 (T=X4+4X2+6T = X^4 + 4X^2 + 6)
    • Operation 6 (multiplication): T=T×XT = T \times X (T=X5+4X3+6XT = X^5 + 4X^3 + 6X)
    • Operation 7 (addition): T=T+5T = T + 5 (T=X5+4X3+6X+5T = X^5 + 4X^3 + 6X + 5)
  3. Total count:

    • 4 multiplications (steps 1, 3, 4, 6)
    • 3 additions (steps 2, 5, 7)
      Total = 4+3=74 + 3 = 7 arithmetic operations.

Hence, the minimum number of arithmetic operations required is 77.

Final answer

7

Common trap

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.