Big O calculation

金秀·2022년 5월 11일
0

알고리즘

목록 보기
1/2

안하면 다시 헷갈리는 Big O 계산

How to calculate

    1. Worst case
      always care about the worst(not the best) case.
    1. Remove Constants

      while 문은 n의 절반만 체크함 (middleIndex)
      for loop 은 100까지만 돈다! (i<100)
      O(1+n/2+100 ) => O(n) drop the constant 1,2,100
    1. Different terms for inputs
      *** a lot of people make mistakes here!
      여기는 big O => O(n)인데 input 2개면 어떨까?
      boxes 와 boxes2 는 각기 다른 크기임! => O(a+b)
    1. Drop Non Dominants

      O(n + n^2) => O(n^2)

Case1

O(3+4n) => O(n)

Case 2

O(4+5n) => O(n)

profile
기록하기

0개의 댓글