The World of Algorithms
What an algorithm is, column addition as an algorithm and why it is fast, finding the gcd from lists of divisors, data structures, improving an algorithm step by step, Euclid’s subtraction method and Āryabhaṭa’s division method, and how Al-Khwārizmī gave us the word ‘algorithm’ – with every exercise solved.
What an Algorithm Is
2 topics to learn here
Addition as an algorithm
Columns, carries and speed.
- 1
Counting dots works for 5 + 7 but not for 473 + 695.
- 2
An algorithm is a precise, step-by-step procedure to get an answer.
- 3
Addition algorithm: align digits from the right; add each column with the carry; write the units digit and carry 1 when the sum is 10 or more; at the end, write any leftover carry.
- 4
It relies on a basic step we can already do: adding single digits.
- 5
Why it works: we add units, tens, hundreds separately and pass each new ten to the next group.
- 6
It is fast: one more digit means one more column, not ten times as many dots. At 1 dot per second, 3347 + 2729 takes over 1 h 40 min to count but about a minute column by column.
Basic step assumed in column addition?
✅ Adding single digits (with a carry).
Listing divisors
Check 1 to n, keep divisors.
- 1
Start with an empty list-of-divisors; for each j from 1 up to n, add j to the end whenever it divides n.
- 2
Names like j and list-of-divisors make the steps easy to describe.
- 3
Running the steps is executing the algorithm: divisors(18) = [1, 2, 3, 6, 9, 18] – in increasing order.
- 4
Basic step assumed: telling whether one number divides another.
divisors(20)?
✅ [1, 2, 4, 5, 10, 20].
Algorithms for gcd
4 topics to learn here
gcd from lists; data structures
Common list, take the last.
- 1
gcd(m, n): list the divisors of each; keep those in both lists (common-divisors); the rightmost is the gcd.
- 2
divisors(375) and divisors(825) share [1, 3, 5, 15, 25, 75], so gcd = 75. gcd(54000, 81000) = 27000.
- 3
A list is a data structure: a way of organising intermediate values so the algorithm works well.
Why is the gcd the rightmost common divisor?
✅ The lists are in increasing order.
Improving the algorithm
One scan, up to min, no lists.
- 1
Scan once up to max(m, n) for both numbers instead of twice (m + n checks).
- 2
Collect common divisors directly – and only up to min(m, n).
- 3
Drop lists: just remember the most-recent-common-divisor; the last one found is the gcd.
- 4
Still, the work grows with the value: a 4-digit number needs about 10 times the checks of a 3-digit one.
- 5
Scanning backwards from min(m, n), the first common divisor found is the gcd – you can stop early.
💡 UnderstandProgrammers improve code exactly like this – same output, far fewer steps.
What single value replaces the list of common divisors?
✅ The most-recent-common-divisor.
Euclid’s subtraction algorithm
Subtract the smaller.
- 1
If d divides m and n, it divides m − n; and if d divides n and m − n, it divides m. So both pairs share the same common divisors.
- 2
Picture: if blocks of size d tile m and n, they also tile m − n.
- 3
Steps: if m < n, swap; if n = 0, the answer is m; otherwise find gcd(n, m − n).
- 4
gcd(375, 825) needs 7 reductions to reach gcd(75, 0) = 75.
- 5
But gcd(99, 2) takes about 49 subtractions – work still grows with the value.
- 6
Euclid wrote it in his Elements; earlier Greeks probably knew it.
gcd(14, 6) by subtraction?
✅ Subtracting repeatedly ends at gcd(2, 0): 2.
Āryabhaṭa’s division algorithm
Use the remainder instead.
- 1
Repeatedly subtracting 2 from 99 just leaves the remainder of 99 ÷ 2.
- 2
So reduce gcd(m, n) to gcd(n, m mod n); m mod n is the remainder (17 mod 5 = 2).
- 3
gcd(99, 2) → gcd(2, 1) → gcd(1, 0) = 1: only two steps.
- 4
The long-division layout appears in Āryabhaṭa’s Āryabhaṭīya (499 CE).
- 5
The number of steps grows with the number of digits, not the value – a huge saving.
💡 UnderstandPhones use the same remainder idea (with huge numbers) every time they encrypt a message.
Find gcd(60, 16) by Āryabhaṭa’s division method.
- 60 = 3 × 16 + 12 → gcd(16, 12)
- 16 = 1 × 12 + 4 → gcd(12, 4)
- 12 = 3 × 4 + 0 → gcd(4, 0)
Answer: gcd = 4
🧠 Memory trickDivide, keep the remainder, shift left; the last non-zero remainder is the gcd.
gcd(48, 18) by division?
✅ 48→12, 18→6, 12→0: 6.
The Word Itself
1 topic to learn here
Where the word ‘algorithm’ comes from
Al-Khwārizmī and Indian numerals.
- 1
Al-Khwārizmī (780–850 CE), at Baghdad’s House of Wisdom, learnt Sanskrit and wrote (c. 820 CE) on the Indian place-value system and its four operations.
- 2
Its Latin translation, Liber Algorismi de numero Indorum, spread Indian arithmetic in Europe.
- 3
‘Algorismus’ – from Algoritmi, the Latin form of his name – first meant an Indian method of calculation, later any step-by-step procedure: algorithm.
What did ‘algorismus’ first mean?
✅ An Indian method of calculation.
🔤 Key words
Each science word with its meaning and its Hindi name. Cover the meaning and try to say it first.
- Algorithmकलनविधि (एल्गोरिद्म)
A precise step-by-step procedure that solves a problem.
- Executeनिष्पादन
Run through an algorithm’s steps.
- Basic stepमूल चरण
A step we assume we can do directly, e.g. adding two digits.
- Carryहासिल
The 1 passed to the next column when a column sum is 10 or more.
- gcd / hcfमहत्तम समापवर्तक
Greatest common divisor (highest common factor).
- Listसूची
An ordered collection of values, written [1, 2, 3].
- Data structureडेटा संरचना
A way of organising information for an algorithm.
- m mod nशेषफल
Remainder when m is divided by n.
- Efficiencyदक्षता
How the work grows as the input grows.
🛂 One-look revision
One card per idea. Read the key point, then try to recall the whole topic.
- AlgorithmPrecise steps + basic stepsColumn addition
- ExecuteRun the stepsdivisors(18)
- gcd by listsRightmost common divisorgcd(375, 825) = 75
- Data structureOrganised intermediate valuesIncreasing lists
- ImprovementScan to min(m, n); keep only latestSame answer, less work
- Euclidgcd(n, m − n)Slow for gcd(99, 2)
- Āryabhaṭagcd(n, m mod n)gcd(99, 2) in 2 steps
- Word originAl-KhwārizmīIndian numerals
❔ Questions and answers
Tap a question to see the answer. Try answering in your head first.