【发布时间】:2023-06-13 16:02:01
【问题描述】:
问题链接:Ugly Numbers
你如何找到丑数的蛮力(简单方法)解决方案的大 O。
我看到这部分代码:
/* Function to check if a number is ugly or not */
int isUgly(int no)
{
no = maxDivide(no, 2);
no = maxDivide(no, 3);
no = maxDivide(no, 5);
return (no == 1)? 1 : 0;
}
每个步骤都需要log_2(x) + log_3(x) + log_5(x) 步骤,其中x = no
所以这意味着运行时间是 (log_2(x) + log_3(x) + log_5(x))n 其中 x 是输出的结果。但是,算法的结果不能是大 O 符号的一部分,对吧?如果不能,这将减少到 cn 对吗? c > 结果。什么是正确的证明方法?
【问题讨论】: