Big O notation

I’ll be using “big O” notation a lot to describe the efficiency of an algorithm, or some process that code is doing, so for all of you who don’t know big O notation here is a quick overview.

I’ll start with an example. You need to find an element in a list, the number you trying to find is 18. To find the number, or to check if it is even there, your going to have to iterate over the list until you find the number 18. In the worst case scenario you won’t find it until you reach the very last element in the list. That would be O(n).

- O  is used to express the worst case scenario.
- ( ) is where you tell how many steps it will take in the worst case scenario to accomplish your goal.
- n  is a common letter to use to signify the number of elements in the problem (in this case the number of “things” in our list)

So O(n) is essentially saying, in the worst case scenario it will take us the same number of steps to find the number 18 as there are items in the list.

Comments