Lecture7 Design Strategies Divide and Conquer and Greedy
Lecture7 Design Strategies Divide and Conquer and Greedy
11/24/2024 1
Design Strategies
Divide & Conquer
Greedy
Dynamic
Backtracking
Branch & Bound
11/24/2024 2
Divide & Conquer :
How to feed a mass of people ?
Greedy :
What to select from a collection of items ?
Dynamic
What options should I choose after S.4 ?
11/24/2024 4
Divide & Conquer :
11/24/2024 5
P
Divide
P1 P2 Pn
11/24/2024 6
If P: Problem
P What to solve?
P1 P2
What to
solve? P3
P2221 P2222
11/24/2024 7
Then the algorithm is
P1
P1 P1 P1
11/24/2024 8
This is strictly not called ‘DIVIDE & CONQUER’
11/24/2024 9
In Divide & Conquer
it is not the ‘PROBLEM’ which is divided ,
11/24/2024 10
DATA
Gr 1 Gr 2 Gr 3 Gr k
Solve by ‘specialized’ algorithm
suitable for each group
11/24/2024 11
One Specific Case
11/24/2024 12
For Instance :
Let us assume that there are two floors in a house
Ground Floor
First Floor
Let us assume each floor has two wings
Left Wing
Right Wing
Let us assume each wing has two rooms
Room 1
Room 2
Let us assume each room has two working tables
Table 1
Table 2
11/24/2024 13
I have misplaced my ‘mobile’ somewhere?
11/24/2024 14
SEARCH in the HOUSE
T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2
11/24/2024 15
SEARCH in the HOUSE
T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2 T1 T2
In this problem
Search Domain ( Data Space ) was divided more or less into two
equal halfs every time.
This is also a very specific case of dividing data into exactly 2 halves (Binary
Division) every time.
:
:
Has it become small enough ?
If yes, SOLVE
Start COMBINING local
solutions
11/24/2024 18
A general control abstract to illustrate Divide & Conquer
Procedure DC (nstart,nfinish)
{
if SMALL (nstart,nfinish)
then {SOLVE (nstart,nfinish)}
else
{
nmid (nstart+nfinish)/2
11/24/2024 20
Greedy Strategy
There are n number of candidates, and k number of seats.
S = s1 s2 s3 .. .. .. .. sk
Since k n SA
The approach to fill up ‘S’ is to maximize the objective called
MOST APPROPRIATE
An ambitious search through A will result in S.
11/24/2024 23
Greedy Strategy
Once the data is given in the greedy sequence then the solution is
obtained using - O algorithm
t ub n O(n)
11/24/2024 24
Greedy Strategy
Control abstract of greedy strategy based algorithm
11/24/2024 25
Example Knapsack Problem
Knapsack is a leather / Canvas bag used by a soldier
Consider a knapsack of capacity M.
Consider storing ‘n’ items(objects) into this knapsack
Object ‘i’ occupies wi of the knapsack if one full load of the object is
placed.
Instead if a part of the object(fraction) 0 xi 1 of the object is
placed then occupancy is wixi
If pi is the profit earned by placing the ith object, then the profit
earned by placing fraction xi of the object is pixi
Therefore objective function is
MAXIMIZE pixi 1in
Subject to wixi M and 0 xi 1 and 1 i n.
The profits and weights are positive numbers.
11/24/2024 26