SK CLASSES • CLASS 9 MATHEMATICS

The World of Algorithms

Chapter 11 • Complete exercise solutions • Step-by-step virtual teacher

Based on the supplied Ganita Manjari, Grade 9, Part II chapter, printed pages 37–50. Covers every question in Exercise Sets 11.1, 11.2 and 11.3; all five end-of-chapter exercises, including starred questions; and the Think and Reflect prompts. Question statements are restated briefly, preserving the original numbering.

Start here: how to read an algorithm

An algorithm is a precise, finite sequence of instructions for solving a problem. The answer matters, but so do the instructions: a reader should not have to guess a missing rule. In this chapter, you will ask three questions: What does each step do? Why is the answer correct? Will the procedure stop?

Term / notationMeaning
InputThe information supplied, such as two numbers m and n.
OutputThe required answer, such as their greatest common divisor.
VariableA name storing a value that may change, such as carry or remainder.
ListAn ordered collection such as [1, 2, 3, 6]. The empty list is [ ].
AppendAdd an item at the end of a list.
a ← bAssign the value b to a. This changes what a stores.
n mod jThe remainder on dividing n by j. Example: 17 mod 5 = 2.
j divides nn mod j = 0; division leaves no remainder.
RETURN / STOPGive the answer and end the algorithm immediately.
FOR / WHILERepeat instructions over a range or while a condition remains true.
Teacher’s tip: Unless stated otherwise, divisor, prime-factorisation and lcm algorithms here take positive integers. The gcd algorithm also permits one input to be 0, with the other positive. We do not attempt gcd(0, 0) or division by 0.
Dividend = divisor × quotient + remainder
m = qn + r, where 0 ≤ r < n and n > 0

How to study: Read the plan, trace the sample input, then explain the reason for every update. The dark algorithm boxes are readable pseudocode, not browser scripts.

Exercise Set 11.1

Digit-by-digit addition • Printed page 38

11.1 · Q1

Does the written addition algorithm cover every case?

Choose two four-digit numbers and follow the printed steps literally. Can you always obtain the correct result?

Step 1 — Choose a test that exposes a missing case. Take 2468 + 1532. Align thousands with thousands, hundreds with hundreds, and so on.

ThousandsHundredsTensOnes
2468
1532

Step 2 — Follow the printed units rule.

8 + 2 = 10

The chapter tells us what to do when the sum is less than 10 or more than 10. It gives no instruction for a sum equal to 10. Therefore, if we follow only the written instructions, we cannot continue this example. We must not silently invent the missing branch.

Step 3 — Correct the rule. In both the units step and the later-column step, replace “more than 10” with “10 or more”. Then write the units digit and carry 1.

ColumnCalculationWriteCarry to next column
Ones8 + 2 = 1001
Tens6 + 3 + 1 = 1001
Hundreds4 + 5 + 1 = 1001
Thousands2 + 1 + 1 = 440
2468 + 1532 = 4000
Answer: The algorithm is incomplete as printed: it omits the sum-10 case. After correcting both conditions, this example gives 4000.
Teacher’s tip: Some inputs still work as printed: 1234 + 4321 = 5555 never reaches the missing case. One successful input is not a proof that an algorithm works for every input.
11.1 · Q2

Adding numbers with unequal lengths

What happens when a five-digit number is added to a three-digit number?

Step 1 — Try 12,345 + 678. Right alignment leaves the thousands and ten-thousands positions of the shorter number blank.

Step 2 — Identify the missing instruction. The printed algorithm says to add the two digits in each column, but does not explicitly say how to handle a blank. Ordinary arithmetic treats the blank as 0; a fully precise algorithm must state that rule.

Write 678 as 00678 for the calculation.
12,345 + 00,678
ColumnCalculationWriteCarry
Ones5 + 8 = 1331
Tens4 + 7 + 1 = 1221
Hundreds3 + 6 + 1 = 1001
Thousands2 + 0 + 1 = 330
Ten-thousands1 + 0 = 110
12,345 + 678 = 13,023
Answer: The literal steps need a missing-digit-as-zero rule. With that rule and the corrected “sum ≥ 10” condition, unequal-length numbers are handled correctly.
Teacher’s tip: Leading zeros do not change an integer’s value. Padding on the left aligns equal place values.
11.1 · Q3

Why align from the right?

Explain why the columns must be aligned from right to left when adding whole numbers.

Step 1 — Recall the meaning of position. The rightmost digit counts ones, the next tens, the next hundreds, and so on. Addition must combine like units.

234 = 2 × 100 + 3 × 10 + 4
56 = 0 × 100 + 5 × 10 + 6

Step 2 — Match the place values. Write 56 below 234 with 6 under 4 and 5 under 3. Then ones combine with ones and tens with tens.

Ones: 4 + 6 = 10 → write 0, carry 1 ten
Tens: 3 + 5 + 1 = 9
Hundreds: 2 + 0 = 2
234 + 56 = 290

If 56 is wrongly aligned on the left and the blank on its right is treated as 0, it effectively becomes 560. That would give 234 + 560 = 794, which answers a different question.

Answer: Right alignment ensures that equal place values are added together.
Teacher’s tip: For decimal numbers, align decimal points rather than merely aligning the last written digits.
11.1 · Q4

Why can the carry not exceed 1?

In Step 3, why is the carry at most 1 when adding two numbers?

Step 1 — Bound the units-column sum. Each digit is at most 9, so the first sum is at most 18. Its carry is therefore either 0 or 1.

Largest first-column sum = 9 + 9 = 18

Step 2 — Include an incoming carry. In any later column, there are two digits, each at most 9, and an incoming carry at most 1.

Largest later-column sum = 9 + 9 + 1 = 19
Outgoing carry = whole-number quotient on dividing the sum by 10
19 ÷ 10 has quotient 1 and remainder 9

Thus the carry into the next column again cannot exceed 1. Starting at the first column and applying this reasoning repeatedly proves the claim for every column.

Answer: The greatest possible column total is 19, so the carry is always 0 or 1.
Teacher’s tip: This bound is for adding two base-ten numbers. With three numbers, 9 + 9 + 9 = 27 can produce carry 2.
11.1 · Q5

Why must we write the final carry?

What happens if the fifth step is omitted? Give a working example and a failing example.

When it still works: If there is no carry after the leftmost column, omitting Step 5 changes nothing.

1234 + 4321 = 5555
Final carry = 0 → no extra digit is needed.

When it fails: Choose 6789 + 5678. This example avoids the separate missing-sum-10 issue, so it isolates the importance of Step 5.

ColumnCalculationWriteCarry
Ones9 + 8 = 1771
Tens8 + 7 + 1 = 1661
Hundreds7 + 6 + 1 = 1441
Thousands6 + 5 + 1 = 1221

After processing the four columns, the written digits are 2467 and the carry is 1. That 1 represents one ten-thousand.

Correct result = 10,000 + 2467 = 12,467
Without Step 5, the recorded result would be only 2467.
Answer: Step 5 is essential whenever a final carry of 1 remains. It creates the extra leftmost digit.
Teacher’s consolidation

A complete, corrected addition algorithm

Use this version to repair both missing cases identified in Exercise 11.1.
ADD(a, b)
Input: two non-negative whole numbers.
1. Align digits by place value.
2. Treat each missing digit as 0.
3. Set carry ← 0.
4. Process every column, from right to left:
   a. s ← digit of a + digit of b + carry
   b. Write s mod 10 in this answer column.
   c. carry ← whole-number quotient of s ÷ 10
5. If carry is 1, write it to the left.
6. Report the completed answer.

The remainder s mod 10 is the digit to write; the quotient is the number of tens transferred left. This single rule handles sums below 10, exactly 10, and above 10 without a gap.

Teacher’s tip: This corrected algorithm is a learning aid, not an extra textbook question.

Exercise Set 11.2

Lists, lcm and paired divisors • Printed pages 43–44

11.2 · Q1

Finding elements present in only one list

List 1 and List 2 are increasing lists. (i) Find elements of List 1 absent from List 2. (ii) Find elements of List 2 absent from List 1.

Plan: Scan the source list. For each value, test whether it appears in the other list. Keep it only if it does not. This is a list-difference operation; the order of the two lists matters.

(i) List 1 minus List 2

DIFFERENCE(List1, List2)
1. Start with an empty answer list.
2. For each value x in List1, in order:
   If x is not present in List2:
      Append x to answer.
3. Return answer.

(ii) List 2 minus List 1

1. Start with an empty answer list.
2. For each value y in List2, in order:
   If y is not present in List1:
      Append y to answer.
3. Return answer.

Worked trace: Take List 1 = [1, 2, 3, 6] and List 2 = [1, 3, 4, 6, 12].

Value in List 1Present in List 2?Answer after the test
1Yes[ ]
2No[2]
3Yes[2]
6Yes[2]
Value in List 2Present in List 1?Answer after the test
1Yes[ ]
3Yes[ ]
4No[4]
6Yes[4]
12No[4, 12]
Answer: For this example, (i) [2]; (ii) [4, 12]. The algorithms work for any such input lists.

Why correct? Every source-list entry is examined, and an entry is kept exactly when it is absent from the other list. Since retained entries stay in their original order, the answer is also increasing. Both loops end because the input lists are finite.

Teacher’s tip: If “increasing” is allowed to include repeated values and you want distinct answers, append a value only if it is not already in the answer. For strictly increasing lists, duplicates do not arise.

Optional improvement: use the sorted order

