Section 9

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Arab

 Academy  for  Science  &Technology  and  Maritime  Transport  (AASTMT)  


College  of  Computing  and  Information  Technology  (CCIT)  
  Computing  Alg.  CS312  –  Spring  2014  
Dr.  Manal  Helal  
  Eng.  Mohamed  Moheeb  

  Section  
    9  –  May,  11,  2014  

 
 
 

Q1.      
xercises 8.2
a. Apply the bottom-up
a. Apply the bottom-up dynamic dynamic programming
programming algorithm
algorithm to to thefollowing
the following instance
instance of theofknapsack
the knapsack problem:
problem:
item weight value
1 3 $25
2 2 $20
capacity =6
3 1 $15
4 4 $40
5 5 $50  
b. How many different optimal subsets does the instance of part (a) have?
b. How many di erent optimal subsets does the instance of part (a) have?
c. In general, how can we use the table generated by the dynamic programming
c. In general,algorithm
how canto we tell whether
use thethere is more
table than one by
generated optimal
the subset for thepro-
dynamic knapsack
problem’s
gramming algorithm toinstance?
tell whether there is more than one optimal subset
for the knapsack problem’s instance?
Hint:  

a. Write pseudocode of the(8.6)—(8.7)


a. Use formulas bottom-up dynamic
to fill programming
in the appropriate table, as algorithm
is done for another
instance
for the knapsack of the problem in the section. 
problem.
b.—c. What would the equality of the two terms in
b. Write pseudocode of the algorithm that finds the composition of an
optimal subset from the table generated
max{F(i−1;j); by thei)}
vi +F(i−1;j−w bottom-up dynamic pro-
gramming algorithm for the knapsack problem.
mean?
For the bottom-up dynamic programming algorithm for the knapsack
problem, prove   that

a. its time e ciency is in ( )

b. its space e ciency is in ( ).

c. the time needed to find the composition of an optimal subset from


a filled dynamic programming table is in ( )
Q2.    

a.  Write pseudo code of the bottom-up dynamic programming algorithm for the
knapsack problem.

b. Write pseudo code of the algorithm that finds the composition of an optimal
subset from the table generated by the bottom-up dynamic programming algorithm
for the knapsack problem.

 
Hint:  
 

a.  Write pseudo code to fill the table in Fig. 8.4 (say, row by row) by using
formulas (8.6)—(8.7).

b.  An algorithm for identifying an optimal subset is outlined in the section via an
example.

You might also like