Big-O complexity chart


Big-O : 입력값 변화에 따라 연산을 실행할 때, 연산 횟수에 비해 시간이 얼마만큼 걸리는가를 표기하는 방법

function algorithm(arr,index){
  let result = [];
  result.push(arr[index]);
  return result;
}

let arr = [0,1,2,3,4]

algorithm(arr,3);
// [3]
function algorithm(n){
  let result = [];

  for(let i = 0; i < n; i+=1){
    result.push(i)
  }
  return result;
}

algorithm(5);
// [0,1,2,3,4]
function algorithm(n){
  let result = [];
  for(let i = 0; i < n; i+=1){
    for(let j = 0; j < n; j+=1){
      result.push(j)
    }
  }
  return result;
}
algorithm(2);
// [0,1,0,1]
function fibonacci(n){
  if(n <= 1){
    return n;
  }
  return fibonacci(n-2) + fibonacci(n-1);
}