Ganita Manjari Class 9 Ch 11 The World of Algorithms Solutions
Home › Class 9 Maths & Science › Class 9 Maths NCERT Solutions, Part II › Chapter 11: The World of Algorithms
📘 Ganita Manjari · Part II · CBSE 2026-27 ✨ Free — No Sign-up 17 Questions

Chapter 11The World of Algorithms

Class 9 Maths Ganita Manjari NCERT Solutions Chapter 11: The World of Algorithms, from the CBSE 2026-27 Part II textbook, with every step of working shown in full, exactly the way you'd be expected to present it in an answer sheet. Covers what an algorithm is, the digit-by-digit addition algorithm, computing the divisors of a number, the greatest common divisor (GCD), data structures, Euclid's subtraction algorithm and Āryabhaṭa's division algorithm — including every "Think and Reflect" box, all 3 Exercise Sets and the End-of-Chapter questions.

17Solved Questions
2Think & Reflect
100%NCERT Aligned
Get the Class 9 Formula Card →

Key Concepts & Formulae at a Glance

  • An algorithm is a systematic, step-by-step procedure to solve a problem, described precisely enough that someone else can follow it without guessing.
  • Algorithm steps can repeat (for each number from 1 to n, ...) and can be conditional (only add j to the list if j divides n).
  • Every algorithm needs two things checked: is it correct (does it always give the right answer, and why), and is it efficient (how does the number of steps grow as the input grows)?
  • A list is a simple data structure — a named, ordered collection of values that an algorithm builds up and refers back to.
  • The basic GCD algorithm: compute divisors(m) and divisors(n), then scan for the largest number common to both lists.
  • Euclid's subtraction algorithm: if \(m \geq n\), \(\gcd(m,n) = \gcd(n,\,m-n)\), and \(\gcd(m,0) = m\).
  • Āryabhaṭa's division algorithm (the modern, efficient version): \(\gcd(m,n) = \gcd(n,\,m \bmod n)\), where \(m \bmod n\) is the remainder when \(m\) is divided by \(n\). This needs a number of steps proportional to the number of digits in \(m\) and \(n\), not to their value.
\[ \text{Euclid: } \gcd(m,n) = \gcd(n,\, m-n) \quad (m \geq n) \] Improved (Āryabhaṭa): \[ \gcd(m,n) = \gcd(n,\, m \bmod n), \qquad \gcd(m,0) = m \]

This chapter steps back from any one topic in mathematics and asks a more basic question: what exactly is an algorithm? It starts with something you already know how to do without thinking — adding two numbers digit by digit — and shows that this is itself an algorithm, a precise sequence of steps. Writing it down that precisely is what lets us ask sharp questions about it: does it always work, and how much effort does it take as the numbers get bigger?

The chapter then uses the same lens on a familiar problem, the greatest common divisor. It builds up an algorithm from the plain definition of gcd, then improves it in stages — first combining two scans into one, then dropping the lists altogether — before arriving at two historically important solutions: Euclid's subtraction algorithm from his Elements, and the faster division-based algorithm recorded by Āryabhaṭa, whose Sanskrit name for the method eventually gave the word "algorithm" itself its meaning, by way of the 9th-century mathematician Al-Khwārizmī.

11.1 Adding Numbers — Exercise Set 11.1

Answers to all 5 questions on the digit-by-digit addition algorithm (section 11.1.1).

Algorithm to add two numbers
  1. Write the numbers one below the other in the Indian base-ten place-value system so that the digits are aligned from right to left.
  2. Add the rightmost digits.
    • If the sum is less than 10, write the sum directly below the two digits. Set the value of carry to 0.
    • If the sum is 10 or more, write the units digit of the sum directly below the two digits. Set the value of carry to 1.
  3. Move to the next column of digits on the left. Add the two digits and the current value of carry.
    • If the sum is less than 10, write the sum directly below the two digits. Set the value of carry to 0.
    • If the sum is 10 or more, write the units digit of the sum directly below the two digits. Set the value of carry to 1.
  4. Repeat Step 3 until there are no more digits on the left.
  5. If the value of carry is 1, write 1 to the left of the bottom row.
1Add two 4-digit numbers using the steps we have written down. Make sure you follow the steps precisely; do not perform any action that is not explicitly mentioned. Are you able to obtain the correct result?

Let us add 4728 and 3695, following the five steps exactly as written.

  • Step 1: Write one below the other, aligned from the right: 4728 over 3695.
  • Step 2 (rightmost column): \(8 + 5 = 13\). This is 10 or more, so write the units digit, 3, and set carry = 1.
  • Step 3 (next column left): \(2 + 9 + 1(\text{carry}) = 12\). This is 10 or more, so write 2, set carry = 1.
  • Step 4 (repeat Step 3, next column): \(7 + 6 + 1 = 14\). Write 4, set carry = 1.
  • Step 4 (repeat Step 3, next column — the leftmost digits): \(4 + 3 + 1 = 8\). This is less than 10, so write 8, set carry = 0.
  • No more digits remain on the left, so Step 4's repetition stops.
  • Step 5: The final carry is 0, so nothing more is written.

