Efficiency of algorithms

EasyMedium
123456789
Question 5
Easy

An algorithm is required to calculate the eighth power of an input integer xxx (i.e. x8x^8x8). Two different designs are proposed.

Design A

temp_1 ← x * x
temp_2 ← temp_1 * temp_1
result ← temp_2 * temp_2

Design B

result ← 1
FOR i ← 1 TO 8
    result ← result * x
ENDFOR

Explain why the algorithm shown in Design A is more efficient than the algorithm shown in Design B.

[1]

Efficiency of algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Efficiency of algorithms