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

来源:互联网 发布:单片机 型号 - 百度 编辑:程序博客网 时间:2024/05/17 01:49

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
原创粉丝点击