- 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
您可能关注的文档
最近下载
- 三国杀卡牌(全套精装+限量版).pdf VIP
- 22HM001-1 海绵城市建设设计示例(一)上.pdf VIP
- 2026人教版小学数学六年级下册期末考试精选3套试卷(含答案解析).docx
- 2025年中考英语时文阅读 20(学生版+解析版).docx
- 2025年江苏专转本《财经综合基础理论(财会基础)》精编讲义复习备考必备资料.pdf VIP
- G60沪昆高速(浙江段)出入口、服务区、里程数及风景点.docx
- 高考历史蓝皮书 挖掘隐含前提.pptx VIP
- 高考文言文逆袭指南:吃透150词+6大招.docx VIP
- DB1310_T 369-2025 化学分析实验室玻璃仪器使用规.docx VIP
- 款 MAZDA(马自达)3 轿车用户使用手册.pdf VIP
原创力文档

文档评论(0)