离散数学——Algorithm and Recurrence

Algorithm

Big-O

Definition of Big-O

image

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

image

There are rules for combination of Big-O

image

image

Definition of function type

image

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

image

Input size

image

image

Recurrence

First-order linear recurrence

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

image

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

Master Theorem

image

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

  1. When the function has 2 different roots

image

  1. When the function only has 1 root

image

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

image

image

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)\)

posted @ 2022-01-12 23:55  wcvanvan  阅读(281)  评论(0)    收藏  举报