DSA

What is an Algorithm? Definition, Types & Examples

With this tutorial, readers will learn what algorithms are and will understand about them with the help of few examples.

In computer programming, an algorithm is a set of well-defined instructions to solve a particular problem. Algorithms takes input or input(s) and it produces the desired outputs.

For example,

An algorithm to add two numbers:

  1. Take two number inputs.
  2. Add numbers using the + operator.
  3. Display the result.

Advertisements

Qualities of a Good Algorithm

  • Input and output variable should be defined precisely.
  • Algorithm Steps should be clear and unambiguous.
  • Algorithms should be effective in many different ways to solve a problem.
  • An algorithm should only include pseudo codes and not computer code. Algorithm should be written in such a way that it can be understood even by someone who doesn’t understand programming and can be decoded in different programming languages.

Algorithm Examples to understand the pseudo code.

Algorithm for adding two numbers.

Algorithm for finding the largest among given numbers.

Algorithm for finding the factorial of a number.

Advertisements

Algorithm 1: Add two numbers entered by the user.

Advertisements
Advertisements

Algorithm 2: Find the largest number among the given numbers.

Advertisements

Advertisements

Algorithm 3: Find the factorial of a number.

Advertisements
Advertisements

Hope you liked this tutorial, continue reading multiple articles on different categories here

Advertisements

Unknown's avatar

Shaky Byte

Your Saviour on your Coding Days

Leave a Reply