Algorithmic Design Techniques

Algorithmic Analysis

Correctness proof

Efficiency

$f(n)$ is the true growth rate of complexity

Big-$O$ notation:

Big-$\Theta$ notation:

Big-$\Omega$ notation

截屏2023-10-05 17.17.28.png

截屏2023-10-05 17.17.52.png

截屏2023-10-05 17.17.39.png

<aside> 💡 Exam tips:

截屏2023-10-03 10.18.24.png

For the nth line of the code:

Total efficiency:

Example of Asymptotic Running Time Analysis

Selection-Sort(Array A, Integer n)
1. for integer i ← 1 to n-1 do
2.     k ← i
3.     for integer j ← i+1 to n do
4.         if A[j] < A[k] then
5.             k ← j
6.         end if
7.     end for
8.     swap A[i] and A[k]
9. end for
  1. Line 1: $O(n)$
  2. Line 2: $O(n)$
  3. Line 3: Considering its decreasing runs due to i increment: $\Sigma_{i=1}^{n-1} (n-i) = \frac{n(n-1)}{2} = O(n^2)$
  4. Lines 4 & 5: Same as Line 3 $O(n^2)$
  5. Line 8: $O(n)$

Aggregated Time Complexity: $O(n) + O(n) + O(n^2) + O(n^2) + O(n) = O(n^2)$

Thus, the overall time complexity is $O(n^2)$