True or False
1-2
The root node of the optimal binary search tree must store the keyword with the highest search probability.
T F
1-3 When
using dynamic programming instead of recursive methods to solve problems, the key is to save the calculation results of the sub-problems so that each different sub-problem only needs to be calculated once. The solution of the subproblem can be stored in an array or hash table.
T F
Multiple choice
2-1
In dynamic programming, we need to derive the recurrence relationship between the solution of one sub-problem and the solutions of other sub-problems. To convert this relationship into a bottom-up dynamic programming algorithm, we need to fill in the sub-problem solution form in the correct order, so that when solving any sub-problem, all the sub-problems it needs have been solved. Which one of the following relations cannot be calculated?
AA (i, j) = min (A (i − 1, j), A (i, j − 1), A (i − 1, j − 1))
BA (i, j) = F (A (min {i, j} −1, min {i, j} −1), A (max {i, j} −1, max {i, j} −1))
CA (i, j) = F (A ( i, j − 1), A (i − 1, j − 1), A (i − 1, j + 1))
D.A(i,j)=F(A(i−2,j−2),A(i+2,j+2))
Draw a matrix and you will know it, and it can only be derived from the previously derived elements, namely the upper left and right elements;
2-2
Given the recurrence equation f i,j,k =f i,j+1,k + min0≤l≤k (f i−1,j,l +wj,l }. To solve this equation in a loop, we must not use which of the following methods to fill in the table?
A.for k in 0 to n: for i in 0 to n: for j in n to 0
B.for i in 0 to n: for j in 0 to n: for k in 0 to n
C.for i in 0 to n: for j in n to 0: for k in n to 0
D.for i in 0 to n: for j in n to 0: for k in 0 to n
2-3
Log cutting problem: Given a log with a length of N meters; there is also a segmented price list, giving the price PL corresponding to the length L=1,2,...,M. You are required to find the maximum profit RN that can be obtained by appropriately cutting logs and selling them in sections. For example, according to the price list given below, if you want to sell a log of 8 meters long, the optimal solution is to cut it into two segments of 2 meters and 6 meters, so that you can get the maximum profit R8 =P 2+P6=5+17=22. If you want to sell a 3 meter long log, the best solution is not to cut it at all and sell it directly.
Length L | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
Price PL | 1 | 5 | 8 | 9 | 10 | 17 | 17 | 20 | 23 | 28 |
Which of the following statements is wrong?
A. This problem can be solved by dynamic programming
B. If N≤M, then RN =max{PN ,max1≤i<N {Ri +RN− i }}
C. If N>M, then RN =max1≤i<N {Ri +RN−M}
D. The time complexity of the algorithm is O(N2)