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:
- Initialization: It is true prior to the first iteration of the 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 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:
- Divide the problem into a number of subproblems that are smaller instances of the same problem.
- Conquer the subproblems by solving them recursively. If the subproblem sizes are small enough, however, just solve the subproblems in a straightforward manner.
- 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.
In the equation , T(n) is the running time on a problem of size n. When the size is small enough , n≤c , 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”.