Algorithms Quiz
Algorithms are step-by-step methods for solving problems. This quiz covers Euclid’s GCD algorithm, Strassen’s matrix multiplication, divide and conquer and how time complexity is described with Big-O.
What this quiz covers
- Euclid’s algorithm and GCD
- Divide and conquer
- Matrix multiplication
- Time complexity
Study tip: Work through Euclid’s algorithm on paper with two or three pairs of numbers until the pattern is obvious.
Questions, answers and explanations
1. Euclid’s algorithm is used for finding ________.
- GCD of two numbers
- GCD of more than three numbers
- LCM of two numbers
- LCM of more than two numbers
Answer: GCD of two numbers
Euclid’s algorithm finds the greatest common divisor (GCD) of two integers by repeatedly replacing the larger number with the remainder of the division.
2. Who invented Euclid’s algorithm?
- Sieve
- Euclid
- Euclid-Sieve
- Gabriel Lame
Answer: Euclid
The algorithm is named after the Greek mathematician Euclid, who described it around 300 BC in his work Elements.
3. If 4 is the GCD of 16 and 12, what is the GCD of 12 and 4?
- 12
- 6
- 4
- 2
Answer: 4
GCD(12, 4): 12 divided by 4 leaves remainder 0, so the GCD is 4. This also confirms that GCD(16, 12) = GCD(12, 4) = 4.
4. Which of the following is NOT an application of Euclid’s algorithm?
- Simplification of fractions
- Performing divisions in modular arithmetic
- Solving quadratic equations
- Solving Diophantine equations
Answer: Solving quadratic equations
Euclid’s algorithm works on integers to find a GCD; it is used for fractions, modular arithmetic and Diophantine equations, but not for solving quadratic equations.
5. Euclid’s algorithm runs efficiently by repeatedly dividing until the remainder becomes zero.
- True
- False
Answer: True
The algorithm keeps dividing and taking remainders until the remainder becomes zero; the last non-zero remainder is the GCD, which makes it very efficient.
6. According to Gabriel Lame, Euclid’s algorithm requires how many steps?
- Less than five times the number of digits
- More than five times the number of digits
- Less than two times the number of digits
- More than two times the number of digits
Answer: Less than five times the number of digits
Lamé’s theorem shows the number of division steps is always less than five times the number of digits of the smaller number.
7. Which of the following is a mathematical application of Euclid’s algorithm?
- Determination of prime numbers
- Lagrange’s four square theorem
- Cauchy-Euler theorem
- Residue theorem
Answer: Lagrange’s four square theorem
Euclid’s algorithm is used in number theory proofs such as Lagrange’s four-square theorem, as well as in cryptography.
8. If the GCD of two numbers is 1, they are called ________.
- Co-prime numbers
- Prime numbers
- Composite numbers
- Rational numbers
Answer: Co-prime numbers
When the GCD of two numbers is 1 they share no common factor other than 1, and such numbers are called co-prime (relatively prime).
9. What is the time complexity of Euclid’s algorithm?
- O(N)
- O(N log M)
- O(N log N)
- O(log N)
Answer: O(log N)
Each step reduces the numbers by at least half every two iterations, so the running time grows logarithmically: O(log N).
10. Euclid’s algorithm does not require calculation of prime factors.
- True
- False
Answer: True
Euclid’s algorithm only needs division and remainders, so no prime factorization is required, which is why it is much faster than factoring for large numbers.
11. What is the formula used in Euclid’s algorithm?
- GCD(m,n) = GCD(n, m mod n)
- LCM(m,n) = LCM(n, m mod n)
- GCD(m,n,o,p) = GCD(m, m mod n, o, p mod o)
- LCM(m,n,o,p) = LCM(m, m mod n, o, p mod o)
Answer: GCD(m,n) = GCD(n, m mod n)
The core identity is GCD(m, n) = GCD(n, m mod n). It is applied repeatedly until the second argument becomes 0.
12. What is the running time of the Binary GCD algorithm?
- O(N)
- O(N²)
- O(log N)
- O(N log N)
Answer: O(log N)
The Binary GCD (Stein’s) algorithm uses shifts and subtraction instead of division, and its running time is logarithmic in the size of the inputs.
13. What is the GCD of 20 and 12 using Euclid’s algorithm?
- 8
- 2
- 4
- 6
Answer: 4
20 mod 12 = 8, 12 mod 8 = 4, 8 mod 4 = 0. The last non-zero remainder is 4, so GCD(20, 12) = 4.
14. Strassen’s algorithm is a ________ algorithm.
- Non-recursive
- Recursive
- Approximation
- Accurate
Answer: Recursive
Strassen’s algorithm multiplies matrices by splitting them into sub-matrices and calling itself on the pieces, so it is a recursive algorithm.
15. What is the time complexity of Strassen’s algorithm?
- O(n²·⁸¹)
- O(n³)
- O(n¹·⁸)
- O(n²)
Answer: O(n²·⁸¹)
Strassen reduces the number of recursive multiplications from 8 to 7, giving a time complexity of about O(n^2.81) (n to the power log2 7).
16. What is the running time of the naive matrix multiplication algorithm?
- O(n²·⁸¹)
- O(n⁴)
- O(n)
- O(n³)
Answer: O(n³)
The standard method uses three nested loops over n elements each, so it performs about n × n × n operations, i.e. O(n³).
17. Strassen’s matrix multiplication algorithm uses which technique?
- Greedy
- Dynamic Programming
- Divide and Conquer
- Backtracking
Answer: Divide and Conquer
Strassen’s method is a divide and conquer technique: the problem is divided into smaller matrix products whose results are combined.
18. The number of scalar additions and subtractions used in Strassen’s algorithm is ________.
- O(n²·⁸¹)
- Θ(n²)
- Θ(n)
- O(n³)
Answer: Θ(n²)
The additions and subtractions of the sub-matrices take quadratic time, Θ(n²), at each level of the recursion.
19. Running time of Strassen’s algorithm is better than the naive Θ(n³) algorithm.
- True
- False
Answer: True
Because O(n^2.81) grows more slowly than Θ(n³), Strassen’s algorithm is asymptotically faster for large matrices, although it has more overhead for small ones.
20. In the naive matrix multiplication algorithm, what statement belongs inside the innermost loop?
- Z[i][j] = Z[i][j] + X[i][k] * Y[k][j]
- Z[i][j] = Z[i][j] + X[i][k] + Y[k][j]
- Z[i][j] = Z[i][j] * X[i][k] * Y[k][j]
- Z[i][j] = Z[i][j] * X[i][k] + Y[k][j]
Answer: Z[i][j] = Z[i][j] + X[i][k] * Y[k][j]
In the naive method each result cell is built by accumulating products of a row of X and a column of Y: Z[i][j] = Z[i][j] + X[i][k] * Y[k][j].