Divide and Conquer - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Divide and Conquer

Description:

Separate the 9 coins into 3 groups, each with 3 coins. Weigh 2 groups: ... You are given an n X n square board, in which one cell is marked. ... – PowerPoint PPT presentation

Number of Views:190
Avg rating:3.0/5.0
Slides: 11
Provided by: cockroa
Category:
Tags: conquer | divide | use

less

Transcript and Presenter's Notes

Title: Divide and Conquer


1
Divide and Conquer
What is divide and conquer?
Divide and conquer is a problem solving technique.
It does not imply any specific computing problems.
The idea is to divide a DIFFICULT task to SIMPLE
task(s).
Solve the simple task(s).
Combine the results of simple task(s) for the
original task.
2
Divide and Conquer
A classic example
How can you find the counterfeit dollar?
3
Divide and Conquer
Counterfeit dollar
MINDLESS approach
Grab the first one as control, test all others
with respect to the first one (i.e. the control).
Best case The 1st or the 2nd is counterfeit ? 1
weighing.
Worst case The 9th is counterfeit ? 8 weighing.
4
Divide and Conquer
Separate the 9 coins into 3 groups, each with 3
coins.
Weigh 2 groups
Repeat the same process for the suspicious group.
5
Divide and Conquer
Best case? Worst case?
Divide and Conquer usually gives us a faster
approach to the problem, thats why it is useful.
Many well known algorithms make use of DC to
formulate.
Shell sort, Merge sort, Quick sort, Binary
Search, Interpolation Search, Cut Vertices, Cut
Edges, etc
However, please be noted that DC does not
necessarily provide you the best algorithm to
solve it.
6
Divide and Conquer
Difficult problem
Sub Tasks must be simpler
Solution readily known or obtained by DC again.
Recombination
7
Divide and Conquer
Some terms
8
L-Block Filling
You are given an n X n square board, in which one
cell is marked.
n is a power of 2 ? n 2k
Find a way to cover the board with L blocks.
9
L-block filling
4 smaller sub-problems
10
L-block filling
What is the base case?
It is very important to know that for any
recursive approach, there must be a base case!
An equally important note is that the way you
design your recursion should gradually progress
to your base case (s).
Function Hello(n integer) Integer Begin
If n 1 Then Hello n Else
Hello Hello(n-2) End
What is the problem of this recursion?
Write a Comment
User Comments (0)
About PowerShow.com