Learnify Academy is a tuition centre in Bahrain. Classes are for students in Bahrain only.Tuition classes in Bahrain only

Algorithms · 3 marks

Try to execute the algorithm to compute the divisors of 15, 135, and 775. How does the amount of work increase as the numbers grow?

Answer: divisors(15) = [1, 3, 5, 15], divisors(135) = [1, 3, 5, 9, 15, 27, 45, 135], divisors(775) = [1, 5, 25, 31, 155, 775]. The algorithm checks every number from 1 to n, so the work grows in step with the number itself: 15, 135 and 775 checks. One more digit means about 10 times as much work.

Step-by-step solution

Idea: The algorithm tests j = 1, 2, 3, …, n, one at a time. So the number of tests equals n, however many divisors there turn out to be.

  1. n = 15: check j = 1 to 15. 1, 3, 5, 15 divide 15 (2, 4, 6, … do not). divisors(15) = [1, 3, 5, 15].½ mark
  2. n = 135: check j = 1 to 135. 135 = 33 × 5, and the numbers that divide it are [1, 3, 5, 9, 15, 27, 45, 135].½ mark
  3. n = 775: check j = 1 to 775. 775 = 52 × 31, and the numbers that divide it are [1, 5, 25, 31, 155, 775].½ mark
  4. Work done. The algorithm makes one divisibility check for each j from 1 to n: 15 checks, 135 checks and 775 checks. So the work is proportional to the size of the number, not to how many divisors it has (775 has fewer divisors than 135 but needs almost 6 times as many checks).1 mark
  5. Each extra digit makes a number about 10 times larger, so it makes the work about 10 times larger: a 3-digit number needs hundreds of checks, a 5-digit number tens of thousands.½ mark
divisors(15) = [1, 3, 5, 15]; divisors(135) = [1, 3, 5, 9, 15, 27, 45, 135]; divisors(775) = [1, 5, 25, 31, 155, 775]. The work (number of checks) equals n, so it grows in proportion to the number: about 10 times more work for each extra digit.

Check: Pairs multiply back to the number: 135 = 1 × 135 = 3 × 45 = 5 × 27 = 9 × 15; 775 = 1 × 775 = 5 × 155 = 25 × 31 ✓.

Answer to write in the exam

divisors(15): check 1 to 15 → [1, 3, 5, 15]

divisors(135): check 1 to 135 → [1, 3, 5, 9, 15, 27, 45, 135]

divisors(775): check 1 to 775 → [1, 5, 25, 31, 155, 775]

Number of checks = n: 15, 135, 775

∴ Work grows in proportion to the number (about 10 times for each extra digit).

Common mistakes that cost marks

  • Missing 27 and 45 as divisors of 135, or 31 and 155 as divisors of 775 (a prime factor like 31 is easy to overlook).
  • Saying the work depends on how many divisors there are. The algorithm checks every number up to n, so it depends on n.
  • Saying the work grows with the number of digits (adding 1 more step per digit). Here each extra digit multiplies the work by about 10.

How this can come in the exam

MCQ (1 mark)

How many divisibility checks does the divisors algorithm make to find all the divisors of 640?

  1. 8
  2. 16
  3. 320
  4. 640
Show answer

(D) 640
It checks every j from 1 to 640, so 640 checks.

Assertion–Reason (1 mark)

Assertion (A): Finding the divisors of 9000 with this algorithm takes about 10 times as many checks as finding the divisors of 900.
Reason (R): The algorithm checks every number from 1 to n.

  1. Both A and R are true, and R is the correct explanation of A.
  2. Both A and R are true, but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.
Show answer

(A) Both A and R are true, and R is the correct explanation of A.
9000 checks against 900 checks: 10 times as many. This follows directly from R.

Try one yourself

Find the divisors of 196 by the algorithm. How many checks are made?

Show answer

[1, 2, 4, 7, 14, 28, 49, 98, 196]; 196 checks (one for each j from 1 to 196).

More questions like this

All Algorithms questions · All maths questions