4 minutes read

An algorithm is a set of consecutive steps needed to achieve some goal. Designing an algorithm is one of the base parts of the coding process. So, it could be helpful to understand the thinking process while working on your code. How do you start designing an algorithm? What are the most essential parts of algorithm design? How will it help you create better code? Do you really need algorithms? Let's try and answer these questions.

Algorithmic thinking

While working with code, you need to evaluate the main problem and deconstruct it in a number of steps. This way, you'll be able to create a step-by-step solution, which you can perfect and reuse. This is basically what algorithmic thinking is in coding. At its core, algorithmic thinking is a useful skill that evolves your understanding of processes within the code.

With it, your knowledge of basic algorithmic creation will increase, as well as your ability to implement it in different programming languages. While languages differ in syntax, the basic principles of writing code are mostly the same. So, developing your algorithmic thinking will allow you to be a programmer with more potential.

Algorithmic thinking is a mental tool that helps you to understand your problem better, formulate it correctly, as well as design and implement the algorithm.

Signs of algorithmic thinking

The ability to create and implement algorithms in a way that your code will run correctly shows that you truly understand the task at hand. If the task is too complex, you could decompose it as much as possible using ready-made algorithms. And well, it doesn't have to be your own algorithms all the time. There are multiple common algorithms that you could use to make your work easier. Just take all the sorting algorithms as an example.

Algorithmic thinking isn't that simple

On paper, algorithmic thinking is the simplest thing there is. You can summarize it as all "Just understand the problem and break it down into steps". Easy enough and it will indeed help you design an algorithm. But, in practice, you'll probably need to evaluate the problem multiple times. And each time there will be a new algorithm in mind.

You will probably have to evaluate the problem several times.

So, as the first step to better algorithm design, you should learn how to properly understand the problems you are facing. Understanding the problem is the basis for your algorithmic solution.

Code inputs and outputs

Let's try to visualize algorithmic thinking for some simple task. Imagine you were assigned the creation of a simple app that displays some text. There are a few predefined texts that could be shown depending on the pressed key. How do you start working on it?

In the beginning, let's try to consider the input and output of this app. As the input, we can only get numbers from one to four. And the output will consist of some text strings. So, we need to define the relations between inputs and outputs. Let's create a table for that:

Input

Output

1

Hello, this is a great day!

2

Welcome to this topic!

3

Let's discuss algorithmic thinking.

4

Understand the input and output.

This way, we know which user actions will lead to a certain outcome. It's one of the basic considerations while making an algorithm. You need to know what goes in your code and what comes out. And you need to consider it on multiple different levels.

Designing the algorithm

When you know the basic input and output, you can start designing the algorithm. Knowing the problem that needs to be solved, you can break it down into multiple steps. In our case, you need to create an algorithm that will get you from a number to some text. There can be multiple solutions to this problem. We will just use the simplest one: assign an ID number to each text and compare them to the input.

Designing the algorithm

It is our most basic algorithm. This is a start that could be iterated to create a more sophisticated algorithm.

You also need to evaluate your solution to understand its efficiency and know how it should function correctly. For example, we can find where our algorithm fails and consider redesigning it accordingly. Like, what should happen when there are no matches to the number input? If you don't think it through, your code will just show an error. However, you can consider making your algorithm the way that users will have to return to the starting point until they input the right number.

Algorithm in the form of a flowchart

Improving your algorithms

This example is pretty simple and easy to understand. But real tasks can be way more complex. So, there are times when you can't simply define all the inputs and outputs of the program in a second. This will lead to a deeper look and analysis of the problem, which, in turn, will lead to a more detailed algorithm. It will allow you to understand the impact of each individual step, and there could be many of them.

There are some ways to improve your algorithm at different stages of its creation. Mainly, you could try to consider all crucial inputs and outputs of your code and decompose your algorithms while designing. There are also many principles of algorithm design that you can learn to improve your solutions.

While designing algorithms, keep in mind that your solution needs to use the least amount of resources. That is, if it needs to be fast in terms of time and small in terms of memory usage. If there are a few ways to write an algorithm for a current task, you should evaluate its complexity and choose the one that would be the least consuming.

Conclusion

Algorithmic thinking is an approach to coding that can help you create better algorithmic solutions. Its main point lies in proper problem evaluation, which helps you in the design process. Being aware of the problem, with all inputs and outputs of your code, will greatly increase the quality of your algorithms. So, it's a good idea to apply algorithmic thinking as a starting point on the path to improving your code. It is just a basic mental tool that could help you improve your algorithms and make the coding process more thorough.

13 learners liked this piece of theory. 1 didn't like it. What about you?
Report a typo