Group 24
Group 24
● Most of the divide and conquer design uses the concept of recursion
therefore it requires high memory management.
● Memory overuse is possible by an explicit stack.
● It may crash the system if recursion is not performed properly.
● It may crash the system if the recursion is performed rigorously.
● It involves recursion which is sometimes slow.
● Dividing a problem into smaller sub-problems can increase the
complexity of the overall solution.
GREEDY ALGORITHM
• It refers to a problem-solving technique that selects the best option available (locally
optimum choice) at that particular moment with the hope of finding a global optimum.
• It does not take into account whether the current best option does not lead to optimal
results.
• It does not reverse its earlier decision even though it turns out not to be the best
decision ever.
• It is a top-down approach which means that it divides its problems into small problems
that is to say we start from the top of the problem and gradually reach the bottom.
GREEDY ALGORITHM
20
GREEDY ALGORITHM
GREEDY ALGORITHM
GREEDY ALGORITHM
● Kruskal’s algorithm
● Prim’s algorithm of finding minimum spanning trees
● Prim’s algorithm of finding Hoffman trees
● Scheduling tasks to minimize the total time required
● Finding the shortest path in a graph
● Selecting subset of items to maximize a certain value, subject
to a constraint on total weight or cost
TIME AND SPACE COMPLEXITY
• Solves sub-problems recursively and stores their solutions to avoid repeated calculations.
• The solutions of sub-problems are combined in order to achieve the best solution.
• Dynamic algorithms use Memorization to remember the output of already solved sub-
problems.
What are sub-problems ?
Sub-problems are smaller versions of the original problem. Let’s see an
example. With the equation below:
Sub-problem 1: 1+2
Sub-problem 2: 3+4
● Once we solve these two smaller problems, we can add the solutions to
these sub-problems to find the solution to the overall problem.
● Notice how these sub-problems break down the original problem into
components that build up the solution.
Applications
The following computer problems can be solved using dynamic
programming approach
● Fibonacci number series
● Knapsack problem
● Tower of Hanoi
● All pair shortest path by Floyd-Warshall
● Shortest path by Dijkstra
● Project scheduling
What are sub-problems ?
Implementation
F(5)
F(4)
F(3)
F(3)
F(2)
F(2) F(1)
F(2) F(1)
1. typically O(n log n) or O(n) 1. typically its O(n log n) for is typically exponential, 1. is typically O(n^2) or
for problems that can be problems that can be O(b^d), where b is O(n^3) for problems that
solved by making locally divided into sub-problems the branching factor and d is involve computing optimal
optimal choices at each of equal size, such the depth of the search tree, solutions for all possible
step, such as the Huffman as sorting for problems that involve sub-problems, such as
coding problem and the algorithms like merge searching through all possible the knapsack problem and
minimum spanning tree sort and quicksort. solutions, such as the N- the matrix chain
problem. queens problem and the graph multiplication problem.
2. It can be higher: closest coloring problem.
2. can be higher, like in the pair of points algorithm is 2. can be higher, like in the
case of the traveling O(n^2 log n) case of the sequence
salesman problem, where alignment problem, where
the time complexity is NP- the time complexity is
hard. O(n^2 m).
Space Complexity
NB: Space complexity of these algorithmic designs depends on many factors, including the specific problem being solved, the
implementation details of the algorithm, and the size and structure of the input.