Reading the bottom row left to right gives 8423.

4728 + 3695 = 8423, and following the steps precisely, without adding anything extra, gives exactly this correct result.
2What happens if you add a 5-digit number to a 3-digit number? Do our steps handle this situation correctly?

Try adding 42536 (5 digits) and 178 (3 digits). Written one below the other, aligned from the right:

  42536
  +  178

The rightmost 3 columns have a digit from both numbers, so Steps 2–3 work exactly as written: units \(6+8=14\) → write 4, carry 1; tens \(3+7+1=11\) → write 1, carry 1; hundreds \(5+1+1=7\) → write 7, carry 0.

But once we move further left, the 3-digit number has run out of digits — there is no digit of 178 in the thousands or ten-thousands column. The algorithm as literally written only says "add the two digits and the current value of carry" — it never says what to do when one number has no digit in that column.

In practice, we handle this by silently treating a missing digit as 0 (thousands: \(2+0+0=2\); ten-thousands: \(4+0+0=4\)), which gives the correct answer 42714. But this is an extra rule we are implicitly assuming, not one of the 5 steps as written.

The steps get the correct answer, 42714, but only if we silently assume a missing digit counts as 0 — the written algorithm does not explicitly say this, so strictly speaking it is incomplete for numbers of different lengths.
3Why is it important to align the columns from right to left?

In the Indian (and international) place-value system, a digit's position tells us its place value — units, tens, hundreds, and so on — counting from the rightmost digit. Aligning from the right guarantees that units sit under units, tens under tens, hundreds under hundreds, and so on, so that when we add a column we are always adding quantities of the same place value.

If we instead aligned from the left, digits of different place value would land in the same column — for instance, adding 47 and 138 by left-aligning would put the 4 (tens) of 47 under the 1 (hundreds) of 138, giving a meaningless sum.

Right-to-left alignment ensures every column adds digits of the same place value (units with units, tens with tens, ...), which is exactly what makes column-by-column addition correct.
4In Step 3, why cannot the value of carry be more than 1?

In Step 3, we add two digits (each digit is between 0 and 9) together with a carry that is already either 0 or 1. The largest possible sum is therefore \(9 + 9 + 1 = 19\).

Since 19 is less than 20, dividing it by 10 gives a quotient of at most 1 — that is, the new carry (the number of complete tens generated) can only be 0 or 1, never 2 or more.

The largest possible column sum is 9 + 9 + 1 = 19, which produces at most one ten to carry, so the carry can never exceed 1.
5What happens if we do not include the fifth step in the algorithm above? Give examples where the algorithm will work correctly and where it will fail to work.

Step 5 only matters when the very last (leftmost) column produces a carry of 1 — that carry has nowhere left to go except a brand-new digit at the front of the answer.

Where it still works without Step 5: \(123 + 456\). Adding column by column: \(3+6=9\), \(2+5=7\), \(1+4=5\), and the final carry is 0. Since there is no leftover carry, skipping Step 5 makes no difference — the answer 579 is unaffected.

Where it fails without Step 5: \(999 + 1\). Units: \(9+1=10\) → write 0, carry 1. Tens: \(9+0+1=10\) → write 0, carry 1. Hundreds: \(9+0+1=10\) → write 0, carry 1. Without Step 5 to record this final carry, we would report the answer as just "000", i.e. 0 — instead of the correct answer, 1000.

Without Step 5, the algorithm still works whenever the leftmost column has no final carry (e.g. 123 + 456 = 579), but fails whenever it does (e.g. 999 + 1 gives 000 instead of the correct 1000).

Think and Reflect

TR1. See if you can complete the argument about grouping by units, tens, hundreds, ... to justify why the addition algorithm works. 2. How would you modify the algorithm to add two decimal fractions?

(1) Justifying the algorithm. Every number can be split into a units group, a tens group, a hundreds group, and so on — this is exactly what the Indian place-value system records. Adding two numbers means adding each of these groups separately: the units of one number with the units of the other, the tens with the tens, and so on.

The only complication is that a group's sum can itself reach or exceed ten of that unit. For instance, if the units digits add to 13, that is 1 ten and 3 units — the 3 units stay in the units place, and the 1 ten must be moved over and combined with the tens group, since a "ten of the units" is worth exactly one unit of the next group up. This is precisely what "carry" does: it moves the newly-formed larger unit into the next column so it is counted in the right group. Since every column is handled this way, from the smallest place value to the largest, the final combined answer correctly represents the sum, grouped and re-grouped consistently at every place value.

(2) Adding decimal fractions. The key idea — aligning quantities of the same place value — extends naturally to decimals: we now align both the decimal points and the digits, so that tenths line up with tenths, hundredths with hundredths, and so on (padding the shorter decimal part with trailing zeros if the two numbers have a different number of decimal places). We then add right to left exactly as before, starting from the smallest place value, carrying between columns in exactly the same way, and finally placing the decimal point in the answer directly below the aligned decimal points.

