算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机制。也就是说,能够对一定规范的输入,在有限时间内获得所要求的输出。如果一个算法有缺陷,或不适合于某个问题,执行这个算法将不会解决这个问题。不同的算法可能用不同的时间、空间或效率来完成同样的任务。一个算法的优劣可以用空间复杂度与时间复杂度来衡量。
特征
一个算法应该具有以下五个重要的特征:
有穷性
(Finiteness)
算法的有穷性是指算法必须能在执行有限个步骤之后终止;
确切性
(Definiteness)
算法的每一步骤必须有确切的定义;
输入项
(Input)
一个算法有0个或多个输入,以刻画运算对象的初始情况,所谓0个输入是指算法本身定出了初始条件;
输出项
(Output)
一个算法有一个或多个输出,以反映对输入数据加工后的结果。没有输出的算法是毫无意义的;
可行性
(Effectiveness)
算法中执行的任何计算步骤都是可以被分解为基本的可执行的操作步,即每个计算步都可以在有限时间内完成(也称之为有效性)。
U2FsdGVkX18KTZQA2vrKmVh3Jm6PbqD5Baj9pbohxE6wY0+jwwJkW6xsZX2FZno5
h6QdlSTq9EtQSuC/UxUwrxfpyevS4gWGwcoVjy4vueCPGbRWUXQz6aYztPIiuXDY
TonI34M/YvHtLG4mjCbXF1qEPOej6pcKvhOn0Enbp5SNH5gbgtr9GlW7aQBUDmCK
PXh/R+AtDpq6VvO2xgNUOqU3mZFihgvCmWhTQKhDbIVHE86uckuzP9+/dNibKE6g
WAuReWcto3ysgV1SK9kp45KAki0h33jNTeKvdmgc2Sy/dIPzyxZGIB4Z7s2+ypxi
FrUueqzi5djqlow+MJ/6/OpLXmHffZ4b6VSe8l2lW+nUUVPpZLwpcn+R9WWhwf0N
4vklhRAZE8o7kNAwgGiKN2Bm3ncRyps9N5d3Ti11cdZWmZEXBBBaHOigypk2+by3
cvGl5QPKgm9ZoCVRoZCHm9wS1rCffvu6JGETGjcLg1LjeZZO806ZeN1JRJGOuSAr
C4OmRi8cIY1b9gvyz6IZi180jojRIo7vnvT2oeJ859gaFAQuniNzhFb4/GRWdL9E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