Keep one position in each list. If the values match, move both positions. If the List 1 value is smaller, keep it for part (i) and move only its position. If the List 2 value is smaller, move only its position. Once List 2 is exhausted, keep all remaining List 1 values. For part (ii), swap the lists. Each position moves only forwards.

11.2 · Q2

An algorithm for the least common multiple

Describe an algorithm to compute lcm(m, n).

Start from the definition. A common multiple must be a multiple of m and of n. Examine positive multiples of the larger input in increasing order. The first that is also divisible by the smaller input is the least common multiple.

LCM(m, n)
Input: positive integers m and n.
1. a ← max(m, n)
2. b ← min(m, n)
3. candidate ← a
4. While candidate mod b is not 0:
   candidate ← candidate + a
5. Return candidate.

Worked example: lcm(12, 18). Here a = 18 and b = 12.

CandidateDivisible by 12?Action
18No: remainder 6Try 18 + 18 = 36
36Yes: remainder 0Return 36 and stop
lcm(12, 18) = 36

Why correct? Every candidate is a multiple of a. The stopping test confirms it is also a multiple of b. We test candidates in increasing order, so none of the earlier multiples of a is common.

Why does it stop? The product ab is a common multiple: it occurs among a, 2a, 3a, …, ba. Therefore a successful candidate appears after at most b tests.

Faster alternative once gcd is available

lcm(m, n) = m × ngcd(m, n)
For 12 and 18: gcd = 6, so lcm = 12 × 186 = 36

To justify the formula, compare prime powers: gcd takes the smaller exponent of each prime and lcm takes the larger. Their exponents add to those in the product mn.

Answer: Either the increasing-multiples algorithm or the gcd-based formula gives a valid lcm procedure.
11.2 · Q3 ★

Finding divisors in pairs

(i) How far do we need to test when divisors occur in pairs? (ii) Will the chapter’s gcd algorithm still work if we list divisors in pairs?

(i) Use the smaller member of each pair. If a × b = n and both a and b were greater than √n, their product would exceed n. Therefore at least one factor in every pair is at most √n.

It is enough to test j = 1, 2, …, ⌊√n⌋.

The symbol ⌊√n⌋ means the greatest whole number not exceeding √n. For every successful j, the paired divisor is n ÷ j.

Test for n = 18ResultDivisors found
118 ÷ 1 = 181 and 18
218 ÷ 2 = 92 and 9
318 ÷ 3 = 63 and 6
4Remainder 2None

Since 4² ≤ 18 < 5², only 4 candidate numbers are tested instead of all 18. At j = 4 no divisor is found; this test is still part of the scan.

Perfect-square case: For n = 36, the pair at j = 6 is (6, 6). Add 6 only once to avoid duplicating a divisor.

(ii) The rightmost-element rule may fail. Appending both factors of each pair immediately gives divisors(18) as [1, 18, 2, 9, 3, 6]. This is not in increasing order.

For gcd(18, 36), every value in that first list appears in the second divisor list. The common-divisor list therefore ends with 6 even though the gcd is 18. Selecting its rightmost item would be wrong.

Answer: (i) Test ⌊√n⌋ candidates. (ii) Not unchanged: preserve sorted order or return the maximum common divisor instead of the last one.

A paired-divisor algorithm that preserves increasing order

PAIRED_DIVISORS(n)
Input: a positive integer n.
1. small ← [ ]; large ← [ ]
2. For j from 1 through floor(√n):
   If n mod j = 0:
      Append j to small.
      paired ← n ÷ j
      If paired is not equal to j:
         Append paired to large.
3. Reverse large.
4. Return small followed by large.

For 18, small = [1, 2, 3] and large is initially [18, 9, 6]. Reversing large gives [6, 9, 18]. Joining the lists gives [1, 2, 3, 6, 9, 18], so the original rightmost-common-divisor rule is safe again.

Exercise Set 11.3

Scanning backwards • Printed page 45

11.3 · Q1

Reverse the order of divisor scanning

How does the original gcd algorithm change if divisors are obtained by examining n, n − 1, …, 1?

Step 1 — Understand the new list order. Divisors now appear in decreasing order. For example:

divisors(12) = [12, 6, 4, 3, 2, 1]
divisors(18) = [18, 9, 6, 3, 2, 1]

Step 2 — Scan the first list for common entries. The values 12 and 4 are not divisors of 18; 6, 3, 2 and 1 are. Thus the common list is [6, 3, 2, 1].

Step 3 — Change the final selection. The greatest common divisor is now the leftmost common entry, not the rightmost.

GCD_BY_DESCENDING_LISTS(m, n)
1. Obtain the divisors of m in decreasing order.
2. Obtain the divisors of n in decreasing order.
3. Start common ← [ ].
4. Scan the first list in its stored order:
   If the current value is in the second list:
      Append it to common.
