

A brute force algorithm blindly iterates all possible solutions to search one or more than one solution that may solve a function. This is one of the simplest algorithms in the concept. To do Huffman coding, we first need to build a Huffman tree from the input characters and then traverse through the tree to assign codes to the characters. In Huffman coding, The algorithm goes through a message and depending on the frequency of the characters in that message it assigns a variable-length encoding for each character. Huffman Coding and Dijkstra’s algorithm are two prime examples where the Greedy algorithm is used. Solution function that tells when we have found a solution to the problem.An objective function that assigns value to a possible solution or to a partial solution.A feasibility function that helps in deciding if the candidate can be used to find a solution.A selection function that helps choose the best possible candidate.The first one is a candidate set from which we try to find a solution.The method does not guarantee that we will be able to find an optimal solution. In this algorithm, we find a locally optimum solution (without any regard for any consequence in future) and hope to find the optimal solution at the global level. These algorithms are used for solving optimization problems. In other words, a dynamic programming algorithm solves complex problems by breaking them into multiple simple subproblems and then it solves each of them once and then stores them for future use.įibonacci sequence is a good example for Dynamic Programming algorithms, you can see it working in the pseudo code: These algorithms work by remembering the results of the past run and using them to find new results. Merge the halves sorted in step 2 and 3:Ĭall merge(ar, l, m, r) 3.Find the mid-point to divide the given array into two halves:.

Here is the pseudocode of the merge sort algorithm to give you an example: Merge sorting, and quick sorting can be done with divide and conquer algorithms. Then, in the second part, these smaller problems are solved and then added together (combined) to produce the problem’s final solution.

In Divide and Conquer algorithms, divide the algorithm into two parts the first parts divide the problem on hand into smaller subproblems of the same type. This is another effective way of solving many problems. Return (y*Fact(y-1)) /* this is where the recursion happens*/ 2. For example, here is a code that finds a factorial using a recursion Algorithm:
