Professional Documents
Culture Documents
Algorithm Design Approaches
Algorithm Design Approaches
2
Quick-sort
Merge-sort
Divide & Conquer - characteristics
# of stops minimization problem
S T
10
D&C Solution for F(6)
F(6)
F(5) F(4)
int fib(int n)
{ Computations are NOT repeated!
int f[n+1];
f[1] = 1;
f[2] = 2;
for (i=3 ; i<= n ; i++)
f[i] = f[i-1]+f[i-2];
return f[n];
}
F(1) F(2) F(3) F(4) F(5) F(6)
12
Knapsack problem
• Individual pieces with specific weights, thief
wants to know whether there is an exact
match for his weight limit.
Dynamic programming - characteristics