For example, to add 4.7 and 12.85, we treat 4.7 as 4.70, align: \(4.70 + 12.85\), add right to left as 470 + 1285 = 1755, and place the decimal point back two digits from the right: 17.55.

The algorithm works because carrying correctly moves a "full ten" of one place value into the next; for decimals, we simply align the decimal points (padding with trailing zeros where needed) and then add exactly as before.

11.2 Greatest Common Divisor — Worked Examples

Full working for the in-text examples of section 11.2, including the divisors algorithm, the first GCD algorithm, and the second Think and Reflect box.

Algorithm to find the divisors of n
  1. Start with an empty list-of-divisors.
  2. For each number j in the sequence \(1, 2, 3, \ldots, n\):
    • if j divides n, add j to the list-of-divisors.

Executing this for n = 18: list-of-divisors starts empty, [ ]. Checking each number from 1 to 18 in turn: 1, 2, 3 all divide 18, so the list grows to [1, 2, 3]; 4 and 5 do not divide 18, so the list is unchanged; 6 divides 18, giving [1, 2, 3, 6]; 7 and 8 do not divide it; 9 divides 18, giving [1, 2, 3, 6, 9]; 10 through 17 do not divide it; finally 18 divides itself, giving the final list.

\(\text{divisors}(18) = [1, 2, 3, 6, 9, 18]\). The list comes out already in increasing order, because we checked systematically from 1 up to 18.

Running the same algorithm on 375 and 825 gives:

  • \(\text{divisors}(375) = [1, 3, 5, 15, 25, 75, 125, 375]\)
  • \(\text{divisors}(825) = [1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275, 825]\)

Think and Reflect

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

Running the divisors algorithm on each number (checking every j from 1 up to n):

  • \(\text{divisors}(15) = [1, 3, 5, 15]\) — 15 numbers checked, 4 found to be divisors.
  • \(\text{divisors}(135) = [1, 3, 5, 9, 15, 27, 45, 135]\) — 135 numbers checked, 8 found to be divisors.
  • \(\text{divisors}(775) = [1, 5, 25, 31, 155, 775]\) — 775 numbers checked, 6 found to be divisors.

Notice that the amount of checking work (how many numbers we test between 1 and n) grows exactly in proportion to n itself — computing divisors(775) needs roughly 52 times as many checks as divisors(15), simply because 775 is about 52 times as large as 15. This is true even though the length of the resulting list does not grow in the same steady way — 135 has more divisors than 775, even though 775 is the bigger number, because how many divisors a number has depends on its prime factorisation, not just its size.

The work (the number of checks performed) grows directly with the value of n, not with how many divisors it happens to have — a much larger number can even end up with a shorter divisor list.

If the numbers are large, comparing their divisor lists by eye stops being practical. For instance:

  • \(\text{divisors}(54000)\) has 70 entries, from 1 up to 54000.
  • \(\text{divisors}(81000)\) has 80 entries, from 1 up to 81000.

To find the gcd systematically, we build a new list, the list of common divisors: starting empty, for each divisor in the first list we check whether it also appears in the second list, and if so we add it to the common list. Since 1 divides every number, this list always has at least one entry. Carrying this out for 54000 and 81000 gives a list of common divisors ending in ..., 13500, 27000 — and since each divisor list is in increasing order, the list of common divisors is too, so the largest common divisor is simply its rightmost entry: \(\gcd(54000, 81000) = 27000\).

Algorithm to find gcd(m, n)
  1. Let divisors-of-m be the list obtained by computing divisors(m).
  2. Let divisors-of-n be the list obtained by computing divisors(n).
  3. Start with an empty list common-divisors.
  4. For each number x in the list divisors-of-m:
    • If x also appears in the list divisors-of-n, add x to the list common-divisors.
  5. Report the rightmost element of the list common-divisors as gcd(m, n).

Executing this for gcd(375, 825): we check each of the divisors [1, 3, 5, 15, 25, 75, 125, 375] of 375 against the divisor list of 825. The numbers 1, 3, 5, 15, 25 and 75 all appear in divisors(825), while 125 and 375 do not. So common-divisors = [1, 3, 5, 15, 25, 75], and its rightmost element gives \(\gcd(375, 825) = 75\).

Exercise Set 11.2

Answers to all 3 questions (Q3 is a starred, two-part question).

1Suppose List 1 and List 2 are two lists of numbers in increasing order. (i) Write an algorithm to find elements in List 1 that are not present in List 2. (ii) Write an algorithm to find elements in List 2 that are not present in List 1.
Algorithm: elements of List 1 not present in List 2
  1. Start with an empty list only-in-1.
  2. For each number x in List 1:
    • If x does not appear anywhere in List 2, add x to only-in-1.
  3. Report only-in-1.

(ii) is exactly the same idea with the two lists swapped:

