Big O

What is considered as good code?

  1. Readability - the code is clean and others can understand your code easily

  2. Scalability - Scalable code, measured in big O. It means as the input grow bigger, how much does the algorithm slow down. The less it slows down, the better it is. So, to measure the efficiency of our function, we can just calculate how many operations a computer has to perform because each operation takes time on the computer

Examples of big O notation:

  1. O(1) or constant time, meaning the number of operation is not dependent on how large the input is

  2. O(n) or linear time, meaning as the inputs increase, the number of operations increase linearly. Example is "for-loop"

  3. O(n^2). Example is nested loop

  4. O(2^n). Example is Fibonacci calculation in recursion

  5. O(n log(n) - compare and search and O(log (n)) - binary search

Last updated