正确性证明
- Loop invariants
- Initialization
- Maintenance
- Termination
时间复杂度
- cost: 硬件执行一条指令的代价
- times: 指令被执行的次数
- running time
- 计算方法:
- worst-case running time
- average-case running time (按输入求期望)
- expected running time (任意输入,按程序随机数求期望)
rate(order) of growth
- (Stirling's approximation:
递归时间复杂度分析
- substitution method
- Guess the form of the solution
- Use mathematical induction to prove
- recursion-tree method
- node represents cost of single subproblem
- master method:
Probalistic analysis
- 平均/期望复杂度分析
- uniform random permutation
- permute-by-sorting
- permute-in-place
问题下界
- sort: decision-tree model
摊还分析
- amortized cost: average cost of each operation in the worst case
- aggregate analysis
- accounting method: assign amortized cost, credit nonnegative
- potential method: