【发布时间】:2017-02-13 11:06:09
【问题描述】:
hi 在书中读到,调用子程序被认为是一个恒定时间的操作,即使子程序本身并不以恒定时间执行,而是取决于输入大小。 然后,如果我有以下代码:
void func(int m){
int n = 10;
subrout(m);//function which complexity depends on m
subrout2(n);//function which complexity depends on n
}
我想我可以认为 func() 是一个常数时间函数,例如O(1)?
如果我有这个怎么办:
void func(){
int n = 10;
Type object;
object.member_method(n);/*member function which time complexity depends upon n*/
}
我还能认为 func() 是一个常数时间函数吗? 在某些情况下这条规则适用吗? 谢谢!
【问题讨论】:
标签: time-complexity complexity-theory asymptotic-complexity code-complexity