Effective And Ineffective Algorithms

cup-of-water

In the last post, we introduced algorithms as a set of instructions given to a computer in order to complete a given task. This post focuses on explaining the difference between an effective and ineffective algorithm, bugs in your algorithm and how to resolve them. In the embedded video, our friend, Albion’s task is to get a glass of water from the water dispenser.

Algorithm 1 – Ineffective

The first algorithm includes the following instructions.

  • – Get up
  • – Go top the machine
  • – Bring me water

This is an example of an algorithm that breaks the definitiveness rule. The instructions ask Albion to bring water. Bring the water in what container? What happens when the instructions you give to the computer are not clear enough? The computer returns an incorrect output or an error. In this case, Albion splashed water in our faces which is definitely not the desired output.

Algorithm 2 – Ineffective

  • – Get up
  • – Go to the machine
  • – Get a class from the cupboard
  • – Pour me some water
  • – Bring me the glass

The problem with this algorithm is in step 4. This is a classic example of an ineffective algorithm where the computer gets stuck on step 4 because it was not clear enough. The algorithm did not specify how much water Albion was required to pour into the glass, so it overflowed forever. This error is an example of a software bug. A bug is an error in your algorithm that computer that causes it to produce an incorrect or unexpected result. In order to debug your algorithm, it is important to go through each step, identify where you have gone wrong, and fix it. We see a debugged algorithm in the last example where Albion was able to get our glass of water, finally!

Algorithm 3 – Effective

  • – Get up
  • – Go to the machine
  • – Get a glass from the cupboard
  • – Pour some water until the glass is ¾ full
  • – Bring it to me

This algorithm is an improvement from Algorithm 2 because it specifies the amount of water the cup should contain. As we saw in the video, Albion successfully delivers the cup of water and we are grateful to him for being such a helpful friend!

We hope that you now have a better understanding of algorithms and how to write an effective algorithm. Visit the next post if you would like to learn how to implement a Sleep Cycle algorithm using real code. The next posts explain algorithms in Python. Python is a programming language and it is used to give algorithmic instructions to a computer. In other words with Python, you can make programs. So, if you are not familiar with basic Python programming, do play around on Google Collaboratory – a free online Python programming platform.

Recommend0 recommendationsPublished in Coding & STEAM, Teens

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.