CST370 Week 2

 This was our second week in CST 370 - Design and Analysis of Algorithms.

 Asymptotic Notations

 This week we discussed three different notations for measuring algorithm efficiency.

  • O notation, also called Big Oh, is defined as all functions with the same or lower order of growth as f(n). It is used to measure the upper bound of an algorithm's efficiency. For example, the O notation of a sequential search would be O(n).
  • Θ notation, also called Big Theta, is defined as all functions with the same order of growth as f(n). It is used to measure the exact efficiency of an algorithm. For example, an algorithm with an order of growth of n would be Θ(n). Θ notation cannot be used for an algorithm with a varying order of growth, such as a sequential search.
  • Ω notation, also called Big Omega, is defined as all functions with the same or higher order of growth as f(n). It is used to measure the lower bound of an algorithm's efficiency. For example, the Ω notation of a sequential search would be Ω(1).

Recursive Algorithms

This week we also looked at how to analyze the efficiency of recursive algorithms. To determine a recursive algorithm's order of growth, we look at the operations that occur in each iteration. Let's use the below algorithm as an example:

 

 It's basic operation is *, which happens once per iteration. We can write the number of operations as:

  • F(n) = F(n-1) + 1 = F(n-2) + 2 = F(0) + n

Then we can calculate the O, Θ, or Ω notation to get the algorithm's order of growth. For this algorithm, its order of growth would be O(n).

Brute Force Algorithms

This week we discussed brute force algorithms. They systematically checks every answer of a problem until it is solved. While less efficient than other algorithms, it is often much simpler to implement. It is used for small problems, where inefficient execution is acceptable, and for benchmarks to compare against other algorithms.

Two examples of brute force algorithms would be selection sort, where in each loop in an array the smallest element is moved to the beginning, and bubble sort, where larger elements are swapped with smaller ones until the array is completely sorted. 

 

Comments

Popular posts from this blog

Week 11

Week 12

Week 19