Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Asian MathSci League, Inc (AMSLI)

Website: amsliphil.com
Email address: amsliphil@yahoo.com

Student Copy
AIEP 1
Session 3

Algorithms and Code


Algorithm

In simple terms, an algorithm is a list of steps and rules you follow in order to accomplish something, like
solving a problem or computing a value. We can see some semblance of algorithms in our daily lives,
like in cooking when following a recipe, in flag ceremonies, or in navigating the streets towards a
destination. For example:

To Alice’s House, from the jeepney terminal


1. Go straight towards the 7-11.
2. On the second corner, turn right.
3. Go straight until the third corner, then turn left.
4. Go straight until the first humps. Alice’s House is on your right.

Code

Computers are limited in what they can do. For example, your mobile phone might only know how to do
50 different instructions (for example, adding two numbers). Once manufactured, the things that a given
computer can do becomes permanent, that’s why it’s called hardware.

What makes computers capable of doing anything you can imagine is through code (programs). Out of
those few basic instructions, you can combine them to do more complex tasks. And unlike hardware,
computer code is easily changeable, that’s why it’s called software.

Since computers are limited in their capability, they don’t understand English. So they cannot execute an
algorithm written in plain English. Coding (or programming) is how you turn an algorithm into code that
computers can understand. In these lessons, we’ll use Scratch to do that. You can do a lot of things in
Scratch even if it only has limited instructions that it can do. You can create games, tell a story, play
music, solve a math problem – the possibilities are endless!

Activity as an Algorithm
Choose an activity that you usually do.
Then, list down all the steps in order to do it.
Activity:
Steps:

Prepared by 2022 AIEP Team: Marte Soliza


Scratch

Code Area – This is where the code (scripts) are located.


Stage Area – This is where you can see the program running.

Run the program

Stop a running program

Center the code

Repeat Until block – This repeats do something until condition is met. We’ll
discuss conditions in the next lesson.

Prepared by 2022 AIEP Team: Marte Soliza


Repeat block – This repeats do something a number of times. Number can
be any integer, or it can also be a variable. We’ll discuss variables in the next lesson.

To undo your changes, press Ctrl-Z.

To redo your undone changes, press Ctrl-Shift-Z.

To move a block, drag it. Dragging a block will move the block and all blocks connected to it below (but
not those above).

To delete a block, right-click and click Delete Block.

To duplicate a group of blocks, right-click and click Duplicate. This will duplicate the right-clicked block
and all blocks connected to it below (but not those above). Sometimes, you might find the duplicated
blocks underneath the other blocks.

A script is a group of blocks connected together (can just be one block). Normally, you use the green flag
button to properly run the whole program. But you can also run a script by clicking it.

Multiplication Algorithm
Oh no! Our computer forgot how to multiply two numbers.
Good thing it still knows how to add.
Here’s an algorithm for multiplying two numbers (multiplicand & multiplier) using only addition:
1. Set product to 0
2. Repeat the following multiplier number of times:
a. Add multiplicand to product

Let’s try it with 4 x 12. Get the product by adding 4 a dozen times.
4 x 12:

Boring and slow, no? Fortunately, computers don’t get bored. And they’re really fast!
Let’s open the Multiplication Algorithm project in Scratch in order to show you how fast they do it.

Prepared by 2022 AIEP Team: Marte Soliza

You might also like