study

A diary of some sort. An interesting one.

Week 2

On Algorithm Efficiency.

There’s Big O Notation, which represents the worst case scenario and is generally said to be used in describing the execution time or space used by an algorithm.

There’s also the Big Omega Notation which, unlike Big O that describes upper bounds, describes lower bounds.

In order of decreasing speed, Big O can be represented as follows:

Quick notes:

A for loop with an O(1) body has a linear time complexity O(n). I.e.

for (init; check; increment) {
  // O(1) operation
}

A nested for loop with an O(1) body has a quadratic time complexity O(n^2). I.e.

for (init; check; increment) {
  for (init; check; increment) {
    // O(1) op.
  }
}