W2232 Big-O Notation

From Coder Merlin
Jump to navigation Jump to search



Big-O Notation[edit]

Big-O Notation is used to describe the performance of an algorithm and establishes a worst-case run time. It calculates the number of operations performed and the memory required for an algorithm to conclude. There are different formulas to calculate the operations performed and memory requirements for each sorting algorithm. Big-O Notation is unable to tell you how long an algorithm will run because there are too many factors that influence the time an algorithm takes to run.

Common Formulas[edit]

O(log n) - Binary Search

O(n) - Simple Search/ Bubble Sort

O(n * log n) - Quicksort

O(n2) - Insertion Sort/Selection Sort

Growth Rate Name Description
O(1) Constant Statement
O(log(n)) Logarithmic Divide in half / Binary search
O(n) Linear Loop
O(n * log(n)) Linearithmic Effective sorting algorithm
O(n^2) Quadratic Nested loop
O(n^3) Cubic Triple-nested loop
O(xn) Example Exhaustive search

Big-O Notation can also be calculated by hand. You can go through each line of code and determine if it will be "1", "log(n)", n, etc. You can then add all of the growth rates together and it can be expressed as, for example, O(1+3n) where the "1" represents one line of O(1), and the "3n" represents 3 lines of O(n).

Coming Soon
  • Timing execution in Linux



Write an essay (minimum 500 words) which:

  • Defines Big-O
  • Compares and contrasts Big-O for:
    • Bubble-Sort
    • Selection Sort
    • Insertion Sort
    • Merge Sort
  • Based upon the above, which sort is most time-efficient for the average case?

Complete your essay in your Journal directory and push to GitHub.


Big-O Notation for Beginners (AdrianMejia)

Big-O Notation (Wikipedia)

Designed with pride in Silicon Valley, CA, USA