It’s probably the most popular question among those who just started to be interested in computers and programming. I guess you also are interested in this question, aren’t you?
If you want to know what makes computers do some cool stuff like games, the internet sites, or any other more or less useful software, you should learn about algorithms first before you start learning any programming language. It’s not very difficult to learn some programming language – it’s just like you learn syntax, some rules, and the most popular libraries or modules, and… TADAM! – you can write the greatest very first computer program in your life – “Hello World!”. But, what about more complicated things? You actually can’t… Because you are not familiar with building a logic of application – the Algorithm!
Meanwhile, what does the algorithm look like and how can you easily understand it? It is very easy, indeed. Whatever you read or heard about algorithms is probably true, but it is still complicated and you continue to search for any other information to make it clearer to you… But, what if I tell you that algorithms are all around you?
Morpheus: Do you want to know what it is? The Matrix is everywhere
The Matrix
You know, the simplest example of an algorithm I can show you – It’s your daily schedule… surprised? And what about a user guide, or job instructions? Ok, I will explain using a schedule. Every point in your schedule is like some command for you – to go somewhere, to make a call, to attend a meeting, and so on. And you are the executor or processor. Got it? For better understanding, I will explain parts of any algorithm and types using examples from the real world. So, algorithms could be written (in formal style or as a program), verbal or schematical. I will describe each type of algorithm representation in different articles, links will be available at the end of the article.
Besides, you should understand one thing – one algorithm can be represented with different levels of detail. For example, if you want to call a friend – you may just put this task as it is and you can divide it into more detailed parts – decide whom to call, find the number, and call the number. Let’s look at parts of an algorithm.
Main parts of the algorithm
Entry point – every algorithm has an entry point – this point is where all begin. The entry point can be simple or contain parameters for the algorithm. Your algorithm should have only one entry point, but if you need more than one entry point with fully different sets of input data for the algorithm – you should think about how to combine entry points into one or separate your complicated algorithm into several algorithms with referencing to each other. So, be aware of multiply entry points.
Description/comments – if you want to remember after years why you wrote your algorithm or to be clear for other dudes, who will ever read your algorithm. This part can be put not only at the start of your algorithm but also near other parts – just to remember.
Input data – every algorithm needs some data to operate. It can be some numbers or strings or whatever else. You definitely can write an algorithm without any data from outside – this algorithm will produce the same result every time you run it – this is not very useful and flexible. But how can the algorithm obtain this data?
You already know one way to do it – to pass such data as input parameters to the entry point. The next way you can obtain necessary information for your algorithm is to ask the “user” to input data from a keyboard or read it from a file. Great! You just have made your algorithm interactive!
Store data – the important part of the algorithm is storing input data or results of algorithm into some place like memory, storage, peace of paper, whatever.
Actions – or data processing. It’s the main part of any algorithm. Without these parts, an algorithm is not an algorithm, because we use it for doing something, not just to start and stop. We can use here all known data and usually produce some new data, or just make an action. As I said before exactly these parts can be simple or atomic – just one action or operation, and also they can be complicated and describe another algorithm.
Conditionals – these parts are actually optional, you can find or write some algorithms without conditions, they usually are called plain algorithms. Besides, they are very useful if we need to do different things regarding some conditions, data, or states.
Loops – sometimes we need to repeat some operations. Of course, you can simply duplicate operations for times you need, but what if you do some operations like million times – not a good idea… Here loops can help you – just put what you need to repeat and put some conditions when the loop should continue and when to stop. You can do this with conditional blocks described above.
Output – your algorithm can do some output for the user, to the file, or technical storage. You can do it in the middle of the algorithm and also at the end when all job is done. It is also an optional part as soon as your algorithm could be just util or sub-algorithm and just pass results outwards.
Exit point – the point where the algorithm should end all its jobs and operations to show its finishing state. And, as I said before, this part can contain some output parameters, which you pass outwards as the result of algorithm execution.
So, that is briefly about what is the algorithm and I believe you had increased your level of understanding. If not – you can read this article again 🙂 – just kidding. Anyway, you can read the next parts about types of representing algorithms with real-life examples and I’m sure you will become more confident with algorithm definition.
Thanks for reading! See you!
Continue with:
- Introduction – What is an algorithm? – this article
- Part 1 – Block Diagram
- Part 2 –
- Part 3 –
- Conclusions