Herramientas de usuario

Herramientas del sitio


wiki2:global

¡Esta es una revisión vieja del documento!


Interview Notes

Academic subjects

Complexity

  • O(1) — Constant Time
    Given an input of size n, it only takes a single step for the algorithm to accomplish the task.
  • O(log n) — Logarithmic time
    Given an input of size n, the number of steps it takes to accomplish the task are decreased by some factor with each step.
  • O(n) — Linear Time
    Given an input of size n, the number of of steps required is directly related (1 to 1)
  • O(n²) — Quadratic Time
    Given an input of size n, the number of steps it takes to accomplish a task is square of n.
  • O(C^n) — Exponential Time
    Given an input of size n, the number of steps it takes to accomplish a task is a constant to the n power (pretty large number).
let n = 16;
O (1) = 1 step "(awesome!)"
O (log n) = 4 steps  "(awesome!)" -- assumed base 2
O (n) = 16 steps "(pretty good!)"
O(n^2) = 256 steps "(uhh..we can work with this?)"
O(2^n) = 65,536 steps "(...)"

Constant example

function isFriend(name){ //similar to knowing the index in an Array 
  return friends[name]; 
};
isFriend('Mark') // returns True and only took one step
function add(num1,num2){ // I have two numbers, takes one step to return the value
 return num1 + num2
}

Logarithmic example

//You decrease the amount of work you have to do with each step
function thisOld(num, array){
  var midPoint = Math.floor( array.length /2 );
  if( array[midPoint] === num) return true;
  if( array[midPoint] < num ) --> only look at second half of the array
  if( array[midpoint] > num ) --> only look at first half of the array
  //recursively repeat until you arrive at your solution

}
thisOld(29, sortedAges)

Linear example

//The number of steps you take is directly correlated to the your input size
function addAges(array){
  var sum = 0;
  for (let i=0 ; i < array.length; i++){  //has to go through each value
    sum += array[i]
  }
 return sum;
}

Quadratic example

//The number of steps you take is your input size squared
function addedAges(array){
  var addedAge = [];
    for (let i=0 ; i < array.length; i++){ //has to go through each value
      for(let j=i+1 ; j < array.length ; j++){ //and go through them again
        addedAge.push(array[i] + array[j]);
      }
    }
  return addedAge;
}
addedAges(sortedAges);
//Nested for loops. If one for loop is linear time (n)
//Then two nested for loops are (n * n) or (n^2) Quadratic!

Exponential example

//The number of steps it takes to accomplish a task is a constant to the n power
//Thought example: Trying to find every combination of letters for a password of length n

Python

Generators

AsyncIO

Diseño de sistemas

We will have to take into account the next three elements:

  • External request from an external client (an HTTP request from a browser, etc).
  • Your code running in some container (a Django app running on mod_wsgi, a Python script listening to RabbitMQ, etc).
  • Pieces of infrastructure (MySQL, Redis, RabbitMQ, etc).

Scaling

Two types of scaling:

  • Vertical: You scale by adding more power (CPU, RAM) to your existing machine.
  • Horizontal: You scale by adding more machines into your pool of resources.

Load balancing pattern

A load balancer (software or hardware) is placed just after the request arrives to our servers. It chooses between workers which one will process the request.

  • HAProxy
  • NGINX
  • Traefik

Caching pattern

Precalculate results, pre-generate expensive indexes, and storing copies of frequently accessed data in a faster backend.

  • Memcache
  • Varnish
  • Cassandra
  • Redis

Distributed systems

Bases de datos

wiki2/global.1592748967.txt.gz · Última modificación: 2020/06/21 15:16 (editor externo)