NonTech | Why software can run slow – Part 3/5 | Algorithms

Welcome to one of my NonTech Posts. This type of post is targeting a non-developer audience and tries to explain specific Topics on a high-flier level.

 

Algorithms describe what an application does. They lay out what and how much work the application needs to do.

An Example could look like this:

  1. Get input from user
  2. Select data from a Database
  3. Process each Dataset according to input – if input is invalid return to user
  4. Return to user with results

This is oversimplified, but I think you get the Idea.

Now imagine that every single one of those points above are just a collection of algorithms themselves. There is no magic command I can give a computer to just „process data“ or „check the user input“.

So what about these algorithms is relevant for performance?

Well, algorithms determine how much work your application has to do.

So the goal here would be to design algorithms which produce the required result, but require less work to do so.

How about the example above, did you find something strange in it?

If not, look at point 3.) - do you really want the application to check your input every time it processes a Dataset? What, if your input is wrong? How much runtime did you already waste, before the application would tell you that your input was nonsense?

And if your input is right, why would you do a repetitive task in your main data-stream?

The answer is you would not, you would change the algorithm:

  1. Get input from user
  2. Check input – if invalid return to user
  3. Select data from a Database
  4. Process each Dataset according to input
  5. Return to user with results

Now you achieve the same result but with less work, because you perform your input check only once.

The basic Message I want you to take with you is that algorithms determine how much work your application has to do. If the algorithm is more efficient, your application needs to do less and performance improves.

If the algorithm on the other hand is bad, you are facing a serious uphill battle which you will in almost all cases lose. Bad algorithms are a guarantee for a bad runtime.