丑数算法的大O(暴力法)

问题描述 投票:0回答:1

链接到问题: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是输出结果。但是,算法的结果不能成为Big O表示法的一部分吗?如果不能,则将其减少为c n对吗?其中c>结果。正确的证明方法是什么?

algorithm big-o proof
1个回答
0
投票

isUgly

© www.soinside.com 2019 - 2024. All rights reserved.