算法分析大题.pdfVIP

  • 7
  • 0
  • 约7.27千字
  • 约 13页
  • 2020-07-17 发布于江苏
  • 举报
1. 写出插入排序、合并排序伪代码,对插入排序进行最坏、最 好和平均情况下复杂度分析,写出合并排序的递归方程,并用递归 树方法和主方 对递归方程求解。Write the running time of the Merge sort with recurrences. Solve the recurrences with recursion-tree method. 写的运行时间归并排序有复发。解决复发与递归树的方 法。 算法描述 3 分 The best-case running time is T(n) = c n + c (n - 1) + c (n - 1) + c (n 1 2 4 5 - 1) + c (n - 1) 8 = (c + c + c + c + c )n - (c + c + c + c ). This running time can 1 2 4 5 8 2 4 5 8 be expressed as an + b for constants a and b that depend on the statement costs c ; it is thus a linear function of n. i 2 This worst-case running time can be expressed as an + bn + c for constants a, b, and c that again depend on the statement costs c ; it is thus i a quadratic function of n. 分析2分 算法描述 2 分 Θ(1) if n = 1 T(n) = 2T(n/2) + Θ(n) if n 1. 递归方程和求解 3 分 InsertionSort(A, n) { for i = 2 to n { key = A[i] j = i - 1; while (j 0) and (A[j] key) { A[j+1] = A[j] j = j - 1 } A[j+1] = key } } Θ(1) if n = 1 T(n) = 2T(n/2) + Θ(n) if n 1. 2.二 分 查 找 算 法以 及 复 杂 性 分 析 3. Do Exercise 4.1-6 on page 67 in CLRS. 4. 公 式 法求 T(n)=4T(n/2)+n T(n)=4T(n/2)+n2 T(n)=4T(n/2)+n3 P75 T(n) = 4T(n/2) + n a = 4, b = 2 ⇒ nlog a = n2;f (n) = n. b CASE 1:f (n) = O(n2 – ε) for ε = 1. ∴ T(n) = Θ(n2). T(n) = 4T(n/2) + n2 a = 4, b = 2 ⇒ nl

文档评论(0)

1亿VIP精品文档

相关文档