Algorithm: elements of List 2 not present in List 1
  1. Start with an empty list only-in-2.
  2. For each number y in List 2:
    • If y does not appear anywhere in List 1, add y to only-in-2.
  3. Report only-in-2.

Since both lists are already sorted in increasing order, an even more efficient version scans both lists together with two markers, one on each list, moving whichever marker points to the smaller current value forward — very similar in spirit to how we later combine the two divisor scans into one (section 11.3.1).

Check every element of one list for membership in the other, and collect the ones that don't appear — this can also be sped up by scanning both sorted lists together with two pointers instead of searching one list from scratch each time.
2Describe an algorithm to compute the least common multiple (lcm) of two numbers.

One direct approach mirrors the gcd algorithm exactly, but scans multiples instead of divisors:

Algorithm to find lcm(m, n)
  1. Starting from k = 1, generate the multiples of m: \(m, 2m, 3m, \ldots\), and separately the multiples of n: \(n, 2n, 3n, \ldots\), each as an increasing list.
  2. Compare the two lists of multiples and find the smallest number that appears in both.
  3. Report this number as lcm(m, n).

A faster approach uses a gcd algorithm we already have: since \(m \times n = \gcd(m,n) \times \text{lcm}(m,n)\), we can compute

\[ \text{lcm}(m,n) = \dfrac{m \times n}{\gcd(m,n)} \]

This needs only one gcd computation (which we already know how to do efficiently) instead of generating and comparing two growing lists of multiples.

lcm(m, n) can be found by comparing lists of multiples until the smallest common one appears, or far more efficiently as (m × n) ÷ gcd(m, n), reusing the gcd algorithm.
3★ Divisors occur in pairs — for instance, the divisors of 18 are (1, 18), (2, 9) and (3, 6). (i) If we write out divisors in pairs, how many numbers do we have to examine between 1 and n to find all the divisors of n? (ii) If we list out the divisors in pairs, will our gcd algorithm still work in the manner we have described?

(i) Every divisor \(d\) of \(n\) pairs up with a partner divisor \(n/d\), and one of the two partners in each pair is always at most \(\sqrt{n}\) (they can only both equal \(\sqrt{n}\) when n is a perfect square). So instead of checking every number from 1 to n, we only need to check numbers from 1 up to \(\sqrt{n}\) — whenever we find that j divides n, we immediately know both j and \(n/j\) are divisors, without having to test \(n/j\) separately. For \(n = 18\), that means checking only up to \(\sqrt{18} \approx 4.24\), i.e. just \(j = 1, 2, 3, 4\), instead of all 18 numbers.

(ii) Not directly. Our gcd algorithm relied on each divisor list being built in strictly increasing order, so that the largest common divisor was simply the rightmost entry once we scanned it. But finding divisors in pairs produces them out of order — for instance for 18 we would find the pair (1, 18) first, then (2, 9), then (3, 6), giving something like [1, 18, 2, 9, 3, 6], which is not sorted. So "look at the rightmost element" would no longer reliably give the gcd; we would instead need to keep explicit track of the largest divisor seen so far (updating it whenever a new, larger one turns up in either half of a pair) rather than relying on the list's order.

(i) Only about √n numbers need to be examined, since divisors come in pairs around √n. (ii) The gcd algorithm needs to change: pairs are discovered out of order, so we must track the running maximum common divisor explicitly instead of just reading off the rightmost list entry.

11.3 Data Structures — Exercise Set 11.3

A list, like the ones used above, is an example of a data structure — a way of organising information that makes an algorithm easier to describe and more efficient to run. Section 11.3.1 improves the gcd algorithm in three stages before Exercise Set 11.3.

Stage 1 — combine the two scans into one. Instead of first scanning 1 to m for divisors of m, then separately scanning 1 to n for divisors of n (m + n checks in total), we run through each j from 1 to \(\max(m,n)\) once, checking both "does j divide m?" and "does j divide n?" together. This cuts the checks needed from \(m+n\) down to \(\max(m,n)\).

Stage 2 — compute common divisors directly. Rather than building both full divisor lists and then comparing them, we check directly: for each j from 1 to \(\max(m,n)\), if j divides both m and n, add it straight to the list of common divisors. Since a common divisor can never exceed the smaller of the two numbers, we can also shrink the range we check to \(1\) up to \(\min(m,n)\).

Stage 3 — do away with lists altogether. Once we realise that each new, larger common divisor makes every earlier one useless to remember, we only need to keep track of a single running value, most-recent-common-divisor, starting at 1 (since 1 always divides everything) and updated to k whenever k (scanning from 2 up to \(\min(m,n)\)) divides both m and n. At the end of the scan, this value is the gcd — no list required.

Example: m = 6, n = 12. min(6, 12) = 6. Start most-recent-common-divisor = 1.
k = 2 divides both 6 and 12 → update to 2.
k = 3 divides both 6 and 12 → update to 3.
k = 4 does not divide 6 → remains 3.
k = 5 does not divide 6 → remains 3.
k = 6 divides both 6 and 12 → update to 6.
Scan complete. gcd(6, 12) = 6
1How would our original algorithm change if we computed the divisors of n by examining the numbers from 1 to n in reverse order, from n down to 1?

