Aaryan Rana (3)
I am an experienced digital marketing analyst with a passion for data-driven insights, optimizing campaigns, and driving business growth with 3years exp.
Here is a list of the types of Algorithms to begin with:
The simplest possible algorithm that can be devised to solve a problem is called the brute force algorithm. To device an optimal solution first we need to get a solution at least and then try to optimise it. Every problem can be solved by brute force approach although generally not with appreciable space and time complexity.
Example:
Exact string matching algorithm
Greedy algorithm is an algorithm that solves the problem by taking optimal solution at the local level (without regards for any consequences) with the hope of finding optimal solution at the global level.
Greedy algorithm is used to find the optimal solution but it is not necessary that you will definitely find the optimal solution by following this algorithm.
Like there are some problems for which an optimal solution does not exist (currently) these are called NP complete problem.
Example:
Huffman tree, Counting money
For better understanding lets go through the most common problem i.e. Job scheduling problem: Let us consider a situation where we are given the starting and end times of various events in an auditorium. Now your job is to maximise the number of events that can be organised in the auditorium where no two events overlap ( starting time or ending time of one event does not fall in between the starting and endpoint of another event).
This is one of the simplest to devise algorithm as it does not require to specifically think about every subproblem. This means we just need to think about the existing cases and the solution of the simplest subproblem, all other complexity will be handled by it automatically. Recursion is a very powerful tool although we should always take care of memory management here as recursion works using recursive stack which is called every time recursion function is invoked. Recursion simply means calling itself to solve its subproblems.
For Example:
Time Complexity: O(n)
Although always remember to give the base case else the loop will continue to infinity giving memory error. This algorithm is simpler to design and implement.
It is an improvement to the brute force approach. Here we start with one possible option out of many available and try to solve the problem if we are able to solve the problem with the selected move then we will print the solution else we will backtrack and select some other and try to solve it. It is a form of recursion, it’s just that when a given option cannot give a solution, we backtrack to the previous option which can give a solution and proceed with other options.
Let us see the application of this algorithm in generating all strings with n bits.
This is one of the most used algorithms in programming. This algorithm divides the problems into subproblems and then solve each of them and then combine them to form the solution of the given problems.
Again, it is not possible to solve all problems using it. As the name suggests it has two parts: Divide the problem into subproblems and solve them.
The given problem is divided into two parts of n/a and n/b size and then computed separately and recursively to bring back the result and combine them to form the solution.
Applications:
Example:
 Quick sort , Merge sort.
This is the most sought out algorithm as it provides the most efficient way of solving a problem. Its simply means remembering the past and apply it to future corresponding results and hence this algorithm is quite efficient in terms of time complexity.
Dynamic Programming has two properties:
 This algorithm has two version:
Let us take a simple example of such algorithm.
Finding the Fibonacci Sequence.
Recursive stack of the function for n = 4
Time Complexity: O(n) Space Complexity: O(n)
As we can see the dynamic programming approach gives faster result although takes up extra space. Most of the problems involving finding the nth element in a sequence can be computed faster using Dynamic programming.
A randomized algorithm uses a random number at least once during the computation to make a decision.
Example:
Quick sort
Article comments