- The order(n, n2, lgn ...) of growth of the running time of an algorithm gives a simple characterization of the algorithm's efficiency,
and also allows us to compare the relative performance of algorithms
- input size n ➡️ infinite, full grown 일 때 faster?
- Asymptotic efficiency - how the running time increases with the size of the input in the limit
- Focus on what’s important by abstracting away low-order terms and constant factors
Notations
O-notation : upper bound
Ω-notation : lower bound
Θ-notation : tight (exact) bound
Teorem and Rule
o-notation
ω-notation
Example
➡️ Time complexity 문제 시 notation 적기!
Proposition
⭐️ Optimality of algorithm
- Each problem has inherent(내제된) complexity; that is some minimum amount of work required to solve it.
- Lower bound of problem : minimal number of operation needed to solve the problem
- When the worst-case time complexity of an algorithm matches lower bound of the problem, the algorithm is said to be optimal
- “Optimal” does not mean “the best known”; it algorithm means “the best possible”
Example
Hierarchy of Orders
Exercise in class
1. Big-Oh notation
O(g(n)) = { f(n) : for any positive constant c, there exists a constant n0 > 0 such that 0 ≤ f(n) ≤ c · g(n) for all n ≥ n0 }
For 5n2 = O(n3), find the value of n0 and c which satisfy the condition
➡️ (n0, c): (1, 5), (5, 1)
2. T / F
1) 5n2 = O(n3) : T
2) f(n)=O(g(n)) and O(g(n))=f(n) have same meaning : F
➡️ why? n2 = O(n3) = n3 = O(n2)
3) n2 + O(n) = O(n2) : T
4) 1/2n2 = Θ(n2) : T
5) 1/2n2 = o(n2) : F
⭐️ 6) f(n)+g(n)=Θ(min(f(n),g(n)) : F
⭐️ 7) f(n)=O(g(n)) implies lg(f(n))=O(lg(g(n))) : T
⭐️ 8) f(n)=O(g(n)) implies 2f(n)=O(2g(n)) : F
➡️ why? 2n=O(n), but 22n=O(2n)
⭐️ 9) f(n)=O((f(n))2) : F
➡️ why? f(n)=1/n, but f(n)2=1/n2
10) f(n)=O(g(n)) implies g(n)=Ω(f(n)) : T
⭐️ 11) f(n)=Θ(f(n/2)) : F
➡️ why? f(n)=22n=Θ(2n)
12) f(n)+o(f(n))=Θ(f(n)) : T
3. Asymptotic relationship
Select all that apply.
1) lgn = O(log8n)
2) lgn = Ω(log8n)
3) lgn = Θ(log8n)
➡️ All true
4. Is 22n=O(2n)?
No, 2n⋅2n=22n≤c2n를 만족하는 n0 과 c가 존재하지 않음
HGU 전산전자공학부 용환기 교수님의 23-1 알고리듬 분석 수업을 듣고 작성한 포스트이며, 첨부한 모든 사진은 교수님 수업 PPT의 사진 원본에 필기를 한 수정본입니다.