Presented by:
FOR-IAN V. SANDOVAL
15-319-030
DIVIDE AND CONQUER
ALGORITHM
DIVIDE AND CONQUER
ALGORITHM- D&C
- an algorithm design paradigm based on
multi-branched recursion
- works by recursively breaking down a
problem into two or more sub-problems
of the same (or related) type (divide),
until these become simple enough to be
solved directly (conquer)- the solutions to the sub-problems are
then combined to give a solution to the
original problem
DIVIDE AND CONQUER
ALGORITHM- Both merge sort and quicksort employ a
common algorithmic paradigm based on
recursion.- Divide-and-conquer solves subproblems
recursively, each subproblem must be
smaller than the original problem, and
there must be a base case for
subproblems.
PARTS OF DIVIDE AND CONQUER
1. Divide the problem into a number of
subproblems that are smaller
instances of the same problem.
2. Conquer the subproblems by solving
them recursively. If they are small
enough, solve the subproblems as
base cases.3. Combine the solutions to the
subproblems into the solution for the
original problem.
DIVIDE AND CONQUER
DIVIDE AND CONQUER
D&C TECHNIQUE
- basis of efficient algorithms for all kinds
of problems
1. sorting (e.g., quicksort, merge
sort)2. multiplying large numbers (e.g.
Karatsuba)3. syntactic analysis (e.g., top-down
parsers)
4. computing the discrete Fourier
transform (FFTs)
D&C SKILL
- complex skill that requires a good
understanding of the nature of the
underlying problem to be solved
- as when proving a theorem by induction,
it is often necessary to replace the
original problem with a more general or
complicated problem in order to initialize
the recursion- there is no systematic method for finding
the proper generalization
ADVANTAGES
1. Solving difficult problem
- divide and conquer is a powerful tool
for solving conceptually difficult
problems: all it requires is a way of
breaking the problem into sub-
problems, of solving the trivial cases
and of combining sub-problems to the
original problem.
- similarly, decrease and conquer only
requires reducing the problem to a
single smaller problem
ADVANTAGES
2. Algorithm efficiency
- the divide-and-conquer paradigm often
helps in the discovery of efficient
algorithms- it was the key, for example, to
Karatsuba's fast multiplication method,
the quicksort and mergesort algorithms,
the Strassen algorithm for matrix
multiplication, and fast Fourier
transforms.
ADVANTAGES
3. Parallelism
- divide and conquer algorithms are
naturally adapted for execution in multi-
processor machines, especially shared-
memory systems where the
communication of data between
processors does not need to be planned
in advance, because distinct sub-
problems can be executed on different
processors.
ADVANTAGES
4. Memory Access
- Divide-and-conquer algorithms naturally
tend to make efficient use of memory
caches.- The reason is that once a sub-problem is
small enough, it and all its sub-problems can,
in principle, be solved within the cache,
without accessing the slower main memory.
- An algorithm designed to exploit the cache
in this way is called cache-oblivious, because
it does not contain the cache size(s) as an
explicit parameter.
ADVANTAGES
4. Memory Access
- Moreover, D&C algorithms can be designed
for important algorithms (e.g., sorting, FFTs,
and matrix multiplication) to be
optimal cache-oblivious algorithms–they use
the cache in a probably optimal way, in an
asymptotic sense, regardless of the cache
size.
ADVANTAGES
5. Round off Control
- In computations with rounded arithmetic,
e.g. with floating point numbers, a divide-
and-conquer algorithm may yield more
accurate results than a superficially
equivalent iterative method.
IMPLEMENTATION ISSUES
1. Recursion
- Divide-and-conquer algorithms are naturally
implemented as recursive procedures.
- In that case, the partial sub-problems
leading to the one currently being solved are
automatically stored in the procedure call
stack.- A recursive function is a function that is
defined in terms of itself.
IMPLEMENTATION ISSUES
2. Explicit Stack
- Divide and conquer algorithms can also be
implemented by a non-recursive program
that stores the partial sub-problems in some
explicit data structure, such as
a stack, queue, or priority queue.- This approach allows more freedom in the
choice of the sub-problem that is to be
solved next, a feature that is important in
some applications — e.g. in breadth-first
recursion and the branch and bound method
for function optimization.
IMPLEMENTATION ISSUES
2. Explicit Stack
- This approach is also the standard solution
in programming languages that do not
provide support for recursive procedures.
IMPLEMENTATION ISSUES
3. Stack Size
- In recursive implementations of D&C
algorithms, one must make sure that there is
sufficient memory allocated for the recursion
stack, otherwise the execution may fail
because of stack overflow.- Fortunately, D&C algorithms that are time-
efficient often have relatively small recursion
depth.- Stack overflow may be difficult to avoid
when using recursive procedures, since
many compilers assume that the recursion
stack is a contiguous area of memory, and
IMPLEMENTATION ISSUES
3. Stack Size
- Compilers may also save more information
in the recursion stack than is strictly
necessary, such as return address,
unchanging parameters, and the internal
variables of the procedure.- Thus, the risk of stack overflow can be
reduced by minimizing the parameters and
internal variables of the recursive procedure,
and/or by using an explicit stack structure.
IMPLEMENTATION ISSUES
4. Sharing repeated subproblems
- For some problems, the branched recursion
may end up evaluating the same sub-
problem many times over. In such cases it
may be worth identifying and saving the
solutions to these overlapping subproblems,
a technique commonly known
as memoization.
- Followed to the limit, it leads to bottom-
up divide-and-conquer algorithms such
as dynamic programming and chart parsing.

