Big O when adding together different routines

后端 未结 4 919
青春惊慌失措
青春惊慌失措 2020-11-29 12:28

Lets say I have a routine that scans an entire list of n items 3 times, does a sort based on the size, and then bsearches that sorted list n times. The scans are O(n) time,

4条回答
  •  心在旅途
    2020-11-29 13:14

    Yes it will just be the worst case since O-notation is just about asymptotic performance.

    This should of course not be taken to mean that adding these extra steps will have no effect on your programs performance. One of the O(n) steps could easily consume a huge portion of your execution time for the given range of n where your program operates.

提交回复
热议问题