# Computer Algorithms Tutorial

Save

A computer algorithm is, simply, a set of rules a program uses to solve a problem, in preferably as few steps as possible. Algorithms can be used for small tasks, or they can be at the centerpiece of giant companies; the algorithm Google uses to get search results is massive, and is constantly being altered (and a well-kept secret). Sophisticated algorithms use events and conditionals to achieve the best result.

## Basic Algorithms

• The basic idea behind algorithms--and really, programs in general--is to decide what you want to accomplish and then keep breaking it into steps. For example, say you want to play tennis. You might have to do the following:

1. Call some friends and invite them to play.
2. Gather your stuff.
3. Drive to the tennis court.

Of course, it doesn't always happen like that. So you might want to refine that both be more specific and cover every possible result.

1. Call a friend and invite them to play. If the friend says no, repeat this step with another friend. If the friend says yes, go to Step #2.
2. Decide a time and location to play.
3. Locate your tennis racket.
4. Put your tennis racket in your car.
5. Ten minutes before [time] occurs, drive to [location].

As you can see, you could keep breaking this down into further steps and further alternative scenarios.

## Ingredients of Algorithms

• The more complicated algorithm above actually contains a number of programming principles. Take a look at Step #1. That's a basic programming loop: keep doing a certain task (calling friends) until a condition is met (one says yes).

You could also look at it as a "case" or an "if/then" statement. In the case of "yes," go to Step #2. In the case of "no," go to Step #1. Or, if "yes," go to Step #2. If any other answer, repeat Step #1. You have to personally decide the best method to use for each particular algorithm.

Step #2 creates two variables: a time, and a location. You can plug them into your program later, in Step #5, when your actions are dependent on the values of the two variables.

Finally, Step #5 contains an event: when [time] minus ten minutes occurs, get in your car.

## Error Checking and Comprehensiveness

• One of the major difficulties behind creating algorithms is the necessity to cover every scenario. This is most obviously illustrated in creating programs that depend on user input. For example, in a video game, what if the player decides to kill a character that's vital to the plot? Do you make the character indestructible? Do you create an alternative victory condition? In an online form, what if you ask users to input a number between one and 10 and they input "bob"? In order to create the sturdiest algorithm possible, you must think out all possible outcomes and build in checks for each of them.

## References

Promoted By Zergnet

## Related Searches

Check It Out

### Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.