php常用命令

來源:互聯網
上載者:User

標籤:algorithm   演算法   

    Once an algorithm is given for a problem anddecided to be correct, an important step is to determine how much in the way of resources,such as time or space, the algorithm will require.

    

    The important things to know are:

    1)It‘s very bad style to include constants or low-order terms inside a Big-Oh

    2)This means that in any analysis that ignore lower-order terms and constants.

    Example: Do not say T(N) = O(2N^2) or T(N) = O(N^2 + N);

             The correct form is T(N) = O(N^2).


   General Rules:

   Rule1: for loop:

   The running time of a for loop is at most the running time of the statements inside the for loop(including tests) times the number of iterations. 

   As an example, the following program fragment is O(N):

for(i=0; i<N; i++)       k++;
   Rule2:Nested for loop:

   Analyze these inside out. The total running time of a statement inside a group of nested loops is the running time of the statement multiplied by the product of the sizes of all the for loops.

   As an example, the following program fragment is O(N^2):

for(i=0; i<N; i++)    for(j=0; j<N; j++)        k++;
   Rule3:Consecutive Statements:

   These just add(which means that the maximum is the one that counts).

   As an example, the following program fragment, which has O(N) work followed by O(N^2) work, is also O(N^2):

for(i=0; i<N; i++)    A[i] = 0;for(i=0; i<N; i++)    for(j=0; j<N; j++)        A[i] += A[j]+i+j;

   Rule4:if/else:

   For the fragment

       if(Condition)

          S1

       else

          S2

   The running time of an if/else statement is never more than the running time of the test plus the larger of the running times of S1 and S2.

   Notices:

   A basic strategy of analyzing from the inside(or deepest part) our works.

   If there are function calls, these must be analyzed first.


Reference:

Data Structures and Algorithm Analysis in C .Second Edtion


Than you for reading!

                 --By lzq at NanYang May.26.2014

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.