Introduction to Algorithm - Summary of Chapter 2(0) - Getting started

in place: it rearranges the numbers within the array A, with at most a constant number of them stored outside the array at any time.

three things about a loop invariant:

  1. Initialization: It is true prior to the first iteration of the loop.
  2. Maintenance: If it is true before an iteration of the loop, it remains true before the next iteration.
  3. Termination: When the loop terminates, the invariant gives us a useful property that helps show that the algorithm is correct.

Analyzing an algorithm: has come to mean predicting the resources that the algorithm requires.

input size: the number of items in the input.

running time : the number of primitive operations.

incremental approach: Keep a part result satisfying the problem requirement from beginning to end , and expanding it gradually to solve the problem.

recursive: to solve a given problem, they call themselves recursively one or more times to deal with closely related subproblems.

divide-and-conquer approach: they break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem.

The divide-and-conquer paradigm involves three steps at each level of the recursion:

  1. Divide the problem into a number of subproblems that are smaller instances of the same problem.
  2. Conquer the subproblems by solving them recursively. If the subproblem sizes are small enough, however, just solve the subproblems in a straightforward manner.
  3. Combine the solutions to the subproblems into the solution for the original problem.

Recurrence equation : describes the overall running time on a problem of size n in terms of the running time on smaller problem.

T(n)={Θ(1)aT(n/b)+D(n)+C(n)if(nc)otherwise

In the equation , T(n) is the running time on a problem of size n. When the size is small enough , nc , it takes constant time to solve it. Division of problem yields a subproblems and each of them is 1/b size of original problem. The division takes D(n) time ,the combination takes C(n) time.

Some of above content refere to “Introduction to Algorithm”.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值