Skip to content

Instantly share code, notes, and snippets.

@cicconewk
Created February 1, 2022 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cicconewk/6fa339120a67f941306bae12807fe4d9 to your computer and use it in GitHub Desktop.
Save cicconewk/6fa339120a67f941306bae12807fe4d9 to your computer and use it in GitHub Desktop.

Big Os

Check out the original source at ZeroToMastery

O(1) Constant – no loops. O(log N) Logarithmic – usually searching algorithms have log n if they are sorted (Binary Search). O(n) Linear – for loops, while loops through n items. O(n log(n)) Log Linear – usually sorting operations. O(n^2) Quadratic – every element in a collection needs to be compared to ever other element. Two nested loops. O(2^n) Exponential – recursive algorithms that solves a problem of size N. O(n!) Factorial – you are adding a loop for every element.

Iterating through half a collection is still O(n) Two separate collections: O(a * b)

What Can Cause Time in a Function?

Operations (+, -, *, /) Comparisons (<, >, ==) Looping (for, while) Outside Function call (function())

Rule Book

Rule 1: Always worst Case Rule 2: Remove Constants Rule 3:

  • Different inputs should have different variables: O(a+b)
  • A and B arrays nested would be: O(a*b)
  • + for steps in order
  • * for nested steps

Rule 4: Drop Non-dominant terms

What Causes Space Complexity?

  • Variables
  • Data Structures
  • Function Call
  • Allocations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment