Mark As Completed Discussion

Best vs. Worst Case Complexity

You may hear the term "worst case" being used when discussing complexities.

An algorithm can have two types of complexities. They are best case scenarios and worst case scenarios.

The best case complexity refers to the complexity of an algorithm in the ideal situation. For instance, if you want to search an item X in a list of N items-- the best case scenario is that we find the item at the first index, in which case the algorithm complexity will be O(1).

The worst case is that we find the item at the nth (or last) index, in which case the algorithm complexity would be be O(n) (where n is the total number of items in the list). When we use the term "algorithmic complexity", we generally refer to the worst case complexity. This is to ensure that we are optimizing for the least ideal situation.