The minimum number of arithmetic operations required to evaluate the polynomial

P(X) = X5 + 4X3 + 6X + 5 for a given value of X, using only on temporary variable is _______

This question was previously asked in
GATE CS 2014 Official Paper: Shift 3
View all GATE CS Papers >

Answer (Detailed Solution Below) 7

Free
GATE CS Full Mock Test
5.4 K Users
65 Questions 100 Marks 180 Mins

Detailed Solution

Download Solution PDF

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.

  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

 

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

Latest GATE CS Updates

Last updated on Jan 8, 2025

-> GATE CS 2025 Admit Card has been released on 7th January 2025.

-> The exam will be conducted on 1st February 2025 in 2 shifts.

-> Candidates applying for the GATE CE must satisfy the GATE Eligibility Criteria.

-> The candidates should have BTech (Computer Science). Candidates preparing for the exam can refer to the GATE CS Important Questions to improve their preparation.

-> Candidates must check their performance with the help of the GATE CS mock tests and GATE CS previous year papers for the GATE 2025 Exam.

More Code Optimization Questions

Hot Links: teen patti 3a teen patti app teen patti master 2024 teen patti 500 bonus