5. Return the leftmost element of common.
Answer: When the list being scanned is decreasing, return the first/leftmost common divisor. For 12 and 18, that is 6.
Teacher’s tip: The order of the output common list is determined by the list you scan. If only the membership-test list is reversed while the scanned list stays increasing, the old rightmost rule still works.
11.3 · Q2

Scan common-divisor candidates backwards

What happens when the no-list gcd algorithm starts at min(m, n) and works down to 1?

Important distinction: Reversing the loop without changing its stopping rule is not enough. If we continue replacing the stored answer at every common divisor, the last stored answer will be 1.

Correct improvement: Scan downwards and stop at the first common divisor. Every larger candidate has already failed.

GCD_DESCENDING(m, n)
Input: positive integers m and n.
1. For j from min(m, n) down to 1:
   If m mod j = 0 and n mod j = 0:
      Return j and STOP.

Trace for gcd(12, 18).

Candidate jDivides both?Action
12NoContinue
11NoContinue
10NoContinue
9No: does not divide 12Continue
8NoContinue
7NoContinue
6YesReturn 6; do not test 5, 4, 3, 2, 1

Correctness: No common divisor is larger than the smaller input. We test every possible larger candidate before reaching the answer, so the first success is the greatest.

Termination: The scan is finite and 1 always divides both positive inputs. The method may stop early, but if the inputs are coprime, it still scans all the way to 1.

Answer: Return the first common divisor found. If you keep overwriting the answer until 1, the algorithm incorrectly returns 1 whenever the actual gcd is greater than 1.

End-of-Chapter Exercises

All five questions, including starred Questions 4 and 5 • Printed page 50

End · Q1

Four gcd calculations with full working

Compute (i) gcd(375, 825), (ii) gcd(51000, 81000), (iii) gcd(1789287, 237656), (iv) gcd(2587392, 157656) using the improved Euclidean algorithm.

Use the improved, remainder-based algorithm. Divide the larger number by the smaller, then replace the pair by (divisor, remainder). Repeat until the remainder is 0. The last non-zero divisor/remainder is the gcd.

GCD_REMAINDER(m, n)
Input: non-negative integers, not both 0.
1. If m < n, swap m and n.
2. While n is not 0:
   r ← m mod n
   m ← n
   n ← r
3. Return m.
Teacher’s tip: Store the remainder before changing either input. The updates must use the old pair. In school work, writing each equation m = qn + r avoids accidental overwriting.

(i) gcd(375, 825)

Start with the larger number as the dividend. In each next row, the old divisor becomes the dividend and the old remainder becomes the divisor.

825 = 375 × 2 + 75
375 = 75 × 5 + 0
StepDividendDivisorQuotientRemainder
1825375275
23757550

The last non-zero remainder is 75. Equivalently, the final division has divisor 75 and remainder 0. Stop here; do not divide by 0.

Answer: gcd(375, 825) = 75.

(ii) gcd(51,000, 81,000)

Start with the larger number as the dividend. In each next row, the old divisor becomes the dividend and the old remainder becomes the divisor.

81,000 = 51,000 × 1 + 30,000
51,000 = 30,000 × 1 + 21,000
30,000 = 21,000 × 1 + 9,000
21,000 = 9,000 × 2 + 3,000
9,000 = 3,000 × 3 + 0
StepDividendDivisorQuotientRemainder
181,00051,000130,000
251,00030,000121,000
330,00021,00019,000
421,0009,00023,000
59,0003,00030

The last non-zero remainder is 3,000. Equivalently, the final division has divisor 3,000 and remainder 0. Stop here; do not divide by 0.

Answer: gcd(51,000, 81,000) = 3,000.

Check: 51,000 = 3000 × 17 and 81,000 = 3000 × 27. Since 17 and 27 have no common factor greater than 1, the gcd is 3000. Note that this question uses 51,000, not the 54,000 from an earlier worked example in the chapter.

(iii) gcd(1,789,287, 237,656)

Start with the larger number as the dividend. In each next row, the old divisor becomes the dividend and the old remainder becomes the divisor.

1,789,287 = 237,656 × 7 + 125,695
237,656 = 125,695 × 1 + 111,961
125,695 = 111,961 × 1 + 13,734
111,961 = 13,734 × 8 + 2,089
13,734 = 2,089 × 6 + 1,200
2,089 = 1,200 × 1 + 889
1,200 = 889 × 1 + 311
889 = 311 × 2 + 267
311 = 267 × 1 + 44
267 = 44 × 6 + 3
44 = 3 × 14 + 2
3 = 2 × 1 + 1
2 = 1 × 2 + 0
StepDividendDivisorQuotientRemainder
11,789,287237,6567125,695
2237,656125,6951111,961
3125,695111,961113,734
4111,96113,73482,089
513,7342,08961,200
62,0891,2001889
71,2008891311
88893112267
9311267144
102674463
11443142
123211
132120

