Answer:
The statement is correct. The time complexity of finding GCD is O(log N)
because it uses the Euclidean Algorithm, which repeatedly reduces the problem size.
Explanation:
The Euclidean Algorithm works as follows:
gcd(a, b) = gcd(b, a % b)
In each step:
- The larger number is replaced by the remainder of division
- The values decrease rapidly
This reduction happens logarithmically. That means:
- The number of steps required is proportional to log N
- N is the larger of the two numbers
For example:
gcd(48, 18)
→ gcd(18, 12)
→ gcd(12, 6)
→ gcd(6, 0)
Here, the numbers reduce quickly in very few steps.
Conclusion:
- Each step reduces the problem size significantly
- The total number of steps is proportional to log N
- Therefore, time complexity = O(log N)