How to Explain Algorithms to Kids?

An algorithm is just the logic that you use to solve a problem. It can be as simple as a recipe or as complex as instructions for the coordination of an entire spacecraft mission. An algorithm in computer science is a set of instructions that need to be given to a computer in a machine-readable language to do a task. Tasks can be very simple - “print ‘hello’” or very complex - “take the data from a file and run a specified computation over all the data.” If you know the basic steps for making a cake, for example, you can continue to tweak it a little bit to make chocolate or apple or get increasingly fancy and add multiple layers and frosting. Computer programming works in the same way.

A simple bubble sort example with AgentCubes

Why are Algorithms Important for Kids to Learn?

As our world is run increasingly by computers, Algorithms are quickly becoming of paramount importance. In order to understand how our own personal data is being processed, handled and even evaluated by the companies that handle and share it, it is crucial that we understand a little bit about algorithms. It is becoming important for every job seeker to be aware of how computer-based logic works, and even if you start your own business, you will need to know something about algorithms if you would like to promote your business on Social Media and Search Engines, and create a web presence that will be seen by the prospective clients that you want.

How can you learn about Algorithms with AgentCubes

AgentSheets, Inc. products have always been about teaching Computational Thinking concepts. Before you even choose a specific programming language, it’s a good idea to work out the logic of a program and design it in advance. From the simplest things you need the computer to do, i.e. move a character along a path, it helps to figure out what you want the computer to do and the particular steps the computer needs to do to make it happen. Why does this help? It helps, because data that the computer needs to do what you want will have to be available when the step is about to be completed. Keeping track of these sorts of things can be very complex for beginners, and the visual programming language of AgentCubes Online helps them not become overwhelmed or discouraged as they learn. Text-based languages force you to know very low-level details and sometimes complicated syntax in order to give the computer the commands you envision. With AgentCubes Online, this is all taken care of for you. For example, if you want the player of your game to press the arrow keys to make their character move in each direction in a game, you just specify the arrow keys, and then what direction the character needs to move in a single statement, rather than a whole subroutine. AgentCubes Online allows you to build increasingly complex algorithms for yourself visually. Once you understand the basic algorithms, the sky’s the limit for what you can create.

How to Make a Bubble Sort with AgentCubes

Bubble Sort is a basic algorithm, commonly in beginning computer science classes. The idea of bubble sort is to sort a list of numbers from smallest to largest. To do that, the computer is programmed to go through the list and compare two numbers with each other. If the left number is bigger than the right number, the program switches the two numbers. Then the computer program continues doing this until the number list is sorted from smallest to largest.

If our starting list looks like this:
2 4 1 3

Then the first iteration of the bubble sort program would do this:
2 1 4 3

Second:
2 1 3 4

And Finally:
1 2 3 4

It compared 2 and 4 first and found that 2 is smaller than 4. However, it compared 4 and 1 and found that 4 is not smaller than 1 and swapped the two numbers. Now the list is 2 1 4 3 so it swapped 4 and 3 and generate a new list 2 1 3 4. Now the computer program will start from the beginning of the list and do the swaps again. Already it finds that 2 is bigger than 1 and will swap it to 1 2 3 4. Then the computer program will continue to check until everything is sorted. Bubble sort is generally easy to implement in any language and creates a small program.

Let’s look at how we can do this in AgentCubes and how our approach is different. It is also very simple but it’s more sophisticated. In AgentCubes, each agent in the world runs its own code that will be executed in parallel. This is very cool because this type of programming is used for Machine Learning techniques. It is called GPU programming commonly used with OpenCL.

To program Bubble sort with AgentCubes the basics are the same. However, when programming with AgentCubes you have to imagine that you are programming all the agents to execute the program at the same time. So you have to ask the question, “how do I get the agents to figure out what value they represent and how do you get the agents to “talk” to each other?”

To get the agents to work with each other we need to write code that allows an agent to compare its own value to its neighbor’s value. If the neighbor’s value is bigger than the current agent then the agent sends a message to the neighbor that it needs to switch places. Then the agent moves to the left.

Here is how the code is written:

This rule checks the neighbor value and ask to switch if the values are not matching.

The test condition makes the agent look to it’s left neighbor and compares their values. If the left neighbor has a higher value than the agent sends a message to the left neighbor asking to switch places and then the agent moves left.

This rule sets the initial values of the array or list of agents.This rule is a rule for the neighbor to move.

The “switch” method is executed when the message “switch” is received. When the code is executed the agent will move left and the neighboring agent will move right.

If you want to know more on how the bubble sort algorithm works in AgentCubes checkout out this fun bubble sort project! We have plenty more cool project that you can checkout in the project tab. We also have many tutorials you can look through in the tutorial page.