The last non-zero remainder is 1. Equivalently, the final division has divisor 1 and remainder 0. Stop here; do not divide by 0.

Answer: gcd(1,789,287, 237,656) = 1.

Interpretation: The numbers are coprime because their gcd is 1. This does not mean that both individual numbers are prime.

(iv) gcd(2,587,392, 157,656)

Start with the larger number as the dividend. In each next row, the old divisor becomes the dividend and the old remainder becomes the divisor.

2,587,392 = 157,656 × 16 + 64,896
157,656 = 64,896 × 2 + 27,864
64,896 = 27,864 × 2 + 9,168
27,864 = 9,168 × 3 + 360
9,168 = 360 × 25 + 168
360 = 168 × 2 + 24
168 = 24 × 7 + 0
StepDividendDivisorQuotientRemainder
12,587,392157,6561664,896
2157,65664,896227,864
364,89627,86429,168
427,8649,1683360
59,16836025168
6360168224
71682470

The last non-zero remainder is 24. Equivalently, the final division has divisor 24 and remainder 0. Stop here; do not divide by 0.

Answer: gcd(2,587,392, 157,656) = 24.
2,587,392 = 24 × 107,808
157,656 = 24 × 6,569

These divisions confirm that 24 divides both inputs; the remainder chain establishes that it is the greatest common divisor.

PartAnswerRemainder reductions
(i)752
(ii)30005
(iii)113
(iv)247
End · Q2

Why replacing a number by the remainder preserves gcd

Assume m ≥ n. Verify that d divides m and n if and only if d divides n and m mod n.

Set up the division equation. We need n > 0 so that m mod n is defined. Let d be a positive integer and let r be the remainder.

m = qn + r, 0 ≤ r < n
r = m − qn

Direction 1: common divisor of m and n ⇒ common divisor of n and r

Suppose d divides m and n. Then there are whole numbers a and b such that:

m = ad and n = bd
r = m − qn
r = ad − qbd
r = (a − qb)d

Thus r is an integer multiple of d, so d divides r. We already know d divides n. Therefore d is a common divisor of n and r.

Direction 2: common divisor of n and r ⇒ common divisor of m and n

Suppose d divides n and r. Write:

n = bd and r = cd
m = qn + r
m = qbd + cd
m = (qb + c)d

Therefore d divides m as well as n. This proves the reverse direction. The multiplier c can be 0 when the remainder is 0.

Answer: Both pairs have exactly the same common divisors; therefore gcd(m, n) = gcd(n, m mod n).
Teacher’s tip: An “if and only if” proof needs both directions. Showing just that old common divisors survive would not rule out new, larger common divisors.

Example: 60 = 3 × 16 + 12. Common divisors of 60 and 16 are [1, 2, 4]; common divisors of 16 and 12 are also [1, 2, 4]. Both gcds equal 4.

Source clarification: On printed page 48, one sentence says “m and m mod n”. The correct preserved pair is n and m mod n, as in the exercise and the algorithm. For example, gcd(60, 12) = 12, whereas gcd(60, 16) = 4; so keeping m instead of n is not generally valid.

End · Q3

Write prime(n): is a number prime?

Use the fact that a prime has exactly two distinct positive factors, 1 and itself.

Plan: First exclude integers less than 2. For a positive integer n ≥ 2, form the complete divisor list and count its entries.

PRIME(n)
Input: an integer n.
1. If n < 2:
   Return FALSE and STOP.
2. D ← DIVISORS(n)
3. If the number of entries in D is 2:
   Return TRUE.
4. Otherwise:
   Return FALSE.

DIVISORS(n)
Input: a positive integer n.
1. D ← [ ]
2. For j from 1 through n:
   If n mod j = 0:
      Append j to D.
3. Return D.
Input nDivisors / actionOutput
1n < 2: stopFALSE — 1 is not prime
2[1, 2]: two entriesTRUE
13[1, 13]: two entriesTRUE
15[1, 3, 5, 15]: four entriesFALSE
25[1, 5, 25]: three entriesFALSE

Why correct? The divisor algorithm checks every possible positive divisor. For n ≥ 2, both 1 and n occur. Exactly two entries therefore means there are no other positive divisors, which is precisely the definition of prime.

Why it stops: The divisor loop checks a finite sequence of n candidates. The output TRUE means “prime”; FALSE means “not prime”.

Optional faster version

PRIME_FAST(n)
1. If n < 2, return FALSE.
2. For j from 2 through floor(√n):
   If n mod j = 0:
      Return FALSE and STOP.
3. Return TRUE.

