What is an Algorithm?

What is an Algorithm?

In this lecture, we will learn what algorithms are with the help of examples.

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example,

An algorithm to add two numbers:

  1. Take two number inputs

  2. Add numbers using the + operator

  3. Display the result

Qualities of a Good Algorithm

  • Input and output should be defined precisely.

  • Each step in the algorithm should be clear and unambiguous.

  • Algorithms should be most effective among many different ways to solve a problem.

  • An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.

Algorithm Examples

  • Algorithm to add two numbers

  • Algorithm to find the largest among three numbers

  • Algorithm to find all the roots of the quadratic equation

  • Algorithm to find the factorial

  • Algorithm to check prime number

  • Algorithm of Fibonacci series

Algorithm 1: Add two numbers entered by the user

Algorithm 2: Find the largest number among three numbers

Algorithm 3: Find Roots of a Quadratic Equation ax2 + bx + c = 0

Algorithm 4: Find the factorial of a number

Algorithm 5: Check whether a number is prime or not

Algorithm 6: Find the Fibonacci series till the term less than 1000

Last updated

Was this helpful?