最新春季 - 算法导论课程
分析
loop-invariant
• A technique to prove that an algorithm is correct. Identify a loop-invariant.
• Initialization: It is true prior to the first iteration of a loop.
• 初始化:循环的第一次迭代之前,为真
• Maintenance: If it is true before an iteration of the loop, it remains true before the next iteration.
• 保持:如果循坏的某次迭代之前 为真,那么下次迭代之前它仍为真
• Termination: when the loop terminates, the invariant givesus a useful property that shows that the algorithm is correct.
• 终止:在循环终止时,不变式为我们提供一个有用的性质,该性质有助于证明算法的正确性。
RAM
-
We shall assume a generic one-processor, random-access machine (RAM) model of computation.
我们将假设一个通用的单处理器随机存取机(RAM)计算模型
-- Instructions are executed one after another, with no concurrent operations.
-- Each time, an instruction of a program is executed as an atom operation. An instruction includes arithmetic operations, logical operations, data movement and control operations.
-- Each such instruction takes a constant amount of time.
-- RAM capacity is large enough.
- 指令一个接一个地执行,没有并行操作。
- 每次,程序指令都作为原子操作执行。 一条指令包括算术运算,逻辑运算,数据移动和控制操作。
- 每个这样的指令都需要一定的时间。
- RAM容量足够大。
-
Under RAM model: count fundamental operations
在RAM模式下:统计基本操作
-
RAM 计算T(n)
T(n) 时间复杂度计算(练题)
顺序 — 串行
选择 — if 、switch-case
循环 — 插入排序
递归 — 归并排序
递归树 Recursion Tree