If n were composite, a factor pair would have at least one member between 2 and √n. Hence finding no divisor in that range proves primality. For n = 2 or 3, the loop is empty and TRUE is correctly returned.

Answer: A correct prime test checks for exactly two distinct positive divisors and excludes 1.
End · Q4 ★

Write primedivisors(n)

Compute all divisors of n that are prime numbers.

Plan: Use two tools already built: DIVISORS(n) supplies candidates and PRIME(d) filters them. A filter keeps entries that satisfy a condition and rejects the others.

PRIMEDIVISORS(n)
Input: a positive integer n.
1. D ← DIVISORS(n)
2. P ← [ ]
3. For each d in D:
   If PRIME(d) is TRUE:
      Append d to P.
4. Return P.

Trace for n = 60.

D = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60]
Divisor(s) checkedPrime?Action
1NoReject: 1 is not prime.
2YesP becomes [2].
3YesP becomes [2, 3].
4NoLeave P unchanged.
5YesP becomes [2, 3, 5].
6, 10, 12, 15, 20, 30, 60NoReject all: each is composite.
primedivisors(60) = [2, 3, 5]

Why correct? Every returned entry divides n and passes the prime test. Conversely, every prime divisor of n appears in D and will be kept. Nothing is missed and no composite number is included.

Special cases: primedivisors(1) = [ ]; primedivisors(13) = [13]; primedivisors(16) = [2]. The prime divisor 2 is listed only once for 16.

Answer: Return the distinct prime entries of the complete divisor list.
Teacher’s tip: Prime divisors and prime factorisation are not identical. For 60, the prime-divisor list is [2, 3, 5], but the factorisation is 2² × 3 × 5 because 2 occurs twice.
End · Q5 ★

Prime factorisation and comparison

Write a prime-factorisation algorithm. (i) Represent 180 = 2² × 3² × 5¹. (ii) Compare two prime factorisations to obtain their gcd.

Plan: Start with the smallest possible prime divisor, 2. Divide it out repeatedly, counting how many times it occurs. Then try the next candidate. Continue until the remaining number becomes 1.

PRIME_FACTORIZATION(n)
Input: a positive integer n.
1. remaining ← n
2. p ← 2
3. factors ← [ ]
4. While remaining > 1:
   exponent ← 0
   While remaining mod p = 0:
      remaining ← remaining ÷ p
      exponent ← exponent + 1
   If exponent > 0:
      Append the pair (p, exponent) to factors.
   p ← p + 1
5. Return factors.

All divisions performed inside the inner loop are exact. Although p tries composite candidates too, a composite candidate cannot divide the remaining number after all smaller prime factors have already been removed. Therefore every stored p is prime.

Full trace for 180

Candidate pExact divisionsExponent storedRemaining value
2180 ÷ 2 = 90; 90 ÷ 2 = 45245
345 ÷ 3 = 15; 15 ÷ 3 = 525
44 does not divide 5None5
55 ÷ 5 = 111
180 = 2 × 2 × 3 × 3 × 5
180 = 2² × 3² × 5¹

Why correct? At every step, the original number equals the product of all factors removed so far multiplied by the remaining number. A successful division transfers one factor from the remaining number to the stored factorisation, preserving that product. When the remaining number is 1, all factors have been recorded.

Why does it stop? A successful division makes the remaining positive integer smaller. If candidates fail, p increases until it reaches a divisor, at latest the remaining number itself. The process therefore reaches 1. For input 1, return [ ]: 1 has no prime factors; its empty product is 1.

(i) Representing the result

Store each distinct prime together with its exponent:

[(2, 2), (3, 2), (5, 1)]
PrimeExponentPrime power
222² = 4
323² = 9
515¹ = 5

The pair (3, 2) means “the prime 3 occurs twice”, not “multiply 3 by 2”. A repeated-factor list [2, 2, 3, 3, 5] is also valid, but prime–exponent pairs make comparison simpler.

(ii) Comparing two factorisations

Match the same prime bases. For the gcd, keep each common prime with the smaller exponent. A missing prime has exponent 0. For example, compare 180 and 252:

180 = 2² × 3² × 5¹
252 = 2² × 3² × 7¹
PrimeExponent in 180Exponent in 252Minimum for gcd
2222
3222
5100
7010
gcd(180, 252) = 2² × 3² = 36
GCD_FROM_FACTORS(m, n)
1. F ← PRIME_FACTORIZATION(m)
2. G ← PRIME_FACTORIZATION(n)
3. answer ← 1
4. For each prime p appearing in F:
   a ← exponent of p in F
   b ← exponent of p in G, or 0 if absent
   e ← min(a, b)
   Multiply answer by p exactly e times.
5. Return answer.

Why the minimum? A common divisor cannot contain more copies of a prime than either number contains. Taking every prime to its largest allowed common exponent makes the greatest possible common divisor.

