What is an Algorithm?

Any time you need a plan which requires a series of steps to accomplish a task you have a type of algorithm. For the purposes of writing code, an algorithm must do do things. First, it must solve the problem or deliver the desired results and second, it must be efficient

Algorithms are everywhere. A recipe for baking a cake is an algorithm, the steps you use to solve a math problem is an algorithm and the order in which you prepare breakfast is an algorithm. Even the routine you follow every morning getting ready for school is an algorithm.

Example:

1. Get the cereal bowl from the cupboard.
2. Get a spoon from the drawer.
3. Get the cereal from the pantry.
4. Get the milk from the fridge.
5. Put a measured amount of cereal in the bowl.
6. Put a measured amount of milk in the bowl.
7. Eat the cereal.
8. If you are still hungry go to point 5 and repeat.

Note that the instructions are very specific and we don't assume that the computer knows anything. If we don't tell it where to find the cereal bowl then it will not get one.

Click on this link to see a more complicated algorithm that is written in pseudo-code (shorthand writing somewhere between English and code). It is designed to find the number of prime numbers in any number provided by the user. It uses symbols and colours but it does not have to be in that format. Point form works as well. You will also see 'Conditionals', or 'questions' that the computer needs to answer. We will work with those in the next course. This is provided just for an example to see how pseudo-code can look.
 
Prime Numbers

(click on the NEXT button to see the example).

Please watch this video introducing algorithms.

In order to write an effective program you must have a plan. An algorithm is the plan. Remember that as you saw in the video, an algorithm must do two things. First is must solve the problem. Second, it must be efficient. If the solution to the problem does not work in all cases, or if there is a shorter way to solve the problem, then the algorithm must be improved.

NOTE: Every program you write must be accompanied by the algorithm you used to plan the coding process.

Please have a look at the Guessing Game.