Page 210 Page 226 Page 249 Page 162
- Slides: 79
主讲部分 • • Page 210 Page 226 Page 249 Page 162 Page 177 Page 182 Page 330 Page 593 15. 1 -1(DP) 15. 4 -1, 15. 4 -2, 15. 4 -5; (LCS) 16. 3 -1; (Huffman) 12. 1 -1, 12. 1 -2, 12. 1 -3; (BST) 13. 2 -2; (RB-Tree) 13. 3 -1, 13. 3 -2; (RB-Tree) 21. 3 -2; (disjoint-set) 32. 4 -1, 32. 4 -2, 32. 4 -6, 32. 4 -7; (KMP) 2021/10/24 2
Page 210 15. 1 -1 • 2021/10/24 3
Page 226 15. 4 -1 。求<1, 0, 0, 1, 0, 1>和<0, 1, 1, 0>的一个LCS Ø LCS:<1, 0, 0, 1, 1, 0> <0, 1, 0, 1> 2021/10/24 4
Page 226 15. 4 -2 。设计伪代码,利用完整的表c及原始序列X = <x 1, x 2, …, xm>和 Y=<y 1, y 2, …, yn>重构LCS,要求运行时间为O(m+n), 不能使用表b。 解: 1. PRINT-LCS(c, X, Y, i, j) 2. if i == 0 or j == 0 3. return 4. if X[i] == Y[j] 5. PRINT-LCS(c, X, Y, i-1, j-1) 6. print X[i] 7. else if c[i-1, j] >= c[i, j-1] 8. PRINT-LCS(c, X, Y, i-1, j) 9. else 10. PRINT-LCS(c, X, Y, i, j-1) 2021/10/24 5
Page 226 15. 4 -2 。设计伪代码,利用完整的表c及原始序列X = <x 1, x 2, …, xm>和 Y=<y 1, y 2, …, yn>重构LCS,要求运行时间为O(m+n), 不能使用表b。 解: 1. PRINT-LCS(c, X, i, j) 2. if i == 0 or j == 0 3. return 4. if c[i-1, j-1] == c[i, j] - 1 5. PRINT-LCS(c, X, i-1, j-1) 6. print X[i] 7. else if c[i-1, j] == c[i, j] 8. PRINT-LCS(c, X, i-1, j) 9. else 10. PRINT-LCS(c, X, i, j-1) 2021/10/24 举例:X = 0 1 1 0 Y=1001 c[8, 3] = 3 即 1 0 0 c[9, 4] = 4 即 1 0 0 1 c[9, 4] – 1 = c[9 -1, 4 -1] = c[8, 3] = 3 但X[9]的‘ 0’并不是LCS的构成元素 6
Page 226 15. 4 -5 • 2021/10/24 7
Page 226 15. 4 -5 • 2021/10/24 8
Page 249 16. 3 -1 。解释:在引理16. 2的证明中,为什么若x. freq = b. freq, • • 则有a. freq = b. freq = x. freq = y. freq。 引理16. 2提供的条件:a. freq <= b. freq and x. freq <= y. freq x. freq <= a. freq and y. freq <= b. freq 推导出: x. freq <= a. freq <= b. freq x. freq <= y. freq <= b. freq 当 x. freq = b. freq, a. freq = b. freq = x. freq = y. freq 2021/10/24 9
Page 162 12. 1 -3 。设计执行二叉搜索树中序遍历的非递归算法。 1. INORDER-TREE-WALK(T) 2. Initialize an empty stack s. 3. temp = T 4. while(!s. empty() or temp != NULL){ 5. while(temp != NULL){ 6. s. push(temp) 7. temp = temp. left 8. } 9. temp = s. pop() 10. print temp. val 11. temp = temp. right 12. } 2021/10/24 11
Page 330 21. 3 -2 • 方法 1:循环更新 • 方法 2:使用stack 1. 2. 3. 4. 5. 6. 7. 8. 9. FIND-SET(x) root = x while(root != root. p) root = root. p while(x != root) temp = x. p = root x = temp return root 1. FIND-SET(x) 2. Initialize an empty stack s. 3. while(x != x. p) 4. s. push(x) 5. x = x. p 6. while(!s. empty()) 7. y = s. pop() 8. y. p = x 9. return x 常见错误: 1. FIND-SET(x) 2. . 3. while(x != root) 4. x. p = root 5. x = x. p 6. return root 2021/10/24 15
Page 593 32. 4 -1 • i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 P[i a ] b a b a b b 0 0 1 2 3 4 5 2021/10/24 16
Page 593 32. 4 -2 • 2021/10/24 17
Page 593 32. 4 -7 • 2021/10/24 18
主讲部分 • • Page 124 Page 231 Page 244 Page 535 Page 187 Page 587 9. 3 -5; 15. 5 -2 16. 2 -3 30. 2 -2 13. 4 -3 32. 3 -1 32. 3 -2 2021/10/24 20
Page 231 15. 5 -2 • 解: w e i, j 0 1 2 3 4 5 6 7 1 0. 06 0. 28 0. 62 1. 03 1. 34 1. 83 2. 44 3. 12 1 0. 06 0. 16 0. 28 0. 42 0. 49 0. 64 0. 81 1. 00 0. 06 0. 30 0. 68 0. 93 1. 41 1. 96 2. 65 2 0. 06 0. 18 0. 32 0. 39 0. 54 0. 71 0. 90 0. 06 0. 32 0. 57 1. 04 1. 48 2. 13 3 0. 06 0. 20 0. 27 0. 42 0. 59 0. 78 0. 06 0. 24 0. 57 1. 01 1. 55 4 0. 06 0. 13 0. 28 0. 45 0. 64 0. 05 0. 30 0. 72 1. 20 5 0. 05 0. 20 0. 37 0. 56 0. 05 0. 32 0. 78 6 0. 05 0. 22 0. 41 0. 05 0. 34 7 0. 05 0. 24 0. 05 8 2 3 4 5 6 7 8 2021/10/24 0. 05 22
Page 244 16. 2 -3 • 2021/10/24 24
Page 535 30. 2 -2 • 解: 2021/10/24 25
Page 297 19. 2 -1 • 解: 斐波那契堆调用FIB-HEAP-EXTRACT-MIN后得到的斐波那契堆 2021/10/24 28
主讲部分-思考题 • • Page 53 Page 55 Page 112 Page 231 4. 4 -7, 4. 4 -8; 4. 5 -4; 8. 3 -4; 15 -2, 15 -5 2021/10/24 31
Page 53 4. 4 -7 • 2021/10/24 32
Page 53 4. 4 -8 • 2021/10/24 33
Page 112 8. 3 -4 • 2021/10/24 35
Page 231 15 -2 • string longest. Palindrome(string s) { if (s. empty()) return " "; int dp[s. size()] = {0}, left = 0, right = 0, len = 0; for (int j = 0; j < s. size(); ++j) { for (int i = 0; i < j; ++i) { dp[i][j] = (s[i] == s[j] && (j - i > 2 || dp[i + 1][j - 1])); if (dp[i][j] && len < j - i + 1) { len = j - i + 1; left = i; right = j; } } dp[j][j] = 1; } return s. substr(left, right - left + 1); } 2021/10/24 36
Page 231 15 -5 • 2021/10/24 37
Page 231 15 -5 • 解: 2021/10/24 38
主讲部分 • • Page 210 15. 1 -2; Page 222 15. 3 -1 15. 3 -2; Page 261 17. 1 -2; Page 262 17. 2 -1; Page 165 12. 2 -1; Page 168 12. 3 -2; Page 176 13. 1 -1 13. 1 -2; 2021/10/24 40
主讲部分 • Page 177 13. 2 -1; • Page 201 14. 3 -2 14. 3 -3; • Page 583 32. 2 -1 32. 2 -3; 2021/10/24 41
Page 222 15. 3 -1 • 2021/10/24 43
Page 222 15. 3 -1 • 2021/10/24 44
Page 222 15. 3 -1 • 2021/10/24 45
Page 261 17. 1 -2 • 2021/10/24 47
Page 176 13. 1 -1 • 红黑树的黑高为 2: 2021/10/24 51
Page 176 13. 1 -1 • 红黑树的黑高为 3: 2021/10/24 52
Page 176 13. 1 -1 • 红黑树的黑高为 4: 2021/10/24 53
Page 177 13. 2 -1 解:写出RIGHT-ROTATE的伪代码: RIGHT-ROTATE(T, x) y = x. left = y. right if y. right != T. nil y. right. p = x y. p = x. p if x. p == T. nil T. root = y elseif x == x. p. left 2021/10/24 x. p. left = y else x. p. right = y y. right =x x. p =y 56
Page 201 14. 3 -2 解:INTERVAL_SEARCH_NEW(T, i) x = T. root while x != T. nil and i does not overlap x. int if x. left != T. nil an d x. left. max > i. low x = x. left else x = x. right return x 2021/10/24 57
Page 201 14. 3 -3 解:INTERVAL_SEARCH_MIN(T, i) x = T. root while x != T. nil and i does not overlap x. int if x. left != T. nil an d x. left. max >= i. low x = x. left else x = x. right while x. left != T. nil and i overlap x. left x = x. left return x 2021/10/24 58
Page 583 32. 2 -1 解:共 3个伪命中点。 3 1 9 4 3 1 8 5 4 9 4 2 4 6 4 5 10 9 2021/10/24 3 5 2 8 3 9 1 7 9 9 2 3 5 59
主讲部分 • • • Page 123 9. 2 -3, Page 215 15. 2 -1 15. 2 -2 15. 2 -3 15. 2 -5, Page 264 17. 3 -1, Page 47 4. 2 -3, Page 531 30. 1 -2 , Page 196 14. 1 -1 14. 1 -3, Page 198 14. 2 -2, Page 328 21. 2 -2 21. 2 -3, Page 579 32. 1 -1 32. 1 -2 2021/10/24 62
Page 123 9. 2 -3 • 本题即用循环将递归具体展开,算法如下: • RANDOMIZED-SELECT(A, p, r, i) • while p < r do //p != r则不断用i修正p和r的位置 q = RANDOMIZED -PARTITION(A, p, r) k=q-p+1 if i <= k r=q else p=q+1 i=i–k return A[p] 2021/10/24 63
Page 215 15. 2 -1 最小乘法次数为 2010,最优链乘次序为(A 1 A 2)((A 3 A 4)(A 5 A 6)) 2021/10/24 65
Page 215 15. 2 -3 于是命题得证 2021/10/24 66
Page 215 15. 2 -5 l = 2 to n i = 1 to n-l+1 k = I to j-1 所以总查表次数等于 2021/10/24 67
Page 215 15. 2 -2 本题相当于要求大家会查s表,将其具体对应到最优解,算法如下: if i == j then Return Ai else Return MATRIX-CHAIN-MULTIPLY(A, s, i, s[i, j]) · MATRIX-CHAINMULTIPLY(A, s, s[i, j]+1, j) 2021/10/24 68
Page 531 30. 1 -1 • 按公式来,不多说: 2021/10/24 71
Page 531 30. 1 -2 2021/10/24 72
Page 196 14. 1 -1 • 算法即不断考察x. left+1和rank的关系决定下一步方向,具体步骤为: OS-SELECT(T: root, 10) OS-SELECT(T: root: left: right, 2) OS-SELECT(T: root: left: right: left: right, 1) 返回关键字为 20。 2021/10/24 73
- 210 210 210
- Ap 11 penurunan kuasa
- Ee 249
- Comp 249
- Circular susep 249
- Dm 249 del 2010
- How to convert y=a(x-h)^2+k into y=ax2+bx+c
- Artigo 249 cc
- Ee 249
- Linea 1503
- Comm 226
- Comm 226 quiz 1
- Maksud 231
- Psy 226
- 226 curepipe
- Cmpe226
- 162 ad
- Rle 162
- Prime factorization of 24
- Cs 162
- 6-1 work together p. 162 answers
- Lcm of 150 and 180
- Pb162
- Komulator
- Prime factorization of 144 using exponents
- Cs 162
- What is written on the three-line heading on a work sheet
- 6-1 work together p. 162
- Máximo común divisor de 126 y 162
- Cs 162
- 18/36 simplified
- Speed, velocity and acceleration quiz
- Abcdefghijklmnopqrstvwxyz
- 7 sınıf en'âm suresi 162. ayet
- 2 6 18 54 162 sequence
- Apsc 162
- Cs 162
- 1. 6-1 work together, p. 162
- Tutti i numeri composti
- Eso error 210
- Numeri divisibili per 62
- Beta decay of pb-210
- Sound is
- What is 140 000 000 in scientific notation
- Ist 210
- Tds 210
- Solidworks pdm 210
- Mth 210
- Normalization
- Rumus rasio trigonometri
- Un autobus recorre cada dia de la semana 210 kilometros
- Decomposer en produit de facteur premier
- Mism-210
- Nfc 33-210
- Barracuda web filter 410
- Ist 210 penn state
- 10 lusin kaos dibeli dengan harga rp180.000 per lusin
- Mth 210
- Phoenix union high school district 210
- Processist
- 211 miller indices
- Ist 210
- 210 000 in scientific notation
- Entity 210
- 93 000 in scientific notation
- Cable nfc 33-210
- 1-2/210
- Dfl 210 "loopdetect"
- Seorang pedagang membeli 2 kuintal beras dengan harga 840
- Pbnsp 210
- Ist 210
- Bme 210
- Nia 210 acuerdo de los términos del encargo de auditoría
- Ist 210
- Utnfrh
- Ffpm 210
- Revelation 210
- Jika a=210° maka
- 210/72
- 6000000/210