If the task is to check whether the two original numbers are equal, their sorted prime–exponent lists must match exactly. If the task is lcm, use the maximum exponent over all primes appearing in either list.

lcm(180, 252) = 2² × 3² × 5 × 7 = 1260
Check: 36 × 1260 = 180 × 252 = 45,360
Answer: (i) [(2, 2), (3, 2), (5, 1)]. (ii) Match prime bases and take minimum exponents for gcd.
Teacher’s tip: Trial factorisation is a correct algorithm, but the remainder-based gcd algorithm is usually far more efficient when only the gcd is required.

Think and Reflect: complete explanations

Supplementary solutions to the chapter’s reflection prompts and in-text checks.

Printed page 39 · Reflection 1

Why digit-by-digit addition gives the correct sum

Complete the place-value argument using ones, tens, hundreds and so on.

Step 1 — Break each number into place values. For example:

473 = 4 × 100 + 7 × 10 + 3
695 = 6 × 100 + 9 × 10 + 5

Step 2 — Add equal-sized units. Ones combine with ones; tens combine with tens; hundreds combine with hundreds.

Ones: 3 + 5 = 8
Tens: 7 + 9 = 16 tens = 1 hundred + 6 tens
Hundreds: 4 + 6 + 1 carried hundred = 11 hundreds
11 hundreds = 1 thousand + 1 hundred
Total = 1 thousand + 1 hundred + 6 tens + 8 ones = 1168

General reasoning: At a place worth 10ᵏ, let the column sum be s. Write s = 10c + u, where u is its units digit and c is its carry.

s × 10ᵏ = (10c + u) × 10ᵏ
= c × 10ᵏ⁺¹ + u × 10ᵏ

Writing u in the current column and carrying c to the next column preserves the total value exactly. This is done at every place, so the completed result equals the original sum.

Answer: Carrying is a regrouping of equal value: ten units of one place become one unit of the next place. No value is created or lost.
Printed page 39 · Reflection 2

Modify addition for decimal fractions

How should the addition algorithm be changed to add two terminating decimals?

The key change is alignment. Match decimal points so that tenths line up with tenths, hundredths with hundredths, and ones with ones. Add trailing zeros when necessary; this does not change a decimal’s value.

ADD_DECIMALS(a, b)
1. Align the decimal points.
2. Add trailing zeros so both fractional parts
   have the same number of digits.
3. Treat missing whole-number places as 0.
4. Set carry ← 0.
5. Add from the rightmost digit to the left,
   using the corrected whole-number rules.
6. Put the decimal point in the answer directly
   below the aligned decimal points.
7. Write any final carry to the left.

Example: 12.75 + 3.8. First write 3.8 as 3.80.

PlaceCalculationWriteCarry
Hundredths5 + 0 = 550
Tenths7 + 8 = 1551 one
Ones2 + 3 + 1 = 660
Tens1 + 0 = 110
12.75 + 3.80 = 16.55
Answer: Align decimal points, pad with zeros, and preserve the decimal point’s position in the answer.
Teacher’s tip: Right-aligning the last written digits of 12.75 and 3.8 would put hundredths under tenths and give an incorrect calculation.
Printed page 41 · Reflection

Execute the divisor algorithm

Find divisors of 15, 135 and 775. Explain how the amount of work increases.

Use the chapter’s basic algorithm: start with [ ], test every j from 1 through n, and append j only if n mod j = 0. The following tables display successful updates; all other tested candidates leave the list unchanged.

Divisors of 15

Successful candidate jExact divisionList after appending
115 ÷ 1 = 15[1]
315 ÷ 3 = 5[1, 3]
515 ÷ 5 = 3[1, 3, 5]
1515 ÷ 15 = 1[1, 3, 5, 15]
Answer: divisors(15) = [1, 3, 5, 15].

Divisors of 135

Successful candidate jExact divisionList after appending
1135 ÷ 1 = 135[1]
3135 ÷ 3 = 45[1, 3]
5135 ÷ 5 = 27[1, 3, 5]
9135 ÷ 9 = 15[1, 3, 5, 9]
15135 ÷ 15 = 9[1, 3, 5, 9, 15]
27135 ÷ 27 = 5[1, 3, 5, 9, 15, 27]
45135 ÷ 45 = 3[1, 3, 5, 9, 15, 27, 45]
135135 ÷ 135 = 1[1, 3, 5, 9, 15, 27, 45, 135]
Answer: divisors(135) = [1, 3, 5, 9, 15, 27, 45, 135].

Divisors of 775

Successful candidate jExact divisionList after appending
1775 ÷ 1 = 775[1]
5775 ÷ 5 = 155[1, 5]
25775 ÷ 25 = 31[1, 5, 25]
31775 ÷ 31 = 25[1, 5, 25, 31]
155775 ÷ 155 = 5[1, 5, 25, 31, 155]
775775 ÷ 775 = 1[1, 5, 25, 31, 155, 775]
Answer: divisors(775) = [1, 5, 25, 31, 155, 775].

