Subsections

# 1.2 Mathematical Background

In this section, we review some mathematical notations and tools used throughout this book, including logarithms, big-Oh notation, and probability theory.

## 1.2.1 Logarithms

In this book, the expression denotes the base- logarithm of . That is, the unique value that satisfies

Most of the logarithms in this book are base 2 (binary logarithms), in which case we drop the base, so that is shorthand for .

Another logarithm that comes up several times in this book is the natural logarithm. Here we use the notation to denote , where -- Euler's constant -- is given by

The natural logarithm comes up frequently because it is the value of a particularly common integral:

Two of the most common manipulations we do with logarithms are removing them from an exponent:

and changing the base of a logarithm:

For example, we can use these two manipulations to compare the natural and binary logarithms

## 1.2.2 Factorials

In one or two places in this book, the factorial function is used. For a non-negative integer , the notation (pronounced  factorial'') denotes

Factorials appear because counts the number of distinct permutations, i.e., orderings, of n distinct elements. For the special case , is defined as 1.

The quantity can be approximated using Stirling's Approximation:

where

Stirling's Approximation also approximates :

(In fact, Stirling's Approximation is most easily proven by approximating by the integral .)

Related to the factorial function are the binomial coefficients. For a non-negative integer and an integer , the notation denotes:

The binomial coefficient (pronounced  choose '') counts the number of subsets of an element set that have size , i.e., the number of ways of choosing distinct integers from the set .

## 1.2.3 Asymptotic Notation

When analyzing data structures in this book, we will want to talk about the running times of various operations. The exact running times will, of course, vary from computer to computer and even from run to run on an individual computer. Therefore, instead of analyzing running times exactly, we will use the so-called big-Oh notation: For a function , denotes a set of functions,

Thinking graphically, this set consists of the functions where starts to dominate when is sufficiently large.

We generally use asymptotic notation to simplify functions. For example, in place of we can write, simply, . This is proven as follows:

which demonstrates that the fundtion is in the set using the constants and .

There are a number of useful shortcuts when using asymptotic notation. First:

for any . Second: For any constants ,

These inclusion relations can be multiplied by any positive value, and they still hold. For example, multiplying by yields:

Continuing in a long and distinguished tradition, we will abuse this notation by writing things like when what we really mean is . We will also make statements like the running time of this operation is '' when this statement should be the running time of this operation is a member of .'' These shortcuts are mainly to avoid awkward language and to make it easier to use asymptotic notation within strings of equations.

A particularly strange example of this comes when we write statements like

Again, this would be more correctly written as

The expression also brings up another issue. Since there is no variable in this expression, it may not be clear what variable is getting arbitrarily large. Without context, there is no way to tell. In the example above, since the only variable in the rest of the equation is , we can assume that this should be read as , where .

In a few cases, we will use asymptotic notation on functions with more than one variable. There seems to be no standard for this, but for our purposes, the following definition is sufficient:

This definition captures the situation we really care about: when the arguments make take on large values. This agrees with the univariate definition of when is an increasing function of . The reader should be warned that, although this works for our purposes, other texts may treat multivariate functions and asymptotic notation differently.

## 1.2.4 Randomization and Probability

Some of the data structures presented in this book are randomized; they make random choices that are independent of the data being stored in them or the operations being performed on them. For this reason, performing the same set of operations more than once using these structures could result in different running times. When analyzing these data structures we are interested in their average or expected running times.

Formally, the running time of an operation on a randomized data structure is a random variable and we want to study its expected value. For a discrete random variable taking on values in some countable universe , the expected value of , denoted by is given the by the formula

Here denotes the probability that the event occurs. In all the examples in this book, these probabilities are only with respect to whatever random choices are made by the randomized data structure; there is no assumption that the data stored in the structure is random or that the sequence of operations performed on the data structure is random.

One of the most important properties of expected values is linearity of expectation: For any two random variables and ,

More generally, for any random variables ,

Linearity of expectation allows us to break down complicated random variables (like the left hand sides of the above equations) into sums of simpler random variables (the right hand sides).

A useful trick, that we will use repeatedly, is that of defining indicator random variables. These binary variables are useful when we want to count something and are best illustrated by an example. Suppose we toss a fair coin times and we want to know the expected number of times the coin comes up heads. Intuitively, we know the answer is , but if we try to prove it using the definition of expected value, we get

This requires that we know enough to calculate that , that we know the binomial identity , and that we know the binomial identity .

Using indicator variables and linearity of expectation makes things much easier: For each , define the indicator random variable

Then

Now, , so

This is a bit more long-winded, but doesn't require that we know any magical identities or compute any non-trivial probabilities. Even better: It agrees with the intuition that we expect half the coins to come up heads precisely because each individual coin has probability of coming up heads.

opendatastructures.org