You are on page 1of 8

Comparison among

Greedy, Divide &


Conquer and
Dynamic Programming
Algorithms
Nasser Saleh : 2023-MSCS-28
Greedy Algorithms
Greedy algorithm is defined as a method
for solving optimization problems by
taking decisions that result in the most
evident and immediate benefit
irrespective of the final out come.

Tuesday, February 2, 20XX Sample Footer Text 2


Divide and Conquer
Algorithms
A typical Divide and Conquer algorithm solve a
problem using the following three steps:
1-Divide: This involves dividing the problem into
smaller sub-problems.
2-Conquer: Solve sub-problems by calling
recursively until solved.
3-Combine: Combine the sub-problems to get the
final solution of the whole problem.

Tuesday, February 2, 20XX Sample Footer Text 3


Dynamic Programming
Algorithms
Dynamic Programming is a technique
in computer programming that helps to
efficiently solve a class of problems
that have overlapping subproblems and
optimal substructure property.

Tuesday, February 2, 20XX Sample Footer Text 4


Comparison
Greedy Divide & coquer Dynamic programming

Breaks down a problem into


smaller subproblems, solves
Makes locally optimal each subproblem Solves subproblems
choices at each step with the recursively, and then recursively and stores their
GOAL
hope of finding a global combines the solutions to solutions to avoid repeated
.optimum the .calculations
subproblems to solve the
.original problem

Solves a problem by
dividing it into smaller
subproblems, solving each Solves a problem by breaking
Finds the best solution
subproblem independently, it down into smaller
GOAL among a set of possible
and then combining the subproblems and solving
.solutions
solutions to the subproblems .each subproblem recursively
to solve the original
.problem
5
Comparison
Greedy Divide & coquer Dynamic programming

O(nlogn) or O(n) depending O(nlogn) or O(n^2) O(n^2) or O(n^3) depending


:Time complexity
.on the problem .depending on the problem on the problem

O(1) or O(n) depending on O(nlogn) or O(n^2) O(n^2) or O(n^3) depending


:Space complexity
.the problem .depending on the problem .on the problem

May or may not provide the May or may not provide the Guarantees the optimal
Optimal solution
.optimal solution .optimal solution .solution

:Examples
Fractional Knapsack proble ,Merge sort :Examples ,0/1 Knapsack :Examples
m ,Quick sort ,All pair shortest path
Examples Strassen’s
, .Matrix-chain multiplication
,Activity selection problem . matrix multiplication
.Job sequencing problem

6
the main differences among these algorithms are their approach,

Summary goal, time and space complexity, and their ability to provide the
optimal solution. Greedy algorithm and divide and conquer
algorithm are generally faster and simpler, but may not always
provide the optimal solution, while dynamic programming algorithm
guarantees the optimal solution but is slower and more complex.
7
Thank You
Nasser Saleh

2023-MSCS-28

You might also like