离散数学——Algorithm and Recurrence
Algorithm
Big-O
Definition of Big-O

These are some frequently used Big-O estimates for some functions

There are rules for combination of Big-O


Definition of function type

Under this definition, polynomials are of the same type, but a polynomial and a exponential aren't
N, NP, NPC, NP Hard
P(polynomial)问题:能在多项式时间内解决的问题
NP(non-deterministic polynomial)问题:能在多项式时间内验证答案的问题
P属于NP,能在多项式时间内解决,一定能在多项式时间验证
NP complete: NP complete 属于 NP,即可以在多项式时间内验证,且所有NP问题都可以归约到NP complete,NP complete是NP中最难的问题,能解决NP complete的算法就能解决所有NP
NP hard: NP hard不一定能在多项式时间内验证,NP hard与NP有交集,交集就是NP complete,所有NP都能归约到NP hard

Input size


Recurrence
First-order linear recurrence
First-order linear recurrence: 形如\(T(n) = f(n)T(n-1) + g(n)\)

解决First-order linear recurrence function,一步步往回推找到规律即可,最后用base case来替代掉T(n)
Master Theorem

Linear homogeneous relation
Linear homogeneous relation is of the form: \(a_n = c_1a_{n-1} + c_2a_{n-2} + ... + c_ka_{n-k}\)
The solution to \(a_n\) is of the form: \(r^n\)
Put the solutions of \(a_n, a_{n-1}, ...\) back to the linear homogeneous relation, and we get characteristic function
For characteristic function of degree 2, we have the following theorem
- When the function has 2 different roots

- When the function only has 1 root

Then put the condition we get on base case, then we can solve \(\alpha_1\) and \(\alpha_2\)
For characteristic function of more than 2 degree, we have the following theorem


Linear non-homogeneous recurrence relation
Linear non-homogeneous recurrence relation is of the form: \(a_n = c_1a_{n-1} + c_2a_{n-2} + ... + c_ka_{n-k} + f(n)\)
The solution to \(a_n\) is of the form \(a_n = r^n + p(n)\)
we can get \(r^n\) by ignoring the f(n) part, and use method in solving linear homogeneous recurrence relation
for \(p(n)\), we assume \(p(n) = cn + d\), and now we ignore the \(r^n\) part, and let \(a_n = p(n)\) to solve \(p(n)\)

浙公网安备 33010602011771号