1What an algorithm is
An algorithm is a finite sequence of clear, unambiguous steps that takes an input, and after a finite number of steps produces an output — the same output every time for the same input.
Column addition is an algorithm: line up the digits by place value, add the units column, write the units digit of the sum and carry the tens digit, then repeat for each column to the left. It works for any two numbers, however long, which is the point of an algorithm.
Good algorithms have three properties: every step is precise, the process always stops, and it gives the correct answer. Among correct algorithms we prefer the one that takes fewer steps — it is more efficient.
- Algorithm: input → finite precise steps → output.
- Must be correct, must terminate, should be efficient.
Write an algorithm to find the largest number in a list.
- Step 1: Let 'biggest' be the first number.
- Step 2: For each remaining number, if it is greater than 'biggest', replace 'biggest' with it.
- Step 3: When the list ends, output 'biggest'.
Answer: The algorithm looks at each number once, so a list of numbers takes comparisons.
- Writing steps like 'find the answer' that are not precise enough for someone else (or a computer) to follow.
2Divisors, GCD and LCM
A divisor of divides it with no remainder. The greatest common divisor (also called HCF) is the largest number that divides both. The least common multiple is the smallest positive number both divide.
The simplest GCD algorithm lists all divisors of each number and picks the largest common one. It works, but for large numbers listing divisors is slow — this motivates better methods.
A key link: for positive integers, . So once you know the GCD, the LCM costs one multiplication and one division.
- : and are co-prime, and then .
Find gcd(36, 48) by listing divisors, then the LCM.
- Divisors of 36: 1, 2, 3, 4, 6, 9, 12, 18, 36. Divisors of 48: 1, 2, 3, 4, 6, 8, 12, 16, 24, 48.
- Largest common: 12.
- .
Answer: GCD 12, LCM 144.
- Thinking the GCD can be larger than the smaller number — it is at most the smaller number.
- Using the product rule for three numbers; it only works for two.
3Euclid's subtraction algorithm
Euclid (around 300 BCE) noticed: **any number that divides both and also divides **, and vice versa. So when .
Algorithm: while the two numbers are different, replace the larger by (larger − smaller). When they become equal, that number is the GCD.
It always stops, because the numbers keep getting smaller but stay positive. However, if one number is much larger than the other, it takes many subtractions.
- for
- Stop when both numbers are equal.
Find gcd(84, 36) by repeated subtraction.
- (84, 36) → (48, 36) → (12, 36) → (12, 24) → (12, 12).
- Both equal 12.
Answer: 12.
- Subtracting the larger from the smaller and getting a negative number.
4Aryabhata's division algorithm
Repeated subtraction of from is just division: subtracting as many times as possible leaves the remainder. So where , .
Algorithm: divide the larger by the smaller, then replace the pair by (smaller, remainder). Repeat until the remainder is 0. The last non-zero remainder (the last divisor) is the GCD. Āryabhaṭa (5th century CE) used this method, called kuṭṭaka, and extended it to solve equations like in whole numbers.
This is far faster than subtraction: gcd(1000, 3) by subtraction needs over 300 steps; by division it needs 2.
- , , and
- Stop at remainder 0; the last divisor is the GCD.
Find gcd(1071, 462).
- .
- .
- .
Answer: 21.
Two ropes are 391 cm and 299 cm long. What is the greatest length of piece that can cut both into whole numbers of equal pieces?
- ; ; .
- gcd .
Answer: 23 cm (17 pieces and 13 pieces).
Lay it out as a ladder: each line's divisor and remainder become the next line's dividend and divisor.
- Giving the last remainder (0) as the answer — the GCD is the last non-zero remainder.
- Swapping dividend and divisor at the next step.
5Lists and prime factorisation
Algorithms often store intermediate results in a list (a simple data structure) — for example the divisors found so far, or the primes already known.
**Is prime?** Try dividing by 2, 3, 4, … but only up to : if with both factors bigger than , their product would exceed . This one observation makes the test much faster. You can also skip even numbers after 2.
Prime factorisation: divide by the smallest prime that works, write it in the list, and repeat with the quotient until 1 is left. The list is the factorisation, and it is unique (apart from order).
- To test for primality, check divisors only up to .
- Every integer > 1 has a unique prime factorisation.
- gcd = product of common primes with the smaller powers; lcm = all primes with the larger powers.
Is 221 prime? Factorise 360.
- , so test primes 2, 3, 5, 7, 11, 13: . Not prime.
- .
- .
Answer: 221 = 13 × 17; 360 = 2³ × 3² × 5.
- Calling 1 a prime number — primes have exactly two divisors.
- Stopping the primality test at (correct, but wasteful) or at too small a number.
Important questions
Try each question on paper first, then tap it to check the answer.
Basic Recall and direct use
Find gcd(48, 18) by the division method.Answer
gcd(a, b) = 8 and a × b = 960. Find lcm(a, b).Answer
List the steps of the column addition of 487 and 256.Answer
Medium Two or three steps
Find gcd(252, 198) by repeated subtraction and by division. Compare the number of steps.Answer
Which primes must you test to decide whether 391 is prime? Is it?Answer
Find the LCM of 12, 18 and 30 using prime factorisation.Answer
Advanced Reasoning and HOTS
Why does gcd(a, b) = gcd(b, r) when a = bq + r?Answer
Three bells ring at intervals of 12, 15 and 20 minutes. They ring together at 9:00 a.m. When will they next ring together? Which algorithm idea did you use?Answer
Self-check quiz
Five quick questions. Tap an option to see if you are right.
FAQ
Is Euclid's algorithm the same as Āryabhaṭa's?
They rest on the same idea. Euclid described it with repeated subtraction; using division (taking the remainder at once) does many subtractions in one step. Āryabhaṭa used this division process and extended it to solve whole-number equations.
Why learn algorithms in maths class?
Because maths is not only about answers but about reliable methods. Algorithms are also the foundation of computer programming.
What is the fastest way to find HCF in the exam?
For two numbers, the division method. For three or more small numbers, prime factorisation is often quicker.
Book references
- NCERT Ganita Manjari Part II, Chapter 11: The World of AlgorithmsRead the chapter and do every exercise set first.
- Mathematics for Class 9 — R.D. Sharma (Dhanpat Rai)Extra graded practice; its chapter numbers follow the old syllabus, so match by topic.
- Mathematics for Class 9 — R.S. Aggarwal (Bharati Bhawan)Good for drill on basics; match by topic.
- Exemplar Problems in Mathematics, Class IX — NCERTHarder, concept-testing questions (written for the old book).
These notes, examples and questions are written by PrepRung in our own words to help you study the NCERT Ganita Manjari book. NCERT and CBSE are not affiliated with PrepRung. Always study from your textbook too.