University of Virginia Computer Science CS216: Program and Data Representation, Spring 2006 (none) 23 January 2006

## CS216 Notes 2 (23 January 2006)

#### Assignments Due

Section Reminder: Section meetings are Monday, 7-8:45pm in Thorton D223; Tuesday, 3:30-5:15 in D221; and Tuesday, 7:30-9:15pm in D223. Everyone must be in one of the sections and should attend section today or tomorrow.

#### Order Notation

The operators O, Ω, Θ, and o all take a function (from a positive integer to a real value) and define a set of functions (from positive integers to real values).

O (big-Oh) — the set O(f) is the set of functions that grow no faster than f

f O(g)) means:
There are positive constants c and n0 such that f(n) cg(n) for all values n ≥ n0.
Ω (Omega) — the set Ω (f) is the set of functions that grow at least as fast as f
f Ω (g) means:
There are positive constants c and n0 such that f(n) cg(n) for all values n ≥ n0.
Θ (Theta) — the set Θ (f) is the set of functions that grow as fast as f
f Θ (g) means
f O(g)) and f Ω (g)
o (little-oh) — the set o(f) is the set of functions that grow slower than f
f o (g) means:
For all positive constants c, there exists a positive constant n0 such that f(n) cg(n) for all values n ≥ n0.

People (and textbooks, but fortunately not the one we use in CS216) often use them less carefully and say things like, "linear search is O(n)". This is common, but poor wording. It is better to say, "the running time of linear search is in Θ(n) where n is the number of elements in the input list". Note that it is true to say "the running time of linear search is in O(n)", but this is a much weaker statement. It is also true that "the running time of linear search is in O(n2)". The higher O-bounds are all correct, just not as precise as possible. In cases where a Θ-bound can be found, this is always more useful.

#### Questions

Why do we want to predict the running time of a program?

Which is "bigger", O(n) or O(n2)?

Which is "bigger", Ω(n) or Ω(n2)?

Which is "bigger", Θ(n) or Θ(n2)?

Draw a diagram showing the sets O(n), Ω(n), Θ(n), and o(n) and the functions 3n, log n, n2 as points in your set diagram.

Prove that for all functions f, Θ(f) = O(f) - o(f). (Start by making an information argument why it should be true. Then, prove formally using the definitions of Θ, O, and o.

[an error occurred while processing this directive]