Data Structure and Algorithm - Divide and Conquer

  • 1.
    Presented by: FOR-IAN V.SANDOVAL 15-319-030 DIVIDE AND CONQUER ALGORITHM
  • 2.
    DIVIDE AND CONQUER ALGORITHM-D&C - an algorithm design paradigm based on multi-branched recursion - works by recursively breaking down a problem into two or more sub-problems of the same (or related) type (divide), until these become simple enough to be solved directly (conquer)- the solutions to the sub-problems are then combined to give a solution to the original problem
  • 3.
    DIVIDE AND CONQUER ALGORITHM-Both merge sort and quicksort employ a common algorithmic paradigm based on recursion.- Divide-and-conquer solves subproblems recursively, each subproblem must be smaller than the original problem, and there must be a base case for subproblems.
  • 4.
    PARTS OF DIVIDEAND CONQUER 1. Divide the problem into a number of subproblems that are smaller instances of the same problem. 2. Conquer the subproblems by solving them recursively. If they are small enough, solve the subproblems as base cases.3. Combine the solutions to the subproblems into the solution for the original problem.
  • 5.
  • 6.
  • 7.
    D&C TECHNIQUE - basisof efficient algorithms for all kinds of problems 1. sorting (e.g., quicksort, merge sort)2. multiplying large numbers (e.g. Karatsuba)3. syntactic analysis (e.g., top-down parsers) 4. computing the discrete Fourier transform (FFTs)
  • 8.
    D&C SKILL - complexskill that requires a good understanding of the nature of the underlying problem to be solved - as when proving a theorem by induction, it is often necessary to replace the original problem with a more general or complicated problem in order to initialize the recursion- there is no systematic method for finding the proper generalization
  • 9.
    ADVANTAGES 1. Solving difficultproblem - divide and conquer is a powerful tool for solving conceptually difficult problems: all it requires is a way of breaking the problem into sub- problems, of solving the trivial cases and of combining sub-problems to the original problem. - similarly, decrease and conquer only requires reducing the problem to a single smaller problem
  • 10.
    ADVANTAGES 2. Algorithm efficiency -the divide-and-conquer paradigm often helps in the discovery of efficient algorithms- it was the key, for example, to Karatsuba's fast multiplication method, the quicksort and mergesort algorithms, the Strassen algorithm for matrix multiplication, and fast Fourier transforms.
  • 11.
    ADVANTAGES 3. Parallelism - divideand conquer algorithms are naturally adapted for execution in multi- processor machines, especially shared- memory systems where the communication of data between processors does not need to be planned in advance, because distinct sub- problems can be executed on different processors.
  • 12.
    ADVANTAGES 4. Memory Access -Divide-and-conquer algorithms naturally tend to make efficient use of memory caches.- The reason is that once a sub-problem is small enough, it and all its sub-problems can, in principle, be solved within the cache, without accessing the slower main memory. - An algorithm designed to exploit the cache in this way is called cache-oblivious, because it does not contain the cache size(s) as an explicit parameter.
  • 13.
    ADVANTAGES 4. Memory Access -Moreover, D&C algorithms can be designed for important algorithms (e.g., sorting, FFTs, and matrix multiplication) to be optimal cache-oblivious algorithms–they use the cache in a probably optimal way, in an asymptotic sense, regardless of the cache size.
  • 14.
    ADVANTAGES 5. Round offControl - In computations with rounded arithmetic, e.g. with floating point numbers, a divide- and-conquer algorithm may yield more accurate results than a superficially equivalent iterative method.
  • 15.
    IMPLEMENTATION ISSUES 1. Recursion -Divide-and-conquer algorithms are naturally implemented as recursive procedures. - In that case, the partial sub-problems leading to the one currently being solved are automatically stored in the procedure call stack.- A recursive function is a function that is defined in terms of itself.
  • 16.
    IMPLEMENTATION ISSUES 2. ExplicitStack - Divide and conquer algorithms can also be implemented by a non-recursive program that stores the partial sub-problems in some explicit data structure, such as a stack, queue, or priority queue.- This approach allows more freedom in the choice of the sub-problem that is to be solved next, a feature that is important in some applications — e.g. in breadth-first recursion and the branch and bound method for function optimization.
  • 17.
    IMPLEMENTATION ISSUES 2. ExplicitStack - This approach is also the standard solution in programming languages that do not provide support for recursive procedures.
  • 18.
    IMPLEMENTATION ISSUES 3. StackSize - In recursive implementations of D&C algorithms, one must make sure that there is sufficient memory allocated for the recursion stack, otherwise the execution may fail because of stack overflow.- Fortunately, D&C algorithms that are time- efficient often have relatively small recursion depth.- Stack overflow may be difficult to avoid when using recursive procedures, since many compilers assume that the recursion stack is a contiguous area of memory, and
  • 19.
    IMPLEMENTATION ISSUES 3. StackSize - Compilers may also save more information in the recursion stack than is strictly necessary, such as return address, unchanging parameters, and the internal variables of the procedure.- Thus, the risk of stack overflow can be reduced by minimizing the parameters and internal variables of the recursive procedure, and/or by using an explicit stack structure.
  • 20.
    IMPLEMENTATION ISSUES 4. Sharingrepeated subproblems - For some problems, the branched recursion may end up evaluating the same sub- problem many times over. In such cases it may be worth identifying and saving the solutions to these overlapping subproblems, a technique commonly known as memoization. - Followed to the limit, it leads to bottom- up divide-and-conquer algorithms such as dynamic programming and chart parsing.