Download presentation

Presentation is loading. Please wait.

Published byDaisy Freestone Modified about 1 year ago

1
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
A classic example: Counterfeit coin You have 9 coins, in which one is counterfeit (being lighter) You have only one balance. How can you find the counterfeit dollar?

3
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 1 st or the 2 nd is counterfeit 1 weighing. Worst case: The 9 th is counterfeit 8 weighing.

4
R < G G < R G=R Separate the 9 coins into 3 groups, each with 3 coins. Weigh 2 groups: Repeat the same process for the suspicious group.

5
Best case? Worst case? Divide and Conquer usually gives us a faster approach to the problem, that ’ s why it is useful. Many well known algorithms make use of D&C to formulate. However, please be noted that D&C does not necessarily provide you the best algorithm to solve it. Shell sort, Merge sort, Quick sort, Binary Search, Interpolation Search, Cut Vertices, Cut Edges, etc …

6
Difficult problem Sub Task 1Sub Task 2Sub Task n … Recombination Sub Tasks must be simpler Solution readily known or obtained by D&C again. Sol n of Task 1Sol n of Task 2Sol n of Task n …

7
Some terms:TermsMeaningRemarkD&C Divide and Conquer Problem solving technique Simpler 1. Algorithm already known Reduced problem 2. Answer already known Base cases 3. Same problem, smaller in size Recursive approach Faster Faster in worst case Best and average cases are not our main concern

8
L-Block Filling You are given an n X n square board, in which one cell is marked. Find a way to cover the board with L blocks. n is a power of 2 n = 2 k

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?

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google