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 clear starting and ending, else you will have an algorithm that goes on forever!

Algorithms aren’t just for computers; we humans use them all the time in our daily lives! Let’s see how with a simple example: Imagine you want to make a tasty snack – a roti with jaggery (gur) and ghee.
You follow these steps to make it:

  1. Get a roti.
  2. Spread a spoonful of ghee on it.
  3. Grate some jaggery.
  4. Sprinkle grated jaggery over the roti.
  5. Roll up the roti.

Now you have yourself a tasty snack. Enjoy!

roti and ghee

Why are algorithms important?

Algorithms are everywhere! They help computers, robots, and even people solve problems efficiently. An algorithm is a set of precise instructions that ensures that a task is performed consistently and accurately, every time it is followed. They are intended to be carried out even by a machine and hence should be unambiguous – they cannot have more than one meaning!

Algorithms are particularly useful for automating repetitive tasks, and ensuring consistent output. An algorithm is like a recipe: if the instructions are clear and precise, the dish should taste the same every time, no matter who cooks it. Machines can do repetitive tasks when given a well-defined sequence of instructions – in that case, the output will be precisely the same in each iteration. Using an algorithm to automate tasks ensures that there is no human error due to boredom or fatigue as the machine executes the instructions exactly the same way each time.

This means the current algorithm for making roti with jaggery isn’t really an algorithm because different people might interpret the instructions in various ways. For example, the first instruction, “get a roti,” doesn’t give enough detail. One possible way to improve this instruction is to specify the size, thickness, and ingredients of the roti. We can rewrite it as: “Get one cooked atta roti with a radius of about 5 cm and a thickness of 2 mm.” The second instruction can also be clearer by stating: “Take a teaspoon of Amul ghee and spread it evenly on one side of the roti.” We encourage readers to refine the remaining steps to make them clear and precise.

As you can see, without algorithms, our world would be much more chaotic and much less 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 bicycle. Both methods will get you to school, but each one requires a different set of steps – or in other words, a different algorithm.

Question: Can we solve a problem without an algorithm?

Well, we might think we can solve problems without an algorithm, this is often because we are not consciously recording the steps we are taking. Without a clear algorithm, we might find ourselves going back and forth while solving a problem. Not just that, we may not identify or remember the most efficient way to solve the problem and we may have to repeat all our reasoning when we solve a similar problem. While solving a problem, we should use an organized sequence of steps. We read the problem, analyse the information, and make a plan to solve the problem. Then, we carry out this plan and find the answer. Let us dive into some fun activities to learn more about algorithms. We will explore through stories, games, and exercises that make learning about algorithms as exciting as playing your favourite game.

Activity 1: Story Time – “The Thirsty Crow”

Objective: Use stories to communicate how characters use algorithms to solve problems.

Story: It was a hot summer afternoon and Kalia the crow was thirsty. He found a mud pot filled halfway through and perched on the edge of the pot. He put his long beak in and tried to sip the water, but it was useless, as the water level was too low for him to drink from!

algorithms-F2
The thirsty crow

Kalia looked around him, his beady eyes scanning the ground. He found a pile of pebbles nearby. He hopped off the mud pot’s edge, picked a pebble up with his beak, and hopping onto the pot’s edge again, dropped the pebble into the pot with a plop! He kept dropping pebbles into the pot until the water level reached high enough for him to drink from. Kalia the crow drank to his heart’s content and flew away refreshed!

Let’s arrange Kalia’s solution to his problem into an algorithm:

Kalia’s algorithm

  1. Find a pebble.
  2. Drop it into the pot.
  3. Measure the water level by putting your beak into the pot.
  4. If the water level is not high enough for your beak to reach, repeat steps 1-3.
  5. If the water level is high enough for your beak to reach, drink enough water to satisfy your thirst!

Discussion: This list of steps is Kalia’s algorithm to satisfy his thirst. By following each step precisely, Kalia can prevent getting dehydrated!

Questions

What do you think would happen if Kalia forgot to do one of the steps in his algorithm, such as not checking the water level after dropping a pebble? Why is it important to follow each step in the right order?

Can you think of a different algorithm Kalia could have used to solve the problem? What if there were no pebbles around? For example, could he have pecked the earthen pot and made a hole with his beak to get the water?

Activity 2: Dance algorithm

Objective: Learn about sequences and order of steps.

algorithms F3
Dance steps

Game: We write down the steps to a simple dance and then follow them together. We can even follow the steps of popular nursery rhymes/songs. For example, for the song ‘Looby Loo’, we can put the lyrics into the following dance algorithm:

Dance Steps

  1. Stand with both your hands horizontally outstretched along your sides.
  2. Raise your right hand up.
  3. Shake it up and down.
  4. Spin around once.
  5. Raise your left hand up.
  6. Shake it up and down.
  7. Spin around again.

Instructions

  1. Write the steps on a board or paper.
  2. Practice each step slowly according to a song or rhythm.
  3. Put all the steps together and dance.

Discussion: By following the dance algorithm, you can remember the dance moves and perform them in the right order. If you mix up the steps, the dance will not look the same. This 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 of your choice, but it would be helpful if it was a song with lyrics that included dance steps or body movements.

Activity 3: Planting seeds algorithm

Objective: Use an algorithm to plant a seed and observe the growth of a plant.

The “Planting Seed” Algorithm

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?

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 place.
algorithmsF13

Example 2: Packing Your School Bag

  1. Gather all your schoolbooks.
  2. Check your timetable.
  3. Put the right books in your bag.
  4. Add your pencil case.
  5. Check if your pencils are sharpened, and you have an eraser.
  6. Check if you have your lunch box and water bottle.
  7. Zip up your bag.

Discussion: By breaking down these tasks into simple steps, you can complete them more efficiently and remember everything you need to do.

packing-your-school-bag

Math games with Algorithms

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 + ….. + 1\)
  4. Ask the students if they recognize any patterns in the sequence
  5. Demonstrate the pairing of numbers on the board: \((1 + 100), (2 + 99), (3 + 98), …, (50 + 51)\)
  6. Recognize the pattern that all these pairs sum to the same number \(101\)
  7. Discuss how many such pairs there are
  8. Find the product of the number of pairs and \(101\)
  9. Identify how this product is related to the sum of the sequence.
  10. Try and generalize the pattern for other numbers by applying the same pattern and coming up with a formula!

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

Algorithms might sound complex, but they are just a way of thinking about solving problems step by step. Whether you are making a snack, solving a problem, or playing a game, algorithms help you do things more efficiently and effectively.

By learning about algorithms, we are not just getting better at using computers or doing math — we are becoming better problem solvers. So, the next time you are faced with a tricky problem, remember to think like an algorithm: break it down into smaller steps, follow each step carefully, and you will find your solution!

Algorithms are like treasure maps leading you to the right answers. The more you practice, the better you will get at finding your way.

More Articles