Logo Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

More Big Oh Fallacies and Pitfalls

The purpose of this section is to dispel some common misconceptions about big oh. The next fallacy is related to the selection of the constants c and tex2html_wrap_inline58064 used to show a big oh relation.

Fallacy  Consider non-negative functions f(n), tex2html_wrap_inline58718, and tex2html_wrap_inline58264, such that tex2html_wrap_inline58722. Since tex2html_wrap_inline58724 for all integers tex2html_wrap_inline58076 if tex2html_wrap_inline58728, then by Definition gif tex2html_wrap_inline58730.

This fallacy often results from the following line of reasoning: Consider the function tex2html_wrap_inline58732. Let tex2html_wrap_inline58734 and tex2html_wrap_inline58562. Then f(n) must be O(n), since tex2html_wrap_inline58742 for all tex2html_wrap_inline58098. However, this line of reasoning is false because according to Definition gif, c must be a positive constant, not a function of n.

The next fallacy involves a misunderstanding of the notion of the asymptotic upper bound.

Fallacy  Given non-negative functions tex2html_wrap_inline58254, tex2html_wrap_inline58256, tex2html_wrap_inline58718, and tex2html_wrap_inline58264, such that tex2html_wrap_inline58250, tex2html_wrap_inline58252, and for all integers tex2html_wrap_inline58076, tex2html_wrap_inline58764, then tex2html_wrap_inline58766.

This fallacy arises from the following line of reasoning. Consider the function tex2html_wrap_inline58768 and tex2html_wrap_inline58770. Since tex2html_wrap_inline58772 for all values of tex2html_wrap_inline58556, we might be tempted to conclude that tex2html_wrap_inline58776. In fact, such a conclusion is erroneous. For example, consider tex2html_wrap_inline58198 and tex2html_wrap_inline58780. Clearly, the former is tex2html_wrap_inline58202 and the latter is tex2html_wrap_inline58514. Clearly too, tex2html_wrap_inline58786 for all values of tex2html_wrap_inline58076!

The previous fallacy essentially demonstrates that while we may know how the asymptotic upper bounds on two functions are related, we don't necessarily know, in general, the relative behavior of the two bounded functions.

This fallacy often arises in the comparison of the performance of algorithms. Suppose we are comparing two algorithms, A and B, to solve a given problem and we have determined that the running times of these algorithms are tex2html_wrap_inline58794 and tex2html_wrap_inline58796, respectively. Fallacy gif demonstrates that it is an error to conclude from the fact that tex2html_wrap_inline58798 for all tex2html_wrap_inline58076 that algorithm A will solve the problem faster than algorithm B for all problem sizes.

But what about any one specific problem size? Can we conclude that for a given problem size, say tex2html_wrap_inline58064, that algorithm A is faster than algorithm B? The next fallacy addresses this issue.

Fallacy  Given non-negative functions tex2html_wrap_inline58254, tex2html_wrap_inline58256, tex2html_wrap_inline58718, and tex2html_wrap_inline58264, such that tex2html_wrap_inline58250, tex2html_wrap_inline58252, and for all integers tex2html_wrap_inline58076, tex2html_wrap_inline58764, there exists an integer tex2html_wrap_inline58064 for which then tex2html_wrap_inline58830.

This fallacy arises from a similar line of reasoning as the preceding one. Consider the function tex2html_wrap_inline58768 and tex2html_wrap_inline58770. Since tex2html_wrap_inline58772 for all values of tex2html_wrap_inline58556, we might be tempted to conclude that there exists a value tex2html_wrap_inline58064 for which tex2html_wrap_inline58842. Such a conclusion is erroneous. For example, consider tex2html_wrap_inline58844 and tex2html_wrap_inline58846. Clearly, the former is tex2html_wrap_inline58202 and the latter is tex2html_wrap_inline58514. Clearly too, since tex2html_wrap_inline58786 for all values of tex2html_wrap_inline58076, there does not exist any value tex2html_wrap_inline58856 for which tex2html_wrap_inline58842.

The final fallacy shows that not all functions are commensurate :

Fallacy  Given two non-negative functions f(n) and g(n) then either f(n)=O(g(n)) or g(n)=O(f(n)).

This fallacy arises from thinking that the relation tex2html_wrap_inline57196 is like tex2html_wrap_inline58870 and can be used to compare any two functions. However, not all functions are commensurate.gif Consider the following functions:

eqnarray1701

Clearly, there does not exist a constant c for which tex2html_wrap_inline58100 for any even integer n, since the g(n) is zero and f(n) is not. Conversely, there does not exist a constant c for which tex2html_wrap_inline58892 for any odd integer n, since the f(n) is zero and g(n) is not. Hence, neither f(n)=O(g(n)) nor g(n)=O(f(n)) is true.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.