# 演算法 名詞介紹 ###### tags: `alogithm` ## Big O Notation ### 定義 - 衡量 input 趨勢會往哪走 - 最壞情況下,演算法趨勢會往走 - 界定 upeerbond ### 規則 - Constant does not matter - Small Terms do not matter - logarithm Base does not matter(底數不重要) ## Big Omega ### 定義 當 f(n) = Ω(g(n)), if exist real number c, n0 then f(n) >= c*g(n) >=0 且對於所有 n >= n0 - 定義 lowebond ## Big Theata ### 定義 同時找到f(n)的「上界(upper bound)」與「下界(lower bound)」,像是三明治一樣把f(n)夾住 ## Big O in Arrays and Objects 1. Object ``` Insertion O(1) Removal O(1) Searching O(n) Accessing O(1) ``` 2. Array ``` Insertion - push O(1) - unshift O(n) Removal - pop O(1) - shift O(n) Searching O(n) Accessing O(1) ``` 如果是下面這段程式碼 ``` let n = 5; let array = [1,2,3,4,5] for(let i =0; i< n; i++){ array.unshift(10) } 這邊的時間複雜度會是O(n平方) ```