How does the work grow? The basic procedure performs one divisibility test for each j from 1 to n, so it performs n tests. The number of divisors found is not the number of tests performed.

InputTests in the original algorithmDivisors foundTests using divisor pairs
151543
135135811
775775627

Thus the original algorithm takes 15, 135 and 775 tests for these inputs. From 15 to 135, the input is multiplied by 9 and so is the test count. In general, if the input value is multiplied by 10, this algorithm performs 10 times as many divisibility tests.

Teacher’s tip: Having one more digit does not mean every individual input is exactly ten times as large: 999 and 1000 are close. The chapter’s scaling discussion concerns input values growing by about a factor of ten.
Printed pages 46–48 · In-text checks

Why subtraction works, and why remainders are faster

Explain the reduction rule, the stopping condition and the example gcd(2k + 1, 2).

1. The subtraction rule

For m ≥ n, any common divisor d of m and n divides m − n. Conversely, if d divides n and m − n, it also divides their sum m. Thus the common-divisor sets are identical.

gcd(m, n) = gcd(n, m − n)

2. Why the process stops

After arranging m ≥ n > 0, replacing (m, n) by (n, m − n) reduces the sum of the two entries from m + n to m. A strictly decreasing positive-integer sum cannot decrease forever. Eventually one entry is 0.

gcd(a, 0) = a for a > 0

Every positive integer divides 0, but a common divisor must also divide a. Hence the greatest common divisor is a, not 0.

3. A short subtraction trace

gcd(60, 16) = gcd(44, 16)
= gcd(28, 16)
= gcd(16, 12)
= gcd(12, 4)
= gcd(8, 4)
= gcd(4, 4)
= gcd(4, 0) = 4

The pairs above are reordered when necessary so the larger number is shown first. Reordering does not change common divisors.

4. The same input with remainder division

60 = 3 × 16 + 12
16 = 1 × 12 + 4
12 = 3 × 4 + 0
Therefore gcd(60, 16) = 4.

A single remainder step performs the effect of several repeated subtractions.

5. Odd-number example

For an odd number 2k + 1 ≥ 3, dividing by 2 always leaves remainder 1.

2k + 1 = 2 × k + 1
gcd(2k + 1, 2) = gcd(2, 1)
2 = 2 × 1 + 0
gcd(2, 1) = gcd(1, 0) = 1

Thus two remainder reductions are sufficient for every odd input at least 3. For the boundary case k = 0, the input is gcd(1, 2); after swapping, only one division 2 = 2 × 1 + 0 is needed.

Answer: The remainder method preserves the gcd while reducing the problem much faster than repeated subtraction on inputs such as 99 and 2.

Final revision: what a strong answer includes

TopicRemember this
AdditionAlign place values, include carry, and handle column totals equal to 10.
Unequal lengthsTreat missing positions as 0.
Divisor pairsTest only through ⌊√n⌋; do not duplicate the square root.
Ordered lists“Last common item is greatest” requires increasing output order.
Descending searchStop at the first common divisor.
Remainder gcdReplace (m, n) with (n, m mod n), stopping before division by 0.
Prime testExactly two distinct positive divisors; 1 is not prime.
Prime divisor listList distinct prime factors once each.
Prime factorisationRecord each prime with its exponent.
Gcd from factorsTake minimum exponents of matching primes.

Correctness and efficiency are different. An algorithm can be correct but slow. Scanning every candidate to min(m, n) depends on the numerical value of the input. Repeated subtraction can also be slow. The division algorithm needs far fewer reduction steps; its step count grows on the order of the number of digits in the worst case. A division itself still involves arithmetic work, so “number of reductions” is not the same as “number of single-digit operations”.

Exam answer checklist: State valid inputs; initialise every variable; specify the loop and its bounds; explain each conditional update; state the stopping condition and output; give a short trace; explain why the procedure works.

SK CLASSES • Understand the steps. Explain the reason.

Source: the supplied Chapter 11, “The World of Algorithms”, Ganita Manjari, Grade 9, Part II, printed pages 37–50. Solutions, illustrative inputs and teaching explanations were prepared for this guide. Optional improvements and textbook wording clarifications are labelled within the relevant solutions.

Leave a Reply

SK Tuitions provides high-quality CBSE study material for Classes 6 to 10, including chapter-wise notes, worksheets, important questions, practice tests and concept-based explanations for Maths and Science. The aim is to make learning simple, structured and exam-focused for every student.

Let’s connect

Discover more from SK Tuitions

Subscribe now to keep reading and get access to the full archive.

Continue reading

tag here. */