美文网首页
大O算法

大O算法

作者: ios小喽喽 | 来源:发表于2020-09-30 15:58 被阅读0次

    算法的特点:

                                    正确性、可读性、健壮性、时间效率高和存储量低

    大O表示法的规则:    

                                                        1、用常量1取代运行时间中所有常量

                                                        2、在修改运行函数次数中,只保留最高阶

                                                        3、如果最高阶存在且不等于1,则去除这个项目相乘的常数

    时间复杂度术语:

                        常数阶:O(1)

                            void testSum(int n){

                                        intsum =0;

                                            sum = (1+ n) * n/2;

                                                printf("testSum:%d",sum);}

                        线性阶:O(n)

                                            void LinearOrder(int n){

                                                                intsum =0;

                                                                    for(NSIntegeri =0; i < n; i++) {

                                                                            sum += i;

                                                                            }

                                                                            printf("sum:%d",sum);

                                                                            }

                       对数价:O(Log n)

                                void logarithmicOrder(int n){

                                                intcount =1;

                                                  while(count < n) {

                                                    count = count *2;    

                                                        printf("********%d",count);

                                                        }

                                                }

                        平方阶:O( 时间复杂度图

    相关文章

      网友评论

          本文标题:大O算法

          本文链接:https://www.haomeiwen.com/subject/nyjuuktx.html