The Different Types of Algorithm


Sharing is caring!

The programming world, is very fascinating and interesting, many programmers understand that having their skills sharp and up to date, is very important to solve very complex algorithm questions and problems with code.

In order to be able to solve these complex questions, a good software engineer must be familiar with the different types of algorithms, and algorithm techniques, which exist, to solves complex algorithm problems.

In today’s article we are going to be talking a bit about algorithms, how they work, the different types that exists. A computer is able to solve problems, by using algorithms, which are well-defined procedures, used by software engineers to solve complex algorithmic problems.

Some of the algorithms available today are, Simple recursive algorithms • Backtracking algorithms • Divide-and-conquer algorithms • Dynamic programming algorithms • Greedy algorithms • Branch-and-bound algorithms.

Recursive algorithm, calls itself but with simpler or smaller input values, which are used to to obtain the results of the operations. When a function calls itself, directly or indirectly, it is known as recursion, the recursive function is the corresponding function.

The base case is provided with a solution in recursion, and for the bigger problems a solution is provided in terms of smaller problems, by dividing that big problem into smaller problems. The base case is the case for when the answer is known and can be expressed, without the need to use recursion. In recursive algorithm, a problem is represented in terms of one or more smaller problems, then the base case is used to stop the recursion.

A stack overflow problem may occur, if the base case, has not been reached or well defined. A recursive algorithm may be direct or indirect, which means that when a function bread() call function bread() then this is known as direct recursion.

However, if function bread() call a function bread_new() and then that function call function bread() then this is known as indirect recursion.

The following code is from


// PHP program to demonstrate 

// working of recursion    

// function to demonstrate 

// working of recursion

function printBread( $milk )


     if ( $milk > 1) // base case

         return ;



         echo ( "$test " );

        // statement 2

        printBread( $milk + 1); 

         echo ( "$test " );

         return ;



// Driver Code

$milk = 3;

printFun( $test );    

// This code is contributed by

// Smitha Dinesh Semwal.


Another type of algorithm is known as Backtracking algorithms, which searches every possible combination in order to solve a computational problem. A solution is build incrementally in a backtracking algorithmic technique, which solves problems recursively.

The solutions which fail to satisfy the constrains of the problem, are removed from being identified as a possible viable solution to the problem.

The types of backtracking problems are known as Decision problems, which is where a feasible solution is searched. Another type is optimization problem, where the best solution is searched, and enumeration problem, which finds all the feasible solutions.

Backtracking algorithm is simple and elegant, however it is not the best performing algorithm out there for use. In backtracking algorithm we attempt to solve the problem by trying something, if that doesn’t work, then backtrack what we did and try something else, if that doesn’t work neither backtrack what we did then try solving something else, until the solution is reached. The problem in backtracking is divided into sub problems, and each of those sub problems are solved until a solution is reached.