Part 1. Block diagram
The block diagram is a kind of algorithm representation where all main parts of the algorithm are represented with blocks (usually, every type of algorithm part is represented with a different shape of a block). Those blocs are connected with lines which represent relations between blocks.
Each block contains information about the block’s function, condition or other purposes. Some lines between blocks also could contain some additional information about the relation. Block diagrams are very popular in different industries like design electronics or hardware, design architecture of a system, software design, process flow diagrams and so on. As we are learning algorithms, software design and process flow diagrams are the most relevant for us. So let’s get started!
The block diagram is used for the visual explanation of some processes, flows or algorithms. It can be top-level or low-level, general or detailed. We also can use references to sub-diagrams from a top-level diagram for describing or detailing particular steps.
Let’s look how the main parts of the algorithm are represented in the block diagram. If you are not aware about main parts of an algorithm – please read the introduction article.
Entry/Exit point
Every algorithm has an entry point and an exit point in other words it can be called a “Terminal” block. It can be labelled with “Start“/”End” or “Entry“/”Exit“.
Input/Output block
The input data block and output data block are represented with a parallelogram figure. This block is used only for an algorithm’s input parameters or output parameters. Don’t use it for user input and display output to a user.
Data storage
This block is used to describe which data is stored in persistent storage. It can be disk storage, database etc.
Action/Data processing
One of the commonest blocks of the block diagram is an action or data processing block. It is shown as a rectangle containing a formula or description of the process
Sub-process/Reference
Sometimes we want to use some data processing or action which is complicated or complex enough to draw it directly on the current diagram, or we want to reuse it in different diagrams. In that case, we can use a reference to the previously described diagram which can be called a sub-process, sub-routine, etc.
Condition/Decision
Conditional or decisional blocks are used when we want to make difference in data processing depending on some condition. It is usually depicted as a rhombus with a condition written inside. Also, those blocks are followed by two directional lines for a positive result and a negative result. It also is a main part of loops (repetitive part of a diagram) where one of the result direction points to the first block in the loop and the other one points to some block outside of the loop.
Process flow directions
Flow lines are very important in any block diagram. Each line has a direction which defines a flow or an order in which blocks should be considered or operations/processes be performed.
Let’s do a little practice
Now we know the main blocks which are commonly used in diagrams. And now we gonna create an example of a simple algorithm for preparing a coffee. We will start with a simple one and will complicate it to use as many blocks as possible and you will see how the top-level diagram could be detailed.
So, here is the simplest top-level algorithm. Hmm… not looks like an algorithm. Now we gonna add some details to it
That’s better now. We have now input parameters like instant coffee, sugar and water. And our algorithm has already steps and actions on how to make a cup of coffee.
This is an example of a straight-flow algorithm, but in the real world and actual problems, it is common to see branches in the algorithm. According to some conditions we might do some different actions and proceed with another flow. So, let’s add some milk to our coffee…
Wow! Now it looks more complicated, doesn’t it? What have we done here? Well, we added “milk” as a parameter, and added two conditions – If we want coffee with milk or not, and if we want raw milk or foamed one. But besides of that we also used a sub-process of the foamed milk preparation and just included it in the main block diagram. And also, as you might notice, in the sub-process, we used a conditional block to define a loop, so we keep making foam until it became good enough to add to the coffee.
Ok, great! Now you are familiar with how to create a block diagram for any algorithm. You can practice this with any of your daily routines and visualize the process for yourself or anyone curious. For building a diagram you may use different software such as paint or MS Word, or you can use online tool like diagrams.net. Good luck!
Thanks for reading! See you!
Continue with:
- Introduction – What is an algorithm?
- Part 1 – Block Diagram – this article
- Part 2 –
- Part 3 –
- Conclusions