Introduction to Algorithms

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(); }
Code language: C++ (cpp)

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
Code language: C++ (cpp)

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
Code language: C++ (cpp)

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.


Analysis of Algorithms

Algorithms Analysis help us to determine which algorithms are more efficient. Types of analysis:-Worst, Best,…
Read More

Recursive Algorithms

Here, We will learn about recursive algorithm, recursion, recursive function, implementation, properties and examples of…

Read More

Iterative Algorithms

Here, We will learn about the iterative algorithm, iteration, implementation and properties of iteration. Iterative…

Read More

Quick Sort

Here, We will discuss about Quick sort in C, their algorithm, implementation in C, time…

Read More

Binary Search

Here, We discuss about Binary Search, their implementation in C, time and space complexity and…

Read More

Want to Contribute:-

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

Leave a Comment

Your email address will not be published.