al·go·rithm/ˈalɡəˌriT͟Həm/ Learn to pronounce noun: algorithm; plural noun: algorithms
- a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.”a basic algorithm for division”
If you read the above definition, you’re probably just as lost as when you started, so lets break it down into what it is, and what it means for a software developer.
A software developer is often given a problem that needs to be solved. This could be a complex mathematical formula based upon a lot of inputs (think, solving and filing your taxes), as series of steps to control a CAM (Computer Assisted Manufacturing) robot arm, etc.
The developer will take this abstract directive (properly calculate a person’s taxes) and from there, create a step by step process to solve the problem.
The developer must break the problem down into sections simple enough steps that a computer can understand. Generally, a computer can understand 3 basic blocks. Within these basic blocks are other more complex structures, but for now we’ll look at the three items.
Process
A computer is expected to be able to process some information. This might be as simple as adding two numbers, or capitalizing a set of text. Sometimes these processes have many steps, or mathematical rules. Other times it will involve some sort of I/O, or input/output. This could be writing to a screen, reading a file, or sending a signal to control a motor.
Processes will be run in the order they are encountered/given, unless they encounter a different type of block.
If a process has multiple sub-processes, it might be relegated to a separate function or procedure so that it can logically operate as a single process. By grouping steps into a function or sub-procedure you can logically organize your code, and call these tasks multiple times throughout your program.
Decision
Computers often need to perform one set of processes if a condition is true, and another if the condition is false. This is called a decision block. The condition is a question that has to be provide a true/false answer. So you can’t say “based on the color”, but you can ask “if the color is blue”.
Decisions lets the computer change the path based upon the condition. They allow a program to execute a set of processes if a condition is met, or skip a set of processes.
The decision body will hold the processes to execute. It may include other decision blocks or even repetition blocks which we’ll look at in a minute.
Repetition
Repetition blocks allow for a process, or set of blocks, to be repeated. There are two major types of repetition blocks. Conditional, where they repeat until a task is met, or fails to be met. There is also counting loops, which are run a given number of times.
Within the body of the repetition block, you may have other repetition blocks, condition blocks, or sets of processes.
You will build an algorithm around these three blocks, using as many or few, as you need to meet your goals.
Intro to Algorithms was originally found on Access 2 Learn