Professional Documents
Culture Documents
Assistant Professor
Computer Engineering
Department
• The base case for the recursion are subproblems of constant size.
Divide-and-Conquer
• Merge Sort
• Quick Sort
• Binary Search
• Max-Min Problem
• Exponential
• Tower of Hanoi
Divide-and-Conquer
When to use Divide and Conquer Approach?
• Both paradigms, Divide & Conquer and Dynamic Programming divide
the given problem into subproblems and solve subproblems.
• Divide and Conquer should be used when same subproblems are not
evaluated many times i.e. subproblems are non-overlapping.
• For example,
Divide and Conquer – Binary Search algorithm.
if ( n <= 1 )
return n;
• There are many subproblems which are solved again and again.
Recursive Fibonacci Series
• Recursive Tree:
Fib 5
Fib 4 Fib 3
Fib 1 Fib 0
Recursive Fibonacci Series
• Recursive Tree:
Fib 5
Fib 4 Fib 3
• (a + b ) (c + d ) = a c + (a d + b c) + b d,
• i.e., (a d + b c) = (a + b ) (c + d ) - a c - b d
if r – p ≤ 1 then
else
• Let T(n) be the number of comparisons made by Max−Min(p, r), where the
number of elements n= r − p + 1.
represented as
• So, T(n) = 2 * T( ) + 2
= 2 * (2 * T( ) + 2) ..... = − 2 = 1.5n – 2.
Multiplication of Large Integers
Analysis
of comparisons is less.
by O(n).
Any Questions?