Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Gentle Introduction to Big O

A Gentle Introduction to Big O

It is common for coders to jump straight into writing code, without thinking about the best way to do things. Algorithm complexity is just a way to formally measure how fast a program or algorithm runs.

It is important to be aware, at least partially, of different algorithm complexities so you don’t end up accidentally writing code that take 10 times longer than necessary. This talk is designed to introduce you to algorithm complexity analysis, and the big O (pronounced “big oh”) notation.

Joe Karlsson

May 22, 2019
Tweet

More Decks by Joe Karlsson

Other Decks in Technology

Transcript

  1. @JoeKarlsson1 6 Measures how an app will scale when you

    increase the amount of things it operates on
  2. @JoeKarlsson1 9 Why should you care? •Two types of estimation

    in software •Machine independent •Covers all instances of a problem •Allows us to compare algorithms for a problem
  3. @JoeKarlsson1 13 •We are talking about really, really big numbers

    of elements •We are assuming worst case scenarios for algorithms •Big O can be really hard!
  4. @JoeKarlsson1 15 O(1): Constant Time No matter how large the

    input is, the time taken to run doesn’t change
  5. @JoeKarlsson1 26 O(n): Linear Time The larger the input, The

    longer it takes, in an even tradeoff.
  6. @JoeKarlsson1 27 O(n): Linear Time Every time you double the

    number of elements, the operation will take twice as long
  7. @JoeKarlsson1 46 O(2^n): Exponential Time The time taken will double

    with each additional element in the input data set
  8. @JoeKarlsson1 (logn) (1) (n log n) (n) (n2) (2n) 57

    Elements Time Big O Complexity Graph (n!)
  9. @JoeKarlsson1 59 How do I get better at Big O?

    • Figure out the run time as your write functions. • When reviewing PRs by other devs • Practice!
  10. @JoeKarlsson1 60 • Big O Notation allows us to compare

    algorithms for a problem • Big O Can be confusing
  11. @JoeKarlsson1 (logn) (1) (n log n) (n) (n2) (2n) 61

    Elements Time Big O Complexity Graph (n!)
  12. @JoeKarlsson1 64 Additional Resources • Plain English Explanation of Big

    O: • https://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o • Big O [Wikipedia]: • https://en.wikipedia.org/wiki/Big_O_notation • Big O Cheatsheet • http://bigocheatsheet.com/