Need of an Algorithm

Distribute Education like Computer Geek

Assume you have a problem that can be solved by you or by a machine (computer), and you must follow a specific procedure to solve it. This instruction or the command written in a simple language of the procedure is known as an algorithm.

Need of an algorithm
Complex Algorithms

.

Why We Need Algorithms in Every Task

While we do any activity, there are some specific procedures to be followed so that the work is done in a proper way. Whether the work is easy or hard, there is always a method or a plan that needs to be followed to generate the desired output of the work. This is what algorithms help to do. It provides us with a clear means of ensuring the task is carried out efficiently and correctly.

Consider the simple tasks like cooking, solving a math problem, or going from one place to another. For each of these tasks, we have a specific process in mind, written down or just mentally. Without such steps, we may not easily get the correct results.

In computer science and other fields, algorithms are similarly important for performing tasks in an organized manner, improving performance, and ensuring that our results are consistent.

This is why we need algorithms, to simplify, standardize, and guide our actions so as to ensure accuracy and efficiency in everything we do.

An algorithm can be a tea recipe.

  1. Start
  2. Put Tea pan on the gas
  3. Pour water, milk, and tea leaves
  4. Boil the mixture
  5. Add sugar
  6. Boil the mixture
  7. Tea is ready
  8. Stop

The inputs are water, sugar, tea leaves, tea pan, and gas and the output is tea.

The algorithm is (Definite) clear and unambiguous, also has an (Effective) possible result and terminates after a finite number of steps. If any of these qualities are not fulfilled, then it is not an algorithm, and we can not do that task. It means Donald Ervin Knuth said it correctly.

.

Algorithms are typically written in pseudocode, or a combination of your native language and one or more programming languages, before being implemented in a program. The tea recipe above is a pseudocode because it is written in the English language, and we can add some syntax of any programming language, so that is why it is also called an algorithm.

If you want to write a program in any language (C, C++, Java, or Python), you have to write an algorithm or pseudocode first, and it should be in a bullet-numbered form. So, while making the program, you exactly know what the logic behind it is if it is in numbered form.

.

Note: The algorithm should be very simple, but few of you have read Coreman’s book, and understanding the logic behind the algorithm in that book is not an easy task. But most of the professors and researchers on this earth, read and teach Coreman’s book and deal with the complexities of algorithms.

.

Algorithms are essential for the following reasons
  1. Problem Solving – Algorithms provide a systematic approach to solving complex problems. They break down the problem into smaller, manageable steps, making it easier to find solutions, just like Divide & Conquer.

  2. Efficiency – Algorithms aim to find the most efficient way to solve a problem. They optimize resource usage, reduce time complexity, and minimize memory requirements.

  3. Reproducibility – Algorithms are well-defined and unambiguous, ensuring that anyone following the steps can achieve the same result.

  4. Scalability – Algorithms can handle large datasets or problems, making them suitable for use in various applications, including big data processing and large-scale computations.

  5. Reusability Once an algorithm is developed and tested, it can be reused in similar problem-solving scenarios, saving time and effort.

  6. Automation – Algorithms allow tasks to be automated, reducing human errors and increasing accuracy in various applications, such as machine learning and artificial intelligence.

  7. Standardization – Algorithms provide standard methods for solving common problems, leading to consistency and compatibility across different systems and platforms.

  8. Decision Making – Algorithms are used in decision-making processes, such as route optimization in navigation systems or financial modeling in investment decisions.

  9. Predictive Analysis – Algorithms play a crucial role in predictive analysis, helping to forecast trends, patterns, or future events based on historical data.

  10. Scientific and Engineering Applications – Algorithms are fundamental to scientific simulations, engineering designs, and various computational tasks.

Test Yourself

Q1- What is the difference between Algorithm & Pseudocode?

Algorithms are typically written in pseudocode, or a combination of your native language and one or more programming languages, before being implemented in a program.
Pseudocode is written in natural language and it will have some mathematical notation which is easy to understand. It is an informal text with a simpler version of the solution. Algorithm is a formal text which is unambiguous, effective, finite and definite. 

Q2- What comes first – Algorithm, pseudocode or program?

First you draw pseudocode, which is informal and written in native languages, and mathematical notation (if any).
Second, you draw an algorithm by taking pseudocode into a formal language, and the instruction should be clear, unambiguous, finite, effective, and definite.
Then, in the 3rd part, you will generate a program by taking clear and unambiguous instructions from the algorithm.

Q3- Is the algorithm for each programming language different? 

No, algorithm is same for each programming language. Algorithm just gives us logic and logic are same for every programming language.

Q4- Should an algorithm be rewritten if code is written in one language and then rewritten in another language? 

Yes, the algorithm will have to be rewritten if the algorithm of the previous code is not written. Because a programmer can understand that logic only if he has an algorithm. Break the previous code into smaller form and rewrite the algorithm. 

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha

Â