Another method that can often be used to find Big O is to look at the ratio of times as the size of input is doubled. Ratios that are approximately powers of 2 are easily recognized:
Ratio | Big O |
2 | n |
2+ | n * log(n) ? |
4 | n2 |
8 | n3 |
Example:
n | Time | Ratio |
4000 | 0.01779 | |
8000 | 0.06901 | 3.8785 |
16000 | 0.27598 | 3.9991 |
32000 | 1.10892 | 4.0180 |
64000 | 4.44222 | 4.0059 |
Since the ratio is about 4, this function is O(n2).
Contents    Page-10    Prev    Next    Page+10    Index