Algorithm is simply a set of instructions required to successfully complete a task. For example, an algorithm for making a food, we call it a recipe, a set of ordered instructions. Then there are different types of recipes, using little tricks to make your food quicker like using a pressure cooker instead of usual pot for boiling. This new trick makes our recipe quicker or time efficient.
Similar are concepts for algorithms in computer science, we humans give computers a set of instructions in the language that computer will understand, and as Prof David Malan says these instructions shall be precise, letting computer know what to do at each step and how to do it. And as in the above example some algorithms are better (efficient) than others and hence are preferred.
A common algorithmic example is a search algorithm, suppose we want to find a word in a dictionary, a naïve/ brute force algorithm would be to go through each word and look if our desired word matches the current word we are looking at, if it does, voila! Now we would terminate our search. An important thing for an algorithm is to terminate, otherwise, it will keep using the resources.
So, algorithms are precise set of instructions that a computer follows to successfully perform a task. But, given limited computational resources we want to finish a task as soon and with minimal energy cost. So, we want our algorithm to be time efficient, space efficient, and cost efficient. Space efficient refers to using minimal memory while carrying out a task, and cost efficient refers to complete a task with minimum computation steps.
So, we study algorithms with these things in mind, for our algorithm to be time efficient, space efficient and cost efficient. Now, it’s natural for a person to think, we have to study algorithms for efficiency because of limited computational constraints, so if we had unlimited resources, we might not need study algorithms. But we do, we would still need to study algorithms as Stein et. al. says in their book Algorithms, we would still need to study algorithms for our algorithm to successfully complete a task with a correct answer and reach a terminal state. So, not only terminate but does so with a correct answer.
30 Jan 2024.
Next in series: Binary Search.