What the algorithm computes would not change — the set of divisors found is exactly the same, since every number from 1 to n is still checked, just in the opposite order.

What would change is the order of the resulting list: scanning from n down to 1 produces the divisors in decreasing order instead of increasing order. This matters for the gcd algorithm, which relies on the list being in increasing order so that the largest common divisor is the rightmost entry. If the list is instead in decreasing order, the largest common divisor would be the leftmost entry (the first one found), not the rightmost.

The set of divisors found is identical, but the list comes out in decreasing order, so we would need to read off the gcd from the leftmost entry instead of the rightmost.
2What about the last algorithm described above? What happens when we look at common divisors starting from min(m, n) and work backwards to 1?

This is actually a useful improvement. If we scan k from \(\min(m,n)\) down to 1 instead of from 2 up, the very first value of k we find that divides both m and n is automatically the largest such value — because we started checking from the biggest possible candidate and are working downward.

This means we do not need to scan all the way down to 1 at all: as soon as we find one common divisor, we can stop immediately and report it as the gcd, since nothing smaller that we haven't checked yet could possibly beat it. In the best case (for example, when \(\min(m,n)\) itself divides both numbers) this finds the gcd in a single check, though in the worst case (when the gcd is 1) it still has to scan all the way down to 1.

Scanning downward from min(m, n), the first common divisor found is automatically the gcd, so the algorithm can stop as soon as it finds one — no need to keep scanning to the end.

Each improvement above only changes how efficiently the gcd is computed, not what is being computed — since every version is derived from the same basic definition, all of them are guaranteed to give the correct answer. But even the best of these list-free versions still has to examine every number from 1 (or min(m,n)) up to min(m,n) in the worst case: if the smaller number grows from 3 digits to 4 digits, the algorithm has to check roughly 10 times as many values, and 100 times as many if it grows from 3 digits to 5 digits — exactly the same problem we saw with counting dots to add numbers.

Euclid's Subtraction Algorithm & Āryabhaṭa's Division Algorithm

Full working for sections 11.3.3 and 11.3.4 — an algorithm for gcd where the effort is proportional to the number of digits, not the value, of the numbers.

Reducing a problem to a simpler one. Euclid's algorithm (from his book Elements) uses one key fact: if \(m \geq n\), then \(\gcd(m,n) = \gcd(n,\, m-n)\).

Why this is true: if d is a common divisor of m and n, we can write \(m = ad\) and \(n = bd\) for natural numbers a and b. Then \(m - n = ad - bd = (a-b)d\), so d also divides \(m-n\). Conversely, if d divides both n and \(m-n\), write \(n = xd\) and \(m - n = yd\); then \(n + (m-n) = m = xd + yd = (x+y)d\), so d also divides m. Since every common divisor of (m, n) is a common divisor of \((n, m-n)\) and vice versa, the two pairs have exactly the same gcd.

d d d d d m d d d d d n m − n
Fig. 11.1: If m and n can both be tiled by blocks of size d, then m − n can be tiled by blocks of the same size d — so any common divisor of m and n is also a common divisor of n and m − n.
Euclid's algorithm for gcd(m, n)
  1. If \(m < n\), reverse the numbers and compute gcd(n, m).
  2. If \(n = 0\), report the answer as m.
  3. Otherwise, reduce the problem to computing gcd(n, m − n).
Applying it to gcd(375, 825):
375 < 825 → reverse → gcd(825, 375)
825 − 375 = 450 → gcd(375, 450)
375 < 450 → reverse → gcd(450, 375) → 450 − 375 = 75 → gcd(375, 75)
375 > 75 → 375 − 75 = 300 → gcd(75, 300)
75 < 300 → reverse → gcd(300, 75) → 300 − 75 = 225 → gcd(75, 225)
75 < 225 → reverse → gcd(225, 75) → 225 − 75 = 150 → gcd(75, 150)
75 < 150 → reverse → gcd(150, 75) → 150 − 75 = 75 → gcd(75, 75)
75 − 75 = 0 → gcd(75, 0)
n = 0 → answer is 75. gcd(375, 825) = 75

This took 7 reduction steps. Unfortunately, subtraction-based reduction is not always this quick: \(\gcd(99, 2)\) reduces successively through \(\gcd(97,2), \gcd(95,2), \ldots, \gcd(3,2), \gcd(2,1), \gcd(1,1), \gcd(1,0)\) — about 49 steps — because each step only subtracts 2. In general, \(\gcd(2k+1,\, 2)\) needs about k reduction steps: the number of steps is proportional to the value of the number, not to how many digits it has, so subtraction alone does not solve our efficiency problem.

