Computer scienceAlgorithms and Data StructuresIntro to algorithms and data structuresUnderstanding algorithms and complexity analysis

Comparing algorithms with big O

Arrange time complexities

Report a typo

Arrange the time complexity estimates of an algorithm from faster to slower. The fastest algorithm should be at the top.

Tip: When comparing time complexities, it is important to consider the growth rates as the input size approaches infinity. This is called asymptotic analysis. While it may be tempting to compare the running times for specific values of nn, this can sometimes lead to misleading conclusions. For example, there may arise some confusion between O(3n)O(3^n) and O(n4)O(n^4) depending on the value you use to test.

Instead, focus on the highest order term that contributes the most to the growth rate. Keep in mind that time complexity provides an upper bound on the growth rate, and exceptions or edge cases with specific values of nn may not accurately represent the overall trend. So, analyze the dominant terms and consider how they scale for large input sizes to determine the relative speeds of algorithms.

Put the items in the correct order
O(n2/3)O(n^{2/3})
O(nn)O(n^n)
O(n4)O(n^4)
O(logn)O(\log n)
O(3n)O(3^n)
___

Create a free account to access the full topic