前言*****
最近在看 data structures and algorithms in java,也准备把 算法导论 看一下
之下 和 本分类 将记录一些 数据结构 相关的问题
日后,将持续 完善/修正 本分类
正文*****
1.什么是 数据结构 和 算法:
a data structure is a systematic way of organizing and accessing data,
and an algorithm is a step-by-step procedure for performing some task in a finite amount of time
2.算法效率的考量
characterizing the running times of algorithms and data structure operations,
with space usage also being of interest
即是:时间复杂度 和 空间复杂度
2.1.时间复杂度
只是给人大致感觉
时间复杂度为O(n)的算法a的所耗费的时间 不一定比 O(n^2)的算法b的所耗费的时间 少
但是,一般情况下(如n很大时),小
请,仅和问题的规模n有关
时间 会随着 n的增大而xxx,和其他的因素无关
primitive operation:
如:赋值操作,这些操作,本身所耗费的时间能被计算(被认为是一个constant),
由它们所耗费的时间,最终得出 算法耗费的总时间
大Ο
我们通常用大O来表示 时间复杂度,如:算法的时间复杂度为g(n)
那么,f(n)是什么
它是另外一个多项式
如,对于算法
大致上要执行:
i=0时,1次a赋值,1次A[i]赋值,1次j赋值,1次j比较,1次a赋值
i=1时,1次a赋值,1次A[i]赋值,2次j赋值,2次j比较,2次a赋值
i=k时,1次a赋值,1次A[i]赋值,k次j赋值,k次j比较,k次a赋值
...
将上述时间相加,你会得出f(n)=...
而,我们也往往通过这种计算,得出时间复杂度
常见的时间复杂度排序(从小到大)
大Ω
大Θ