Āryabhaṭa's improvement. The Āryabhaṭīya (499 CE) describes an equivalent but far faster reduction: instead of repeatedly subtracting n from m one step at a time, subtract as many copies of n as possible in one move — that is, replace \(m - n\) with \(m \bmod n\), the remainder when m is divided by n. Since a divisor "tiles" m and n if and only if it tiles n and \(m - n\), the same tiling argument shows a divisor tiles m and n if and only if it tiles n and \(m \bmod n\) — so \(\gcd(m,n) = \gcd(n,\, m \bmod n)\) exactly as before, just reached in far fewer steps.

Āryabhaṭa's division algorithm for gcd(m, n)
  1. If \(m < n\), reverse the numbers and compute gcd(n, m).
  2. If \(n = 0\), report the answer as m.
  3. Otherwise, reduce the problem to computing gcd(n, m mod n).

Revisiting \(\gcd(99, 2)\), which took about 49 subtraction steps, the mod-based version needs just two: \(99 \bmod 2 = 1 \Rightarrow \gcd(2,1)\), then \(2 \bmod 1 = 0 \Rightarrow \gcd(1,0) = 1\).

This "long division" style of computing gcd goes back at least to Āryabhaṭa. Three worked examples, in the same long-division style as the textbook:

1. gcd(99, 2): \(99 = 49 \times 2 + 1\) → gcd(2, 1)
\(2 = 2 \times 1 + 0\) → gcd(1, 0) = 1
2. gcd(825, 375): \(825 = 2 \times 375 + 75\) → gcd(375, 75)
\(375 = 5 \times 75 + 0\) → gcd(75, 0) = 75
3. gcd(60, 16): \(60 = 3 \times 16 + 12\) → gcd(16, 12)
\(16 = 1 \times 12 + 4\) → gcd(12, 4)
\(12 = 3 \times 4 + 0\) → gcd(4, 0) = 4

It can be shown (though the full justification is left for later grades) that the number of reduction steps this division-based method needs is proportional to the number of digits in m and n — which is exactly the kind of efficient algorithm we were looking for.

A Pinch of History

The Persian mathematician Al-Khwārizmī (780–850 CE), a scholar at the "House of Wisdom" in Baghdad, developed a great liking for Indian mathematics. He learnt Sanskrit, and around 820 CE wrote a detailed treatise expounding the Indian place-value number system and the Indian procedures for addition, subtraction, multiplication and division. His original is lost, but its 12th-century Latin translation, Liber Algorismi de numero Indorum ("The Book of Al-Khwārizmī on Indian Numerals"), survives and played a major role in spreading Indian arithmetic through medieval Europe. Al-Khwārizmī's name became so closely tied to these methods that the word algorismus — from Algoritmi, the Latin form of his name — came to mean any Indian method of numerical computation; it later contracted to algorism and then algorithm. Etymologically, then, "algorithm" originally denoted an Indian method of arithmetic, before it broadened to mean any well-defined, step-by-step systematic procedure for solving a class of problems.

End-of-Chapter Exercises

Answers to all 5 End-of-Chapter questions (Q4 and Q5 are starred).

1Compute the following using the improved version of Euclid's algorithm. (i) gcd(375, 825) (ii) gcd(51000, 81000) (iii) gcd(1789287, 237656) (iv) gcd(2587392, 157656)

Using the division-based reduction \(\gcd(m,n) = \gcd(n, m \bmod n)\) throughout:

(i) gcd(375, 825): 825 mod 375 = 75 → gcd(375, 75)
375 mod 75 = 0 → gcd(75, 0) = 75
(ii) gcd(51000, 81000): 81000 mod 51000 = 30000 → gcd(51000, 30000)
51000 mod 30000 = 21000 → gcd(30000, 21000)
30000 mod 21000 = 9000 → gcd(21000, 9000)
21000 mod 9000 = 3000 → gcd(9000, 3000)
9000 mod 3000 = 0 → gcd(3000, 0) = 3000
(iii) gcd(1789287, 237656): 1789287 mod 237656 = 125695 → gcd(237656, 125695)
237656 mod 125695 = 111961 → gcd(125695, 111961)
125695 mod 111961 = 13734 → gcd(111961, 13734)
111961 mod 13734 = 2089 → gcd(13734, 2089)
13734 mod 2089 = 1200 → gcd(2089, 1200)
2089 mod 1200 = 889 → gcd(1200, 889)
1200 mod 889 = 311 → gcd(889, 311)
889 mod 311 = 267 → gcd(311, 267)
311 mod 267 = 44 → gcd(267, 44)
267 mod 44 = 3 → gcd(44, 3)
44 mod 3 = 2 → gcd(3, 2)
3 mod 2 = 1 → gcd(2, 1)
2 mod 1 = 0 → gcd(1, 0) = 1

1789287 and 237656 share no common factor other than 1 — they are coprime.

