Algorithms
An algorithm is a set of well defined steps for solving a problem. There may be many different algorithms for solving the same problem. Algorithms that solve the same problem are often compared to each other to choose the best algorithm to implement. Some common criteria for comparing algorithms are:
- number of steps
- difficulty (time) of implementing
- type and amount of data required
- execution time of implemented version
- ease of maintenance of implemented version
We often describe algorithms using pseudo-code. Pseudo-code is English (at least for us) that looks a little like program code. It is easier to understand than program code and it better illustrates the step-by-step nature of a solution than paragraphs written in English.
Example: Pseudo-code algorithm for calculating a person's BMI
- Save the height and weight of the person in variables.
- If necessary, convert weight to kilograms and height to meters.
- Calculate the BMI as weight / height2.
- Display the results to the user.
Once we have an algorithm for solving a problem, we can implement (code) it in Matlab or any other suitable programming environment.
Most algorithms are much more complex then a single list of steps. They often have conditional statements and iterative statements as part of a much larger solution. We will discuss conditional execution in a later lesson in this module and iterative execution in a later module.
For more information about algorithms, read the
http://en.wikipedia.org/wiki/Algorithm entry.