Introduction to Algorithms

Last updated on September 4th, 2023 at 09:50 pm

Here, We will learn why every programmer should learn introduction to algorithms, categories of algorithms, characteristics of algorithms, how to write algorithms with help of examples like write algorithm for the addition of two numbers.

What are algorithms?

Algorithms are a series of steps or rules for solving a computational problem.

In other words, an algorithm a step-by-step procedure which defines a set of instructions to be executed in a certain order to get the desired output.

what are algorithms
ALGORITHMS

Example Code:

if (clock.getTime() == 7am){
    coffeeMaker.boilWater();
    if (water.isBoiled()){
        coffeeMaker.addCoffee();
        coffeeMaker.pourCoffee();
}
}
else{
    coffeeMaker.doNothing();
}

A good algorithms is like using right and efficient tool in workshop.

Example: Using wrong algorithms mean cutting paper with a saw or trying to cut a piece of plywood with knife.

Categories of Algorithms

  1. Search – Algorithm to search an item. Ex- Searching Techniques
  2. Sort – Algorithm to sort items in a certain order. Ex – Sorting Algorithms
  3. Insert – Algorithm to insert item.
  4. Update – Algorithm to update an existing item.
  5. Delete – Algorithm to delete an existing item.

Characteristics of an Algorithm

Not all procedure can be called an algorithm.

An algorithm should have the following characteristics:

  1. Unambiguous – Each of its step and their inputs/outputs should be clear and must lead to only one meaning
  2. Input – Should have 0 or more well-defined inputs
  3. Output – should have 1 or more desirable well-defined outputs.
  4. Finiteness – must terminate after a finite number of steps.
  5. Feasibility – Should be feasible with the available resources.
  6. Independent – Should have step-by-step directions and independent of any programming language.

How to Write an Algorithm?

There is no well defined standard for writing algorithms. Algorithms are never written in support of a particular programming code.

We write algorithms in a step-by-step manner. Algorithms writing is a process and is executed after the problem domain is well-defined.

Write algorithm for addition of two numbers and display the result.
step 1 - START
step 2 - declare three integers a, b &c
step 3 - define values of a & b
step 4 - add values of a & b
step 5 - store output of step 4 to c
step 6 - print c
step 7 - STOP

Algorithms tell the programmers how to code the program. Alternatively, the algorithm can be written as :

step 1 - START ADD
step 2 - get values of a & b
step 3 - c ← a + b
step 4 - display c
step 5 - STOP

In design and analysis of algorithms, usually the second method is used to describe an algorithm.

We design algorithms to get a solution to a given problem. A problem can be solved in more than one ways.



Want to Contribute:-

If you like “To The Innovation” and want to contribute, you can mail your articles to 📧 contribute@totheinnovation.com. See your articles on the main page and help other coders.😎

Scroll to Top