/data-structures

Data structures and their operations as well as solving problems with data structures.

Primary LanguageJavaScript

This is a data structures and algorithims Reporitory.

It contains an overview of data structures such as Arrays, Objects,stacks and linkedlists and their basic operations.


Big O

Big O allows us to talk formally about how the runtime of an algorithm grows as the inputs grow.

Time Complexity

We say that an algorithm is O(f(n)) if the number of simple operations the computer has to do is eventally less than a constant times f(n), as n increases.

  • f(n) could be constant O(1)
  • f(n) could be linear O(n)
  • f(n) could be quadratic O(n2)
  • f(n) could be something entirely different! O(log n) , O(nlog n) ,

Time Complexity Rules

  1. Arithmetic operations are constant
  2. Variable assignment is constant.
  3. Accessing elements in an array(by index) or object(by key) is constant.
  4. In a loop, the complexity is the length of the loop times the complexity of whatever happens inside the loop.

Space Complexity

  • Auxiliary Space Complexity refers to the space required by the algorithm, not including the space taken up by the inputs.

Space Complexity Rules

  1. Most primitives(booleans,numbers,undefined,null) are constant space.
  2. Strings require O(n) space where n is the string length.
  3. Reference types are generally O(n), where n is the length for arrays or the number of keys for objects.

Big O complexity chart
Image courtesy of Web Dev Simplified