Keywords: algorithms, flowcharts, pseudocode, work description
This article will demonstrate what an algorithm is and how to use them in computer programming. We will also see how we use both flowcharts and pseudocode to illustrate and structure an algorithm.
An algorithm is a methodical and systematic description of how to solve a problem. The definition of an algorithm is a step-by-step procedure of well-defined executable instructions designed to perform a task or solve a problem. An algorithm has many similarities with a program where the difference is that we can describe algorithms regardless of program language.
The algorithm can be seen as a job description of how we should solve a problem and describe the steps the program should take to accomplish that. The critical thing to remember is that there are usually many algorithms for solving the same problem. It is often important to contemplate the simplest and most effective way to solve the problem, rather than only going with the first solution that works.
In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computationWikipedia
With straightforward problem solving, you can manage by having your algorithm in your head, but as the degree of difficulty and complexity of the tasks increases, it is almost necessary to think through your algorithm carefully before you start coding. A good tip is to get in the habit of drawing or writing down the task’s solution. Therefore, you get an overview of your problem and can plan for each step of the way to your solution more easily.
At first, when creating a new algorithm, it can be complicated to get an idea of how and where to start and how everything is related. Setting up an algorithm is a creative process that requires problem-solving ability and structure. To help us make it easier to grasp the problem in front of us, we can use flowcharts and pseudocode. These techniques are not only beneficial to use for your benefit but also if you want to explain and discuss your intended solution with, for example, a friend or a colleague.
To visualize algorithms, you usually draw a so-called flowchart that shows what kind of action the program should perform. The three most common figures in a flowchart are:
If you want to draw your flow charts, we recommend draw.io, a free online site for drawing different figures and diagrams. We have used draw.io to illustrate the images we use in the examples on code-knwoledge.
Pseudocode is in computer programming a program code-like text used to describe how the algorithm should be formed. We could describe pseudocode as a “code sketch“, often written in bullet point, on how an algorithm is structured. Related to flow charts that we saw before, pseudocode can be described as a flow chart in text form.
There is no general standard for pseudocode; instead, the important thing is to be consistent with words and format used. In pseudocode, details that are not critical to the understanding of the algorithm are often omitted. Instead, the pseudocode focus on describing the algorithm generally. It is also essential that you do not try to make it more complicated than it needs to be, which may be easier said than done. A good rule of thumb might be to think that the pseudocode, like the flowchart, is there to help you, not make it more complicated. The simpler and easier they are to read, the greater the chance you will write the correct code from the beginning.
There is no general standard for pseudocode; instead, the important thing is to be consistent with words and format used
Below we will see two examples of how an algorithm works. We will, of course, use the two tools we have discussed, flow charts and pseudocode. Let’s start with an example of an algorithm for a thermometer.
In this example, we will draw an algorithm for a thermometer. We want to create a program that starts a heating element if the temperature is below 10 degrees. However, if the temperature is above 10 degrees, nothing should happen to the heating element, and the program should then wait 30 minutes before checking the temperature again.
If we write it down with a pseudocode, we get:
Additionally, if we then use a flow chart to visualise it:
Let’s look at another example. We will write an algorithm that, depending on whether it rains and how much rain, will start the windshield wipers on a car. To help us, we have a rain sensor that measures how much it is raining.
If it rains below 0.5 mm / h (millimeters per hour), the sensor does not detect it, and the windscreen wipers should not start. However, if it rains between 0.5 mm / h and 4 mm / h, the windscreen wipers should start at low power. If it rains over 4 mm / h, the windscreen wipers must start at maximum capacity. Finally, since we want to save computing power, we should only read the sensor every two minutes.
Okay, let’s take it step by step and write it down in pseudocode, that is, our job description.
Additionally, let’s use a flow chart as well
Please leave feedback and help us continue to make our site better.
How useful was this article?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
The algorithm can be seen as a job description of how we should solve a problem and describe the steps the program should take to accomplish that. Either you can write down step by step instructions that the program should execute, so-called pseudocode, or you can draw flow chart when you have more complex problems to solve.
.The three most common figures in a flowchart are:
An algorithm can be seen as a job description of how we should solve a problem. The algorithm describes the order in which things on that job description should be performed. With a more formal description, the definition of an algorithm is a step-by-step procedure of well-defined executable instructions intended to perform a task or solve a problem.
No. Flow charts is a tool that should make it easier when you are programming to structure your code and get an overview of how all parts are connected. It is not a must, and simply a technique you can use.
There is no general standard for pseudocode, but the important thing is to be clear and consistent. A good rule of thumb might be to ask yourself, would someone with comparable knowledge that you understand your pseudocode. In other words, keep it simple and straightforward so that someone else can understand your pseudocode.