Skip to content

Instantly share code, notes, and snippets.

@gurlock
Last active August 17, 2017 18:54
Show Gist options
  • Save gurlock/3d5b56082c003582a56c55513d2ce88d to your computer and use it in GitHub Desktop.
Save gurlock/3d5b56082c003582a56c55513d2ce88d to your computer and use it in GitHub Desktop.
Benefits of efficiency in code

Week 00 Day 4

Complexity Analysis in the Real World

Def algorithm - The system or plan you use to arrive at a solution

  • As the size of the problem gets bigger, the cost might grow quickly/slowly/not at all.
  • Time complexity - Mathematical comparison between different plans, or algorithm.
  • Cheat sheet- bigocheatsheet.com - An approximation of time complexity, describes worst-case performance for large n.

Approaches to complexity

Name | Big-O Notation | Operations for n items | Approach | Example ---|--- Constant | O(1) | 1 | Compare first & last numbers | Array lookup, hash table insertion Logarithmic | O(log n) | 1 | Def | Def Linear | O(n) | 2n | Find largest & smallest numbers | Finding index of an element in an array Quadratic | O(n^2) | n^2 | Constant time operation inside two nested for-loops. Exponential | O(c^n) | n^2 | Def | Guessing an n-character long password

Examples

  • Array-lookup - Complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment