Quick Index
Lingo


Common Lingo:


Interchangeable Terms:


What is Big-O Notation?


Assume we have:


Big-O analysis basically consists of two steps:


We then use Big-O notation to classify the change in "work" (relative to growth)

Examples will help.

Algorithm Work Effort -- Examples and Quick Quiz


In the following examples, assume we are adding methods (algorithms) to a dynamic array.

Our context (method summary listing), available to us, is shown.
Method Summaries:

Here is an algorithm for the "first" method.

The algorithm gets and returns the first element.

Does the algorithm work harder as it grows?



No, size does not change the work (effort) expended by this algorithm.

We can see that the work does not change as size changes -- size is not a "player" here.
first() {
	//Return first element
	//Return null for empty case
	if (this.isEmpty())
		return null
	return this.get(0)
}
Let's say we are doing Big-O analysis on the algo for a "linear search".

Let us pretend the is growing in size towards infinity.

Does the algorithm work harder as it grows?



Certainly yes.

The structure size [e.g. "this.size()"] controls how many times we could loop.

Bottom line: growth in "size" makes this algo work harder.

Also remember we assume Worst Case


linearSearch(anElem) {
	//Return matching element
	//or null if no match
	let i = 0
	while (i < this.size()) {
		let nextElem = this.get(i)
		if (nextElem.equals(anElem))
			return nextElem
		i++
	}
	return null
}


Number of Operations



Big-O Levels and T-Shirts


One thousand people would probably have one thousand (if precisely measured) different shirt sizes. But when we choose tee shirts we broadly group this into something like (Small, Medium, Large).

Big-O is similar. We do not make exact measurements or operation counts. What we do is determine the grouping (performance level) that a given algorithm belongs to.