140 likes | 249 Views
CSE 3358 Note Set 3. Data Structures and Algorithms. Overview:. More Big-oh Big Omega and Big Theta Calculating T(n) for a particular algorithm. Typical Growth Rates. Revisiting Big Ω.
E N D
CSE 3358 Note Set 3 Data Structures and Algorithms
Overview: • More Big-oh • Big Omega and Big Theta • Calculating T(n) for a particular algorithm
Revisiting Big Ω • T(N) = Ω (g(n)) if there are positive constants c and n0such that T(N) >= c*g(n) when N >= n0.
Revisiting Big • T(N) = (h(n)) iffT(N) = O(h(n)) and T(N) = Ω (h(n)) .
Properties of Big O If f(n)=O(g(n)) and g(n)=O(h(n)), then f(n)=O(h(n)). (Transitivity) If f(n)= O(h(n)) and g(n)= O(h(n)), then f(n) + g(n) = O(h(n)). (Addition) The function ank= O(nk). The function nk= O(nk+j) for any positive j.
Other Rules • If f(n) is a polynomial of degree k, then f(n) =O(nk) • logk n = O(n) for any constant k.
Random Access Machine • “Generic” Computer • Helps us analyze the running time of an algorithm • Count the individual number of steps needed • Simple operations take one time unit • +, -, *, /, comparison, function call, etc • Complex structures such as methods and loops take longer (obviously ) • Not worried about different types of memory acces (cache, ram, disk) – all 1 time unit
Example 1 inty = 10; y = y + x; return y;
Example 2 if (x < 10) return 25; else return 30;
Example 3 int sum = 0; for (inti = 0; i < num; i++) sum = sum + arr[i]; return sum;
Example 4 for (inti = 0; i < n ; i++) for (int j = 0; j < n; j++) k++;
Observations • Loops usually increase complexity • Nested loops usually increase complexity more • Shortcut w/ RAM Model • Typically, only comparisons need to be counted • As types of ops are abstracted away, detail of T(n) reduced – but usually sufficient to come up with O() notation