(iv) gcd(2587392, 157656): 2587392 mod 157656 = 64896 → gcd(157656, 64896)
157656 mod 64896 = 27864 → gcd(64896, 27864)
64896 mod 27864 = 9168 → gcd(27864, 9168)
27864 mod 9168 = 360 → gcd(9168, 360)
9168 mod 360 = 168 → gcd(360, 168)
360 mod 168 = 24 → gcd(168, 24)
168 mod 24 = 0 → gcd(24, 0) = 24
(i) 75   (ii) 3000   (iii) 1 (coprime)   (iv) 24
2Assume that m ≥ n. Verify that d divides m and n if and only if d divides both n and m mod n.

Write \(m = qn + r\), where \(q\) is the quotient and \(r = m \bmod n\) is the remainder when m is divided by n, with \(0 \le r < n\).

Forward direction: suppose d divides both m and n. Since \(r = m - qn\), and d divides m and d divides n (so d also divides \(qn\)), d must divide the difference \(m - qn = r\). So d divides both n and r (= m mod n).

Reverse direction: suppose d divides both n and r. Since \(m = qn + r\), and d divides n (so d divides \(qn\)) and d divides r, d must divide the sum \(qn + r = m\). So d divides both m and n.

Since each direction holds, d divides m and n if and only if d divides n and m mod n — exactly the fact that justifies reducing \(\gcd(m,n)\) to \(\gcd(n, m \bmod n)\).

Writing m = qn + r (r = m mod n): if d | m and d | n then d | (m − qn) = r; if d | n and d | r then d | (qn + r) = m. So the two pairs of numbers always have exactly the same common divisors, and hence the same gcd.
3Write an algorithm prime(n) to check if n is prime. (Hint: A prime number p has exactly two distinct factors, 1 and p. Can you make use of divisors(n) to write out prime(n)?)
Algorithm prime(n)
  1. Compute the list divisors(n) using the divisors algorithm from section 11.2.1.
  2. Count how many entries are in this list.
  3. If the count is exactly 2 (which, since 1 and n are always divisors of n, means the only divisors are 1 and n), report that n is prime. Otherwise, report that n is not prime.

For example, divisors(7) = [1, 7], which has exactly 2 entries, so prime(7) reports true. But divisors(8) = [1, 2, 4, 8], which has 4 entries, so prime(8) reports false.

Compute divisors(n); n is prime exactly when that list has exactly 2 entries (1 and n itself, with nothing in between).
4★ Write an algorithm primedivisors(n) to compute the list of divisors of n that are prime numbers. (Hint: Compute divisors(n) and then filter out the primes in this list.)
Algorithm primedivisors(n)
  1. Compute the list divisors(n).
  2. Start with an empty list, primedivisors-of-n.
  3. For each number d in divisors(n): check whether d is prime, using the prime(d) algorithm from Q3. If prime(d) reports true, add d to primedivisors-of-n.
  4. Report primedivisors-of-n.

For example, divisors(18) = [1, 2, 3, 6, 9, 18]. Checking each: 1 is not prime (it has only one divisor), 2 is prime, 3 is prime, 6 is not prime, 9 is not prime, 18 is not prime. So primedivisors(18) = [2, 3].

Build divisors(n) first, then keep only the entries d for which prime(d) is true — for n = 18, this gives [2, 3].
5★ We can also find the gcd of two numbers by computing the prime factorisation of both numbers. Try to write an algorithm to compute the prime factorisation of a number. (i) The prime factorisation of 180 is \(2^2 \times 3^2 \times 5^1\). How would you represent this? (ii) How would you compare the prime factorisations of two numbers?
Algorithm to find the prime factorisation of n
  1. Start with an empty list prime-factors, and let the current number be n.
  2. Let p be the smallest prime number (starting from 2) that divides the current number.
  3. Count how many times p divides the current number exactly (its exponent), record the pair (p, exponent) in prime-factors, and divide the current number by p that many times.
  4. Repeat Steps 2–3, always searching from the next candidate prime onward, until the current number becomes 1.
  5. Report prime-factors.

(i) The prime factorisation of 180 can be represented as a list of (prime, exponent) pairs: \([(2,2), (3,2), (5,1)]\) — read as "2 raised to the power 2, times 3 raised to the power 2, times 5 raised to the power 1". This representation is compact and unambiguous, and it is easy to reconstruct 180 from it by multiplying out the pairs.

