Classroom
Introduction to Algorithms
Anushka Tonapi
This article explores the concept of algorithms, their significance, and guides
us through various everyday instances of algorithms in use, as well as
mathematical examples highlighting their applications.
What is an Algorithm?
Have you ever wondered how your favourite
video games work? These devices or apps
work by understanding code in a special
programming language that the computer
understands. This code provides instructions
for the computer to execute, allowing you
to use the app or play the game. This set of
instructions to perform a particular task is
called an algorithm. However, to be called an
algorithm, the set of instructions must have a Roti with ghee and jaggery
clear starting and ending, else you will have
an algorithm that goes on forever! Why are algorithms important?
Algorithms are everywhere! They help
Algorithms aren’t just for computers; we computers, robots, and even people solve
humans use them all the time in our daily problems efficiently. An algorithm is a set of
lives! Let’s see how with a simple example: precise instructions that ensures that a task is
Imagine you want to make a tasty snack – a performed consistently and accurately, every
roti with jaggery (gur) and ghee. You follow time it is followed. They are intended to be
these steps to make it: carried out even by a machine and hence
1. Get a roti. should be unambiguous - they cannot have
2. Spread a spoonful of ghee on it. more than one meaning!
3. Grate some jaggery. Algorithms are particularly useful for
4. Sprinkle grated jaggery over the roti. automating repetitive tasks, and ensuring
consistent output. An algorithm is like
5. Roll up the roti.
a recipe: if the instructions are clear and
Now you have yourself a tasty snack. Enjoy! precise, the dish should taste the same every
Keywords: Algorithm, sequence, flow, procedures, code
14 Azim Premji University At Right Angles, November 2024
Classroom
time, no matter who cooks it. Machines can find ourselves going back and forth while
do repetitive tasks when given a well-defined solving a problem. Not just that, we may not
sequence of instructions – in that case, the identify or remember the most efficient way to
output will be precisely the same in each solve the problem and we may have to repeat
iteration. Using an algorithm to automate tasks all our reasoning when we solve a similar
ensures that there is no human error due to problem. While solving a problem, we should
boredom or fatigue as the machine executes the use an organized sequence of steps. We read the
instructions exactly the same way each time. problem, analyse the information, and make a
plan to solve the problem. Then, we carry out this
This means the current algorithm for making plan and find the answer. Let us dive into some
roti with jaggery isn’t really an algorithm fun activities to learn more about algorithms. We
because different people might interpret the will explore through stories, games, and exercises
instructions in various ways. For example, that make learning about algorithms as exciting
the first instruction, “get a roti,” doesn’t give as playing your favourite game.
enough detail. One possible way to improve
this instruction is to specify the size, thickness,
Activity 1: Story Time - "The Thirsty
and ingredients of the roti. We can rewrite it as:
“Get one cooked atta roti with a radius of about Crow"
5 cm and a thickness of 2 mm.” The second Objective: Use stories to communicate how
instruction can also be clearer by stating: “Take characters use algorithms to solve problems.
a teaspoon of Amul ghee and spread it evenly on
Story: It was a hot summer afternoon and Kalia
one side of the roti.” We encourage readers to
the crow was thirsty. He found a mud pot filled
refine the remaining steps to make them clear
halfway through and perched on the edge of the pot.
and precise.
He put his long beak in and tried to sip the water,
As you can see, without algorithms, our world but it was useless, as the water level was too low for
would be much more chaotic and much less him to drink from!
fun. By learning about algorithms, you can start
to understand how to solve problems better,
whether it is in math, science, or everyday life.
Getting started with algorithms
Question: Can there be multiple algorithms
to solve one problem?
Yes, there can be multiple algorithms to solve a
single problem! For example, suppose you are
trying to get from your house to school. You
could take the school bus, or you could ride your The thirsty crow.
bicycle. Both methods will get you to school, but Kalia looked around him, his beady eyes scanning
each one requires a different set of steps – or in the ground. He found a pile of pebbles nearby.
other words, a different algorithm. He hopped off the mud pot’s edge, picked a pebble
Question: Can we solve a problem without an up with his beak, and hopping onto the pot’s edge
algorithm? again, dropped the pebble into the pot with a plop!
Well, we might think we can solve problems He kept dropping pebbles into the pot until the
without an algorithm, this is often because we water level reached high enough for him to drink
are not consciously recording the steps we are from. Kalia the crow drank to his heart’s content
taking. Without a clear algorithm, we might and flew away refreshed!
Azim Premji University At Right Angles, November 2024 15
Classroom
Let’s arrange Kalia’s solution to his problem into Game: We write down the steps to a simple
an algorithm: dance and then follow them together. We
can even follow the steps of popular nursery
Kalia’s algorithm rhymes/songs. For example, for the song ‘Looby
1. Find a pebble. Loo’, we can put the lyrics into the following
2. Drop it into the pot. dance algorithm:
3. Measure the water level by putting your beak Dance Steps
into the pot. 1. Stand with both your hands horizontally
4. If the water level is not high enough for your outstretched along your sides.
beak to reach, repeat steps 1-3. 2. Raise your right hand up.
5. If the water level is high enough for your beak 3. Shake it up and down.
to reach, drink enough water to satisfy your
thirst! 4. Spin around once.
Discussion: This list of steps is Kalia’s algorithm 5. Raise your left hand up.
to satisfy his thirst. By following each step 6. Shake it up and down.
precisely, Kalia can prevent getting dehydrated! 7. Spin around again.
Questions Instructions
What do you think would happen if Kalia forgot 1. Write the steps on a board or paper.
to do one of the steps in his algorithm, such as 2. Practice each step slowly according to a song
not checking the water level after dropping a or rhythm.
pebble? Why is it important to follow each step
in the right order? 3. Put all the steps together and dance.
Can you think of a different algorithm Kalia Discussion: By following the dance algorithm,
could have used to solve the problem? What you can remember the dance moves and perform
if there were no pebbles around? For example, them in the right order. If you mix up the
could he have pecked the earthen pot and made steps, the dance will not look the same. This
a hole with his beak to get the water? shows why the order of steps in an algorithm is
important. Make sure to dance to the algorithm
along with some music! You can use any music
Activity 2: Dance algorithm
of your choice, but it would be helpful if it was
Objective: Learn about sequences and order of a song with lyrics that included dance steps or
steps. body movements.
Dance steps
16 Azim Premji University At Right Angles, November 2024
Classroom
Activity 3: Planting seeds algorithm
Objective: Use an algorithm to plant a seed and observe the growth of a plant.
The "Planting Seed" Algorithm
1. Collect 15-20 seeds. 2. Take a pot of diameter 30 cm 3. Add 20% of compost.
and height 20 cm and fill upto 70%
of it with soil.
4. Make 5-6 small holes 5. Place 3-4 seeds in 6. Cover the holes
with your index finger. each hole. with soil.
7. Water the seed with 8. Place the pot where there is 9. Observe the plant
a watering can. gentle sunlight and water regularly. sprout and grow.
Discussion: Importance of the sequence and of each step.
• What happens if Step 3 is omitted?
• What happens if Step 8 is omitted?
• What happens if Step 6 is done before Step 5?
Azim Premji University At Right Angles, November 2024 17
Classroom
Activity 4: Everyday Algorithms
Objective: Identify algorithms in daily activities.
Exercise: Let’s think about some daily tasks and
break them down into algorithms.
Example 1: Brushing Your Teeth
1. Take your toothbrush.
2. Apply toothpaste to the brush.
3. Wet the toothbrush under the tap.
4. Brush your teeth for two minutes. (Note: You
can make an algorithm for this step too!)
5. Rinse your mouth with water.
6. Clean your toothbrush and put it back in its Math games with Algorithms
place. Game 1: Sum of the first n natural numbers
via pattern recognition
Objective: Finding the sum of the first 100
natural numbers
Algorithm
1. You write the problem on the board:
1 + 2 + 3 + ... + 100
2. Ask the students if they recognize any
patterns in the sequence
3. Add a line below the problem: 100 + 99 + 98
Example 2: Packing Your School Bag + ….. + 1
1. Gather all your schoolbooks. 4. Ask the students if they recognize any
patterns in the sequence
2. Check your timetable.
5. Demonstrate the pairing of numbers on the
3. Put the right books in your bag.
board: (1 + 100), (2 + 99), (3 + 98), ..., (50 + 51)
4. Add your pencil case.
6. Recognize the pattern that all these pairs sum
5. Check if your pencils are sharpened, and you to the same number 101
have an eraser.
7. Discuss how many such pairs there are
6. Check if you have your lunch box and
8. Find the product of the number of pairs
water bottle.
and 101
7. Zip up your bag.
9. Identify how this product is related to the
Discussion: By breaking down these tasks into sum of the sequence.
simple steps, you can complete them more 10. Try and generalize the pattern for other
efficiently and remember everything you need numbers by applying the same pattern and
to do. coming up with a formula!
18 Azim Premji University At Right Angles, November 2024
Classroom
Note to the Teacher
Discuss how recognizing patterns helps to design the steps of an algorithm. When students
recognize a pattern, they are essentially breaking down the problem into simpler and repeatable
parts. For example, in the sequence (5, 10, 15, 20…), if the students notice that there is an
increment of 5 with every term, this pattern can help them solve problems related to this sequence.
Similarly, the purpose of an algorithm is to break down a complex problem into a series of
instructions or steps that, when followed, help them arrive at an efficient solution to the problem.
In the context of algorithms, pattern recognition is extremely important, as it helps students break
down complex problems into simpler and manageable components. Sorting and recognizing
patterns in data helps students understand the concept of categorization.
Conclusion: The Power of Algorithms we are becoming better problem solvers. So, the
Algorithms might sound complex, but they are next time you are faced with a tricky problem,
just a way of thinking about solving problems step remember to think like an algorithm: break it
by step. Whether you are making a snack, solving down into smaller steps, follow each step carefully,
a problem, or playing a game, algorithms help you and you will find your solution!
do things more efficiently and effectively. Algorithms are like treasure maps leading you
By learning about algorithms, we are not just to the right answers. The more you practise, the
getting better at using computers or doing math— better you will get at finding your way.
ANUSHKA TONAPI is a 10th grade student at Sri Kumaran Children's Home in Bangalore. She is a Young
Member of the New York Academy of Sciences and she is a Spirit of Ramanujan Fellowship awardee. She
enjoys solving math problems and is interested in theoretical computer science. Anushka loves playing chess and
practice Carnatic music in her spare time. She can be contacted at Anushka.tonapi@gmail.com
1. Choose any two digit number.
2. Reverse it.
3. Subtract it from the first number you had chosen.
4. What answer did you get?
What happens if the digits are the same? What happens if the digits are different?
Can you explain the pattern you observe?
Look out for more THOAN activities from Yathiraj Sharma in upcoming issues of At Right Angles.
Azim Premji University At Right Angles, November 2024 19