离散数学——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(n1)+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: an=c1an1+c2an2+...+ckank

The solution to an is of the form: rn

Put the solutions of an,an1,... 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 α1 and α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: an=c1an1+c2an2+...+ckank+f(n)

The solution to an is of the form an=rn+p(n)

we can get rn 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 rn part, and let an=p(n) to solve p(n)

posted @   wcvanvan  阅读(195)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示