(ii) To compare two prime factorisations, we line them up by prime number rather than by position in the list — treating each factorisation as giving an exponent for every prime (using exponent 0 for a prime that doesn't appear at all). For instance, comparing 180 = \(2^2 \times 3^2 \times 5^1\) with 84 = \(2^2 \times 3^1 \times 7^1\), we compare exponent by exponent across the primes 2, 3, 5, 7: (2,1), (2,0), (1,1). This prime-by-prime comparison is exactly what is used to compute the gcd (take the smaller exponent of each shared prime, e.g. \(2^2 \times 3^1 = 12\)) or the lcm (take the larger exponent of every prime that appears in either number).

(i) As a list of (prime, exponent) pairs, e.g. [(2,2), (3,2), (5,1)] for 180. (ii) Align both factorisations by prime number (treating an absent prime as exponent 0) and compare exponent by exponent — this comparison directly gives both the gcd (smaller exponents) and the lcm (larger exponents).

Chapter Summary

  • An algorithm is a systematic procedure to solve a problem.
  • Algorithms consist of basic steps that we know how to execute.
  • We may execute the same step a number of times; for instance, for each j in 1, 2, ..., n, check if j is a divisor of n.
  • A step in an algorithm may be conditional; for instance, add j to the list of divisors of n only if j divides n.
  • When we describe an algorithm to solve a problem, we need to justify that it is correct.
  • We can also analyse how many steps an algorithm takes, in terms of the size of its input, and decide how efficient it is.

Extra Practice Questions

Seven extra questions for independent practice once you have gone through the solved questions above. Try each one, then tap to check your answer.

1Use Euclid's division algorithm to find gcd(96, 404).

404 = 4 × 96 + 20

96 = 4 × 20 + 16

20 = 1 × 16 + 4

16 = 4 × 4 + 0

The last non-zero remainder is 4.

gcd(96, 404) = 4
2Use Euclid's subtraction algorithm to find gcd(36, 84). Show every step.

Replace the larger number by (larger − smaller) until the two numbers are equal:

(84, 36) → (48, 36) → (12, 36) → (12, 24) → (12, 12)

gcd(36, 84) = 12
3List all the divisors of 60 using divisor pairs. Up to which number do you need to check?

Check each number from 1 upwards; stop once the number is larger than its partner (√60 ≈ 7.7, so checking up to 7 is enough).

Pairs: (1, 60), (2, 30), (3, 20), (4, 15), (5, 12), (6, 10). 7 does not divide 60.

Divisors of 60: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60 (12 divisors); checking up to 7 is enough.
4Find lcm(18, 24) using their gcd.

gcd(18, 24): 24 = 1 × 18 + 6, 18 = 3 × 6 + 0, so gcd = 6.

\(\text{lcm} = \dfrac{18 \times 24}{\gcd(18, 24)} = \dfrac{432}{6} = 72\)

lcm(18, 24) = 72
5Add 4789 and 5376 using the column addition algorithm. Write the digit and the carry at each step.

Units: 9 + 6 = 15 → write 5, carry 1.

Tens: 8 + 7 + 1 = 16 → write 6, carry 1.

Hundreds: 7 + 3 + 1 = 11 → write 1, carry 1.

Thousands: 4 + 5 + 1 = 10 → write 0, carry 1.

The final carry 1 is written as the leftmost digit.

4789 + 5376 = 10165
6How many divisions does Euclid's division algorithm need to find gcd(89, 55)? What is the gcd?

89 = 1 × 55 + 34

55 = 1 × 34 + 21

34 = 1 × 21 + 13

21 = 1 × 13 + 8

13 = 1 × 8 + 5

8 = 1 × 5 + 3

5 = 1 × 3 + 2

3 = 1 × 2 + 1

2 = 2 × 1 + 0

Every quotient but the last is 1 — consecutive Fibonacci numbers make the algorithm take as many steps as possible for numbers of their size.

9 divisions; gcd(89, 55) = 1
7Using the idea behind prime(n), decide whether 91 is prime.

A number n is prime exactly when its only divisors are 1 and n. It is enough to test divisors up to √91 ≈ 9.5, i.e. 2, 3, …, 9.

91 ÷ 7 = 13, so 7 is a divisor.

91 = 7 × 13, so 91 is not prime.

Frequently Asked Questions

An algorithm is a systematic, step-by-step procedure for solving a problem, described precisely enough that anyone can follow it. Chapter 11 uses the everyday digit-by-digit addition method and the greatest common divisor (gcd) to show what makes an algorithm correct and what makes one efficient.
Euclid's subtraction algorithm says that if m ≥ n, gcd(m, n) = gcd(n, m − n), and gcd(m, 0) = m. Repeatedly subtracting the smaller number from the larger reduces the problem until one number becomes 0, at which point the other number is the gcd.
Āryabhaṭa's version replaces repeated subtraction with division: gcd(m, n) = gcd(n, m mod n), where m mod n is the remainder when m is divided by n. Instead of subtracting one copy of n at a time, it subtracts as many copies as possible in a single step, so the number of steps needed is proportional to the number of digits in m and n, not to their value.
Start with an empty list. Check every number j from 1 up to n in turn; whenever j divides n exactly, add j to the list. The resulting list is automatically in increasing order, since the numbers were checked in increasing order. Checking only up to √n (using that divisors pair up as (d, n/d)) makes this much faster.
The Persian mathematician Al-Khwārizmī (780–850 CE) wrote a treatise explaining Indian arithmetic methods. Its Latin translation attributed these methods to "Algoritmi" (the Latin form of his name), and algorismus/algorism eventually became "algorithm" — so the word originally meant an Indian method of computation before broadening to its modern, general meaning.
© Boundless Maths — Free CBSE Class 9–12 NCERT Solutions, Formula Cards & Question Banks.
Expert CBSE Coaching · Class 9–12