Vous êtes sur la page 1sur 5

Algorithms in DAA

1. DIVIDE AND CONQUER APPROACH


2. DYNAMIC PROGRAMMING
3. GREEDY TECHNIQUE
4. BACKTRACKING
5. BRANCH AND BOUND

1. DIVIDE AND CONQUER APPROACH


In divide and conquer approach, a problem is divided into smaller problems,
then the smaller problems are solved independently, and finally the solutions of
smaller problems are combined into a solution for the large problem.
Generally, divide-and-conquer algorithms have three parts −
 Divide the problem into a number of sub-problems that are smaller
instances of the same problem.
 Conquer the sub-problems by solving them recursively. If they are small
enough, solve the sub-problems as base cases.
 Combine the solutions to the sub-problems into the solution for the
original problem.
Application of Divide and Conquer Approach
Following are some problems, which are solved using divide and conquer
approach.

 Strassen’s matrix multiplication


 Merge sort
 Quick Sort
 Median Finding Algorithm
2. DYNAMIC PROGRAMMING

Dynamic programming is a method frequently applied to optimization problems,


problems where we are looking for the best solution to a problem.

A famous example of an optimization problem is the "travelling salesman


problem." A travelling salesman must visit n cities and return to the first city,
minimizing the cost of his tour (in terms of gallons of gasoline used, miles
travelled, or some other metric). An optimal solution is one that is no longer than
any other solution (we can't say "shortest" because there may be more than one
solution with the same length).

Steps of Dynamic Programming Approach


Dynamic Programming algorithm is designed using the following four steps

 Characterize the structure of an optimal solution.


 Recursively define the value of an optimal solution.
 Compute the value of an optimal solution, typically in a bottom-up fashion.
 Construct an optimal solution from the computed information.

Applications of Dynamic Programming Approach

 Matrix Chain Multiplication


 Longest Common Subsequence
 Travelling Salesman Problem
3. GREEDY TECHNIQUE

Greedy Technique uses iterative/recursive approach to solve an optimization


problem and selects an optimal (best) solution. Greedy approach look for simple,
easy-to-implement solutions to complex, multi step problems by deciding which
next step will provide the most benefit. It is not always the greedy technique
produce an optimal solution, but it helps in producing an approximate optimal
solution in a reasonable time. Greedy generally works on heuristic approach.

Components of Greedy Algorithm


Greedy algorithms have the following five components −
 A candidate set − A solution is created from this set.
 A selection function − Used to choose the best candidate to be added to the
solution.
 A feasibility function − Used to determine whether a candidate can be used
to contribute to the solution.
 An objective function − Used to assign a value to a solution or a partial
solution.
 A solution function − Used to indicate whether a complete solution has
been reached.

Following are few algorithms that make use of greedy approach/technique:

 Knapsack problem.
 Kruskal's Algorithm.
 Prim's Algorithm.
 Dijkstra's Algorithm.
 Huffman tree building.
4. BACKTRACKING

 Many problems are difficult to solve algorithmically. Backtracking makes it


possible to solve at least some large instances of difficult combinatorial
problems.

GENERAL METHOD
 The principal idea is to construct solutions one component at a time and
evaluate such partially constructed candidates as follows.
 If a partially constructed solution can be developed further without violating
the problem‘s constraints, it is done by taking the first remaining legitimate
option for the next component.
 If there is no legitimate option for the next component, no alternatives for
any remaining component need to be considered. In this case, the algorithm
backtracks to replace the last component of the partially constructed solution
with its next option.
EXAMPLE
 N QUEENS PROBLEM
 Graph Colouring

NOTE : REFER CLASS NOTE OF BACKTRACKING AND GRAPH


COLOURING
5. BRANCH AND BOUND

Branch and bound is a systematic method for solving optimization problems.


B&B is a rather general optimization technique that applies where the
greedy method and dynamic programming fail.
Branch and Bound is another method to systematically search a solution space. Just
like backtracking, we will use bounding functions to avoid generating subtrees that
do not contain an answer node.
However branch and Bound differs from backtracking in two important manners:
1. It has a branching function, which can be a depth first search, breadth first
search or based on bounding function.
2. It has a bounding function, which goes far beyond the feasibility test as a mean
to prune efficiently the search tree.
EXAMPLE:
 Travelling Salesman Problem

Vous aimerez peut-être aussi