Representing Algorithms as Flowcharts
Algorithms can be written in multiple ways. We have been writing our algorithms using pseudocode. Using pseudocode allows you to write the algorithm using your own words and often in steps.
Flowcharts
You can also represent algorithms using flowchart symbols. Flowcharting can be considered outdated and too rigid, but for some people, it provides a structured way to look at the algorithm and assists them when translating an algorithm into program code.
We can use flowchart symbols to create an algorithm. In the flowchart, the following symbols are used:
Symbol |
Description |
Example |
Explanation of Example |
|
Used to start and end the algorithm. |
|
This symbol is used to start your algorithm. |
|
Used to represent a single step. |
|
Calculates the quotient of dividing totalTemp by 30 and assigns averageTemp the result. |
|
Used to make a decision, with the steps to take when the condition is true, going to the right and the steps to take when the condition is false, going to the left. |
|
Checks to see if your birthday,YourBday , is today. If it is, then it adds a free cookie, FreeCookie , reward to your account. |
The diamond symbol is also used to represent the decision for whether or not the statements should repeat.
| |
Checks to see if the number of repetitions, numReps is less than or equal to 10 . If it is, then it simulates a jumping jack, jumpingJack and increases the number of repetitions, numReps by 1 . |
|
Used to create a path for the algorithm to follow from one step to the next step. |
Brushing Teeth Algorithm
Pseudocode Example
The following represents an example of an algorithm, written in pseudocode, that could be used to brush your teeth.
- Get out the toothbrush and toothpaste. Uncap the toothpaste.
- Wet the toothbrush with water from the faucet.
- Put about a quarter inch of toothpaste on the bristles of the toothbrush.
- For each one of your teeth:
- scrub in circular motions on the front, back, and top of your tooth
- Spit excess toothpaste into the sink
- Rinse your toothbrush
Flowchart Example
The following represents an example algorithm, written using a flowchart, that is equivalent to the tooth brushing algorithm above.
Your Turn
|
Grab a Piece of Paper, Let's Try It! |
Re-write the algorithm you wrote of something you are really good at as a flowchart.
|
Resources
Next Learn Tutorial
Learn: Intro to Determining A Data Type