What is an algorithm?
At its core, it’s simply a set of instructions. Think about making a sandwich or baking a cake. You list the ingredients. In code, you list the variables you need. In a recipe, you follow steps; otherwise, you’ll end up with a mess, especially if you add butter after baking the cake. Similarly, in coding, the process is sequential. The code executes line by line, starting from the first line and working systematically through each one.
When baking a cake or meal, you might prepare other components separately. For example, making beans on toast (a British favourite, especially with HP sauce) involves toasting the bread separately so it’s ready when the beans are done. This isn’t linear.
In coding, functions perform specific tasks. They can operate concurrently with the main code executing its instructions. These functions can be integrated into the code to execute at specific points.
The purpose of an algorithm in coding is to solve a problem. It’s not a standalone entity. You have a specific problem to solve, so you create a series of steps to achieve that. The beauty of an algorithm lies in its ability to be refined and reused.
Links: