算法分析之基本公理

(Algorithm Analysis -- the base axiom)
算法分析包括许多方面,最重要的是“ determine the running time of a program as a function of its inputs ”,即“时间复杂度”,它与输入有关。此外,算法分析的时候,还需要忽略硬件和操作系统的影响,为此,我们引入了“model”(模型)。按我的理解,所谓模式就是对时间的抽象,它不计算绝对时间,而是计算一些抽象意义的时间,比如Tfecth、Tstore、Tcall等。而模型是基于一些基本的公理,这些公理包括:
Axiom    The time required to fetch an operand from memory is a constant,  tex2html_wrap_inline57411 , and the time required to store a result in memory is a constant,  tex2html_wrap_inline57413 .
公理一:从内存中取操作数的时间是恒定的(Tfetch),将结果存储到内存中的时间也是恒定的(Tstore)。

Axiom    The times required to perform elementary arithmetic operations, such as addition, subtraction, multiplication, division, and comparison, are all constants. These times are denoted by  tex2html_wrap_inline57423 tex2html_wrap_inline57425 tex2html_wrap_inline57427 tex2html_wrap_inline57429 , and  tex2html_wrap_inline57431 , respectively.
公理二:所有的基本算术运算的时间是恒定的,如加减乘除和比较。

Axiom    The time required to call a method is a constant,  tex2html_wrap_inline57435 , and the time required to return from a method is a constant,  tex2html_wrap_inline57437 .
公理三:函数调用和函数返回的时间是恒定的。
“  While the method call/return overhead may be rather large, nevertheless it entails a constant amount of work. ”这句话是说,尽管函数调用和返回的开销相当大,但时它是一个固定量值的工作。

Axiom    The time required to pass an argument to a method is the same as the time required to store a value in memory,  tex2html_wrap_inline57413 .
公理四:函数调用过程中的参数传递(实参到形参),它的时间开销与“将值存到内存中是相同的”。

综上,这四个公理揭示了算法模型中的几项基本操作,这几项基本操作的时间值都是常量。除了这些时间值为常量的基本操作外,还有一类时间值随输入不同而不同的操作。比如数组元素的个数不同,在数组中进行匹配搜索的所消耗的时间也不同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值