Dynamic, Greedy and Divide and Conquer

4 years ago Advait 0

-Advait Bajaj, 221910307002

Dynamic programming

The dynamic programming approach is similar to divide and conquer in breaking down the problem into smaller and yet smaller possible sub-problems. But unlike, divide and conquer, these sub-problems are not solved independently. Rather, results of these smaller sub-problems are remembered and used for similar or overlapping sub-problems.

Dynamic programming is used where we have problems, which can be divided into similar sub-problems so that their results can be re-used. Mostly, these algorithms are used for optimization. Before solving the in-hand sub-problem, the dynamic algorithm will try to examine the results of the previously solved sub-problems. The solutions of sub-problems are combined in order to achieve the best solution.

So we can say that −

  • The problem should be able to be divided into smaller overlapping sub-problem.
  • An optimum solution can be achieved by using an optimum solution of smaller sub-problems.
  • Dynamic algorithms use memorization.

Divide and conquer

In the divide and conquer approach, the problem in hand is divided into smaller sub-problems and then each problem is solved independently. When we keep on dividing the subproblems into even smaller sub-problems, we may eventually reach a stage where no more division is possible. Those “atomic” smallest possible sub-problem (fractions) are solved. The solution of all sub-problems is finally merged in order to obtain the solution of an original problem.

Broadly, we can understand the divide-and-conquer approach in a three-step process:

Divide/Break

This step involves breaking the problem into smaller sub-problems. Sub-problems should represent a part of the original problem. This step generally takes a recursive approach to divide the problem until no sub-problem is further divisible. At this stage, sub-problems become atomic in nature but still represent some part of the actual problem.

Conquer/Solve

This step receives a lot of smaller sub-problems to be solved. Generally, at this level, the problems are considered ‘solved’ on their own.

Merge/Combine

When the smaller sub-problems are solved, this stage recursively combines them until they formulate a solution to the original problem. This algorithmic approach works recursively and conquers & merge steps works so close that they appear as one.

Examples

The following computer algorithms are based on the divide-and-conquer programming approach −

  • Merge Sort
  • Quick Sort
  • Binary Search
  • Strassen’s Matrix Multiplication
  • Closest pair (points)

There are various ways available to solve any computer problem, but the mentioned are a good example of the divide and conquer approach.

Greedy algorithm

An algorithm is designed to achieve the optimum solution for a given problem. In the greedy algorithm approach, decisions are made from the given solution domain. As being greedy, the closest solution that seems to provide an optimum solution is chosen.

Greedy algorithms try to find a localized optimum solution, which may eventually lead to globally optimized solutions. However, generally greedy algorithms do not provide globally optimized solutions.

Examples

Most networking algorithms use the greedy approach. Here is a list of a few of them −

  • Travelling Salesman Problem
  • Prim’s Minimal Spanning Tree Algorithm
  • Kruskal’s Minimal Spanning Tree Algorithm
  • Dijkstra’s Minimal Spanning Tree Algorithm
  • Graph – Map Coloring
  • Graph – Vertex Cover
  • Knapsack Problem
  • Job Scheduling Problem
5.00 avg. rating (100% score) - 1 vote