Rough estimate of running time from Big O

后端 未结 4 1523
余生分开走
余生分开走 2020-12-21 16:12

If the time complexity of my program is,say O(n^2),How do I express running time in terms of seconds for a large value of

4条回答
  •  死守一世寂寞
    2020-12-21 16:49

    You need to roughly know how much one of your base tasks takes in order to have an estimation of the running task for different Algorithms.

    As an example, let's imagine your base task is

    void func(){sleep(1)};
    

    now you know that a O(1) complexity algorithm will yield to just one call to func(), which will take 1s.

    Looking at other examples:

    O(1) -> 1 * 1s
    O(N) -> N * 1s
    O(N2) -> (N^2) * 1s
    

    Without having a rough estimation of your task's execution time, it is impossible to give a precise answer.

提交回复
热议问题