Skip to main content

Definitions

A

Algorithm

An algorithm is a procedure to accomplish a specific task, namely a well-specified problem, where the problem is specified by describing the complete set of instances it must work on and of its output after running on one of these instances.

Problem vs. Problem Instance

The distinction between a problem and an instance of a problem is critical. Determining that you are dealing with a general problem instead of an instance is your first step towards solving it.

Three Desirable Properties for any Algorithm

There are three desirable properties for a good algorithm. We seek algorithms that are

  1. correct
  2. efficient
  3. easy to implement

Correctness may be formally verified by means of a proof (e.g., induction, contradiction, etc.) while efficiency is typically analyzed and established by means of Big-OO notation.

API wrapper

From Quora: An API-wrapper typically takes an API in one form and transforms it into another.

An example might be useful:

The main application interface to Flickr (the image hosting service) is a REST api (is http GET or POST calls). There is a library called pyFlickr which is a API-wrapper it provides a Pythonic interface to Flickr classes, methods, iterators using the REST API under the skin. It keeps all of the REST api methods intact and available, but you call them using Python function calls and wrappings.

Sometimes you will see the term binding, as in a Python binding for xyz; essentially this is different form of API-wrapper. Here the wrapper transforms an API designed for one programming language and provides functionality in a second language to call the original API. An example here is pyGTK. The original gtk api is written a a C library. pyGTK is called a Python binding for gtk as it allows a Python program to call the gtk API written in C.

B

Big Oh

Controlled chaos: OO notation significantly simplifies calculations because it allows us to be sloppy but in a satisfactorily controlled way. [4]

Need for Ω\Omega and Θ\Theta: As noted in [10], Big-OO notation is used extensively to describe the growth of functions, but it has limitations. In particular, when f(x)f(x) is O(g(x))O(g(x)), we have an upper bound, in terms of g(x)g(x), for the size of f(x)f(x) for large values of xx. However, big-OO notation does not provide a lower bound for the size of f(x)f(x) for large xx. For this, we use big-Omega notation. When we want to give both an upper and a lower bound on the size of the function f(x)f(x), relative to a reference function g(x)g(x), we use big-Theta notation. Both big-Omega and big-Theta notation were introduced by Donald Knuth in the 1970s. His motivation for introducing these notations was the common misuse of big-OO notation when both an upper and a lower bound on the size of a function are needed.

The definitions that follow may be found in [10].

Worst case (big-O)

Let ff and gg be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x)f(x) is O(g(x))O(g(x)) if there are constants CC and kk such that

f(x)Cg(x)|f(x)|\leq C|g(x)|

whenever x>kx>k. This reads as, "f(x)f(x) is big-oh of g(x)g(x)," and is sometimes represented as f(x)=O(g(x))f(x)=O(g(x)) even though usage of = is more colloquial than anything.

Example illustrating definition

Problem: Show that f(x)=x2+2x+1f(x)=x^2+2x+1 is O(x2)O(x^2).

Solution: We observe that we can readily estimate the size of f(x)f(x) when x>1x>1 because x<x2x<x^2 and 1<x21<x^2 when x>1x>1. It follows that

0x2+2x+1x2+2x+x2=4x20\leq x^2+2x+1\leq x^2+2x+x^2=4x^2

whenever x>1x>1. Consequently, we can take C=4C=4 and k=1k=1 as witnesses to show that f(x)f(x) is O(x2)O(x^2). That is, f(x)=x2+2x+1<4x2f(x)=x^2+2x+1<4x^2 whenever x>1x>1. (Note that it is not necessary to use absolute values here because all functions in the equalities are positive when xx is positive.)

Alternatively, we can estimate the size of f(x)f(x) when x>2x>2. When x>2x>2, we have 2xx22x\leq x^2 and 1x21\leq x^2. Consequently, if x>2x>2, we have

0x2+2x+1x2+x2+x2=3x20\leq x^2+2x+1\leq x^2+x^2+x^2=3x^2

It follows that C=3C=3 and k=2k=2 are also witnesses to the relation f(x)f(x) is O(x2)O(x^2).

Observe that in the relationship f(x)f(x) is O(x2)O(x^2), x2x^2 can be replaced by any function with larger values than x2x^2. For example, f(x)f(x) is O(x3)O(x^3), f(x)f(x) is O(x2+2x+7)O(x^2+2x+7), and so on.

It is also true that x2x^2 is O(x2+2x+1)O(x^2+2x+1), because x2<x2+2x+1x^2<x^2+2x+1 whenever x>1x>1. This means that C=1C=1 and k=1k=1 are witnesses to the relationship x2x^2 is O(x2+2x+1)O(x^2+2x+1). See [10] for more details.

Abuse of Notation

As noted in [4], mathematicians customarily use the = sign as they use the word "is" in English: Aristotle is a man, but a man isn't necessarily Aristotle. Hence, in discussions of big oh, it is worth noting that the equality sign is not symmetric with respect to such notations; we have n+1=O(n)n+1=O(n) and n+2=O(n)n+2=O(n) but not 1=21=2, nor can we say that O(n)=n+2O(n)=n+2.

The definition above may be expressed more formally in the language of quantifiers as follows:

(C>0)(k>0)(xR)(x>k    f(x)Cg(x))(\exists C>0)(\exists k>0)(\forall x\in\R)(x > k \implies |f(x)|\leq C|g(x)|)
Witnesses

The constants CC and kk in the definition of big-OO notation above are called witnesses to the relationship "f(x)f(x) is O(g(x))O(g(x))". To establish that f(x)f(x) is O(g(x))O(g(x)) we need only one pair of witnesses to this relationship. That is, to show that f(x)f(x) is O(g(x))O(g(x)), we need find only one pair of constants CC and kk, the witnesses, such that f(x)Cg(x)|f(x)|\leq C|g(x)| whenever x>kx>k.

Note that when there is one pair of witnesses to the relationship f(x)f(x) is O(g(x))O(g(x)), there are infinitely many pairs of witnesses. To see this, note that if CC and kk are one pair of witnesses, then any pair CC' and kk', where C<CC < C' and k<kk < k', is also a pair of witnesses, since f(x)Cg(x)Cg(x)|f(x)|\leq C|g(x)|\leq C'|g(x)| whenever x>k>kx>k'>k.

A useful approach for finding a pair of witnesses is to first select a value of kk for which the size of f(x)|f(x)| can be readily estimated when x>kx > k and to see whether we can use the estimate to find a value of CC for which f(x)<Cg(x)|f(x)| < C|g(x)| for x>kx>k.

Best case (big-Ω)

Let ff and gg be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x)f(x) is Ω(g(x))\Omega(g(x)) if there are positive constants CC and kk such that

f(x)Cg(x)|f(x)|\geq C|g(x)|

whenever x>kx>k. This reads as, "f(x)f(x) is big-Omega of g(x)g(x)," and is sometimes represented as f(x)=Ω(g(x))f(x)=\Omega(g(x)). This definition may be expressed more formally in the language of quantifiers as follows:

(C>0)(k>0)(xR)(x>k    f(x)Cg(x))(\exists C>0)(\exists k>0)(\forall x\in\R)(x > k \implies |f(x)|\geq C|g(x)|)

Average case (big-Θ)

Let ff and gg be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x)f(x) is Θ(g(x))\Theta(g(x)) if f(x)f(x) is O(g(x))O(g(x)) and f(x)f(x) is Ω(g(x))\Omega(g(x)). This reads as, "f(x)f(x) is big-Theta of g(x)g(x)," and is sometimes represented as f(x)=Θ(g(x))f(x)=\Theta(g(x)). We also say that f(x)f(x) is of order g(x)g(x). This definition, in light of the previous definitions for big-OO and big-Ω\Omega, may be expressed more formally in the language of quantifiers as follows:

(C1,C2R+)(k1,k2R+)(xR)(x>max{k1,k2}    f(x)C1g(x)f(x)=O(g(x))f(x)C2g(x)f(x)=Ω(g(x))f(x)=Θ(g(x)))(\exists C_1,C_2\in\R^+)(\exists k_1,k_2\in\R^+)(\forall x\in\R)(x > \max\{k_1,k_2\} \implies \underbrace{\overbrace{|f(x)|\leq C_1|g(x)|}^{f(x)=O(g(x))}\land \overbrace{|f(x)|\geq C_2|g(x)|}^{f(x)=\Omega(g(x))}}_{f(x)=\Theta(g(x))})

C

D

E

F

G

H

I

J

K

L

M

Math

Logarithms

  • y=logaxy=\log_a x means ay=xa^y=x
  • logaax=x\log_a a^x = x
  • alogax=xa^{\log_a x}=x
  • loga1=0\log_a 1=0
  • logaa=1\log_a a=1
  • logx=log10x\log x=\log_{10}x
  • lnx=logex\ln x=\log_e x
  • logaxy=logax+logay\log_a xy=\log_a x+\log_a y
  • loga(xy)=logaxlogay\log_a\Bigl(\dfrac{x}{y}\Bigr)=\log_a x-\log_a y
  • logaxb=blogax\log_a x^b = b\log_a x
  • logbx=logaxlogab\log_b x=\dfrac{\log_a x}{\log_a b}

Modular arithmetic

Sequences and series

Arithmetic
Arithmetic sequence

An arithmetic sequence is a sequence of the form

a,a+d,a+2d,a+3d,a+4d,a, a+d, a+2d, a+3d, a+4d,\ldots

The number aa is the first term, and dd is the common difference of the sequence. The nnth term of an arithmetic sequence is given by

an=a+(n1)da_n = a + (n-1)d
Partial sums of an arithmetic sequence

For the arithmetic sequence an=a+(n1)da_n = a + (n-1)d, the nnth partial sum

Sn=a+(a+d)+(a+2d)+(a+3d)++[a+(n1)d]S_n=a+(a+d)+(a+2d)+(a+3d)+\cdots+[a+(n-1)d]

is given by either of the following formulas:

  1. Sn=n2[2a+(n1)d]S_n = \frac{n}{2}[2a+(n-1)d]
  2. Sn=n[(a+an)/2]S_n = n[(a+a_n)/2]
Geometric
Geometric sequence

A geometric sequence is a sequence of the form

a,ar,ar2,ar3,ar4,a, ar, ar^2, ar^3, ar^4, \ldots

The number aa is the first term, and rr is the common ratio of the sequence. The nnth term of a geometric sequence is given by

an=arn1a_n=ar^{n-1}
Partial sums of a geometric sequence

For the geometric sequence an=arn1a_n=ar^{n-1}, the nnth partial sum

Sn=a+ar+ar2+ar3+ar4++arn1(r1)S_n=a+ar+ar^2+ar^3+ar^4+\cdots+ar^{n-1}\qquad(r\neq 1)

is given by

Sn=a1rn1rS_n=a\frac{1-r^n}{1-r}
Sum of an infinite geometric series

If r<1|r|<1, then the infinite geometric series

a+ar+ar2+ar3+ar4++arn1+a+ar+ar^2+ar^3+ar^4+\cdots+ar^{n-1}+\cdots

has the sum

S=a1rS=\frac{a}{1-r}

Sums

Powers of integers
  • k=1n1=n\displaystyle\sum_{k=1}^n 1=n

  • k=1nk=n(n+1)2\displaystyle\sum_{k=1}^n k=\frac{n(n+1)}{2}

  • k=1nk2=n(n+1)(2n+1)6\displaystyle\sum_{k=1}^n k^2=\frac{n(n+1)(2n+1)}{6}

  • k=1nk3=n2(n+1)24\displaystyle\sum_{k=1}^n k^3=\frac{n^2(n+1)^2}{4}

N

O

P

Path (graph theory)

A path is a trail in which all vertices (and therefore also all edges) are distinct.

Q

R

S

T

Time-sharing (computing)

Time-sharing is the ability for multiple users to share access to a single computer’s resources.

An Ars Technica article on the history of Linux also mentions time-sharing: "Thus [due to costs associated with operating and owning the GE 645], there was widespread interest in time sharing, which allowed multiple researchers to run programs on the mainframe at the same time, getting results immediately on their remote terminals. With time sharing, the programs weren’t printed off on punch cards, they were written and stored on the mainframe. In theory, researchers could write, edit, and run their programs on the fly and without leaving their offices. Multics was conceived with that goal in mind. It kicked off in 1964 and had an initial delivery deadline of 1967."

Trail (graph theory)

A trail is a walk in which all edges are distinct.

U

V

W

Walk (graph theory)

A walk is a finite or infinite sequence of edges which joins a sequence of vertices.

Let G=(V,E,ϕ)G=(V,E,\phi) be a graph. A finite walk is a sequence of edges (e1,e2,,en1)(e_1,e_2,\ldots,e_{n-1}) for which there is a sequence of vertices (v1,v2,,vn1,vn)(v_1,v_2,\ldots,v_{n-1}, v_n) such that ϕ(ei)={vi,vi+1}\phi(e_i)=\{v_i,v_{i+1}\} for i=1,2,,n1i=1,2,\ldots,n-1. (v1,v2,,vn)(v_1,v_2,\ldots,v_n) is the vertex sequence of the walk. The walk is closed if v1=vnv_1=v_n and it is open otherwise. An infinite walk is a sequence of edges of the same type described here, but with no first or last vertex, and a semi-infinite walk (or ray) has a first vertex but no last vertex.

X

Y

Z