What is an Algorithm in Computer? (Explained in Simple Words with Examples)
Many of you might have heard the name of the algorithm. Let’s say you stand at a shop where there are only shoes and you think about how good the shoes are, then you go to that shop and ask about their price also but for some reason, you did not like it or the price did not seem good, it could be any reason. Then you come home and search for the same shoes on your mobile and see what their price and quality are, and compare them. After doing all this, you keep the phone aside, and then after some time or the next day, you see similar ads. These ads start appearing on your phone, whether you are using social media or using YouTube; in fact, if you are on any e-commerce site or any educational site, you are shown similar ads there too. So overall, this whole game is the work of algorithms. If you search for something on your phone, then you are shown ads or videos, posts related to that. Read Also : What is the Latest Invention in Science and Technology Today How technical it sounds to hear the algorithm, but it is a part of our daily routine, whether you want to shortlist a list or you have to search for contacts on the phone. In this blog, I will explain to you in very simple language what an algorithm is, how it works, and what is its importance in programming. No heavy theory, just real-life examples, easy explanations, and step-by-step guides – so that it becomes clear to you that this ghost named “algorithm” is not as complex as it appears. What is an Algorithm? (Simple Definition) First of all let us try to understand the basics of what an algorithm is; an algorithm is basically a set of step-by-step instructions that are created to solve any problem. It is just like you have to go through the process of making something. If you are making a vegetable, then a process is followed for making it. First, the vegetable is cut, then that vegetable is washed with water, then it is put in a pan, then it is cooked for a while, then spices are added, and water is added at the end. So, if it is cooked properly, then this is the process of making vegetables. Just like that, an algorithm follows a process to perform any task. Similarly, something similar happens in the computer world as well; you can use your mobile apps or social media that I use, like YouTube, Instagram, or Google Maps; there are several algorithms working behind them. For every small activity, a logic or rule set is made, which is called an algorithm. Its job is to break the problem and define each step logically – so that the computer can work without getting confused. The computer does not think on its own; everything has to be explained to it – and this way of explaining is an algorithm. Real-Life Examples of Algorithms Let us understand this with a real-life example, like you are making tea, then first you heat the water, secondly you add tea leaves, thirdly you add milk and sugar, and finally, how to serve the tea. This is a complete process, and this process itself is an algorithm. An algorithm does not mean only technical or computer or coding; it is everywhere. Whenever you do any work without skipping any step, without any logic, that process also follows an algorithm. We try to explain with some simple and interesting examples. Like we just saw about desire, we followed its process. Finding a name in phone contacts Just like when you are searching for any contact in your phone, you also follow an algorithm there, like you press your A key later and all the names starting with A start appearing on your screen, absolutely systematically. This is called a search algorithm because it refines the result and shows it to you. Books Arranging alphabetically Just like when you have to arrange books alphabetically, you keep books in the book library in the order from A to Z, and there you also follow a process as to which book will come first and which one later. This is also an example of a type of shorting algorithm, and the same logic is used in computer programming also. These examples show you that an algorithm is not rocket science – it is just a game of common sense and logic. You are using algorithms consciously or unconsciously every day. How Algorithms Work in Computers Till now we have discussed what an algorithm is, and we have understood it through a real-life example. Now, let us talk about how all this works inside a computer. If we talk about a computer, the computer does not think on its own. It has to be told a group of instructions for every task. And the ordered set of those instructions is an algorithm. Imagine you opened a calculator app and typed 5 + 3. Now what will the computer do? He will follow an algorithm that performs these steps: Read the first input (5 and 3) Simple, right? But all this happens so fast and efficiently that you hardly even realize it. Another example: Login system Think if you log in to a website or app and you are asked to enter your username and password, there too an algorithm that works. Looped Algorithms Sometimes what happens is that the computer has to do a task repeatedly – check 100 items from a list. Then the algorithm uses a loop like: “Repeat until all the items are checked.” This saves time and also makes the process efficient. In short, every work of the computer is done by an algorithm – be it your Google search, a product suggestion on Amazon, or a recommended video on YouTube. Types of Algorithms (Beginner-Friendly Explanation) Types of Algorithms