Skip to content

Instantly share code, notes, and snippets.

@mepsrajput
Last active November 23, 2021 12:25
Show Gist options
  • Save mepsrajput/8551749da8aaf0f03629770f005bb4c3 to your computer and use it in GitHub Desktop.
Save mepsrajput/8551749da8aaf0f03629770f005bb4c3 to your computer and use it in GitHub Desktop.

DS Flow Chart

BIG-O Cheatsheet

BIG O'S

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

BIG-O Cheatsheet

Arrays

Pros:

  • Fast lookups
  • Fast push/pop
  • Ordered

Cons

  • Slow inserts
  • Slow deletes
  • Fixed size (if using static array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment