38.5k views
2 votes
Suppose that a and b are each powers of 2, with a > b. then the euclidean algorithm, on inputs a and b, will terminate after at most log2(a) steps.

a) True
b) False

1 Answer

2 votes

Final answer:

The Euclidean algorithm will terminate in at most log2(b) steps, not log2(a) steps, when a and b are both powers of 2 with a > b. Therefore, the statement is false.

Step-by-step explanation:

The question posed concerns the efficiency of the Euclidean algorithm when applied to pairs of numbers that are powers of 2. Specifically, the question is whether the algorithm will terminate after at most log2(a) steps if a and b are powers of 2 with a > b. The correct answer to the question is False.

This is because when a and b are powers of 2, the Euclidean algorithm essentially performs a division by 2 in each step. Since a is greater than b, the algorithm would subtract b from a, resulting in another power of 2. In the subsequent steps, it again halves the problem. This division by two continues until b becomes zero, which takes the number of steps equal to the exponent in the power of 2 that b is, which is log2(b), not log2(a).

User Apeiron
by
7.4k points