Version: 0.3.38
Math Recap#
I summarize below the main mathematical concepts we use in this course and the related notations.
See also
I just put here a brief summary, too brief for sure. If you feel “rusty”, just pick up a good textbook about basic Maths for Computer Science. See for instance:
📖 E. Lehman, F. T. Leighton, and A. R. Meyer (2017). Mathematics for Computer Science. MIT Press. Available here
Logic#
As we study algorithms and data structure, we will make statements. To formalize these statements (aka predicates, claims, assertions, etc.) we shall rely on well-known logical operators, namely the negation (not), the conjunction (and), the disjunction (or), the implication (if) and the equivalence (equals).
The negation of an assertion \(A\) is true whenever \(A\) is false, and false whenever \(A\) is true. We denote it by by \(\neg A\). For instance, we write \(\neg (x \lt 5)\) to denote that x shall not be lower than five.
The disjunction (or) of two assertions \(A\) and B is true when either is true and false only when both are false. We denote this disjunction by \(A \lor B\). For instance the expression \(x \lt 0 \lor x \gt 0\) captures all numbers except zero.
The conjunction (and) of two assertions \(A\) and B is true only when both :math: A and B are true, and false otherwise. We denote such a conjunction using \(A \land B\). For instance the expression \(x \leq 0 \land x \geq 0\) captures zero, the only number for which both assertions are true.
The implication (if) between two assertions \(A\) and \(B\) indicates that \(B\) is true whenever \(A\) is true. Intuitively this is close to if A, then B. We denotes this using \(A \implies B\). We can write for instance that \(x \leq 5 \implies x \leq 10\) to say that if a number is smaller than five, it is necessary smaller than 10 too.
The equivalence (equals) between two assertions \(A\) and \(B\) indicates that they are always true and false at together. We denote that by \(A \iff B\). We could write for instance \(x \leq 5 \iff \neg (x \gt 5)\).
Besides these five logical operations, we will use the universal and existential quantifiers, to explicit how many “things” should satisfy our assertions.
The universal quantifier, denoted by \(\forall\) indicates that our assertions apply to everything. For instance, the assertion \(\forall x, \: x \times 0 = 0\) indicates that every number multiplied by zero gives zero.
The existential quantifier, denoted ny \(\exists\) indicates that our assertion applies to at least one thing. For instance, the assertion \(\exists x, \: x+1=5\) claims that there exists at least one number, which incremented by 1 gives 5.
Note these two quantifiers are related by the negation operation as follows:
Sets#
A set is a collection of unique items, without any order. For instance, the set of card families (F) consists of spades (s), hearts (h), clubs (c) and diamonds (d). We will denote the items of a given set between curly brackets as follows:
A set has no order. So returning to our set of card families, we cannot talk about the first family. A set does not include duplicates, so that:
We denote the fact that a given item belongs to a given set (i.e., the membership) using the \(\in\) symbol. For instance, \(s \in F\) indicates that \(s\) (spades) is card family whereas \(z \notin F\) indicates that \(z\) does not.
The number of elements that belongs to a set is called its cardinality. We denote it between using vertical bars, for instance \(|F| = 4\).
A set can be included into another set, if and only if all its member are also members of the larger set. For instance, we can say that the set of black families \(B = \{ s, c \}\) is included into \(F\). We denote this inclusion by \(B \subseteq F\). Using the logical relationships above we can write:
There are two main ways to define a set, by extension or by comprehension.
When defining a set by extension we will simply list all its members, exhaustively. For instance to define the set \(S\) containing all the natural numbers smaller than 10, we would write:
\[S = \{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 \}\]By contrast, when defining a set by comprehension, we will define a set using the rule that characterizes all its members. Returning to the set \(S\) containing all the natural numbers smaller than 10 we would write:
\[S = \{ x \in \mathbb{N} \, | \, x \leq 10 \}\]
We commonly use four main operations on sets, namely the complement, the union, the intersection and the difference.
The complement of a set \(S\) is the all the elements that do not belong to \(S\). We denote it by \(S^\complement\).
\[x \in S^\complement \iff x \notin S\]The union between two sets \(A\) and \(B\) is all their member combined in a single set. We denote this union by \(A \cup B\).
\[x \in (A \cup B) \iff (x \in A) \lor (x \in B)\]The intersection of two sets \(A\) and \(B\) is their common members. We denote this intersection by \(A \cap B\).
\[x \in (A \cap B) \iff (x \in A) \land (x \in B)\]The difference between two sets \(A\) and \(B\) is the set of items that belong to A but not to be. We denote that as \(A \backslash B\).
\[x \in (A \backslash B) \iff (x \in A) \land (x \notin B)\]
Sequences & Tuples#
By contrast with sets, sequences are ordered collections of non-unique elements. We denote a sequence between round brackets, for instance the ten first number of the Fibonacci sequence are \((0, 1, 1, 2, 3, 5, 8, 13, 21, 34)\).
Sequence of particular length are pretty handy. For instance an ordered pair \((x,y)\) is a sequence of length 2, which results from the cartesian product (denoted by \(\times\)) between two sets.
Similarly, triples, quadruples, quintuples, etc are sequences of length 3, 4, 5 and so on and so forth.
Functions#
Intuitively, A relation \(R\) between two sets \(A\) and \(B\) associate some elements from \(A\) to some of the elements \(B\). Formally, such a relation \(R\) is a subset of the cartesian product such as \(R \subseteq A \times B\). We denote the fact that a pair \((x,y)\) belongs to a relation \(R\) using the shorthand \(xRy\).
When R maps some elements of \(A\) onto one and only one element of \(B\), \(R\) is a function. Formally, a function \(f \subseteq A \times B\) implies that:
We denote functions using the notation \(f: A \to B\) to stress the fact that \(f\) is a function that maps \(A\) onto \(B\), and not a general unconstrained relation. We use either the notation \(f(x) = y\) or \(x \mapsto y\) to denote a specific mapping \((x,y) \in f\).
A total function \(f: A \to B\) maps each and every element of \(A\). By contrast, a partial function \(f: A \nrightarrow B\) only maps some of the elements of \(A\).
Probabilities#
A probability is a number that reflects how likely something is to happen. This number is a real number between 0 and 1, where zero means it cannot happen and 1 means it will necessarily happen.
Consider the roll of a dice. The six possible outcomes are the six faces of the dices. In the probability theory, these form the sample space \(\Omega= \{1, 2, 3, 4, 5, 6 \}\) of the experiment. If the dice is fair, each faces has the same probability to show up \(1/6\). If the dice is biased, some faces will show up more often and thus get a higher probability.
The function that maps all possible outcomes to their respective probability is the probability distribution of the experiment.
A random variable is variable whose value represents the outcome of an experiment. A random variable thus comes with both a sample space \(\Omega\) and a probability distribution. Consider again the roll of a dice. We can define a random variable \(D\) that represents its visible face. We will denote the probability of obtaining a 3 by \(\mathbb{P}[D=3] = \frac{1}{6}\).
With probabilities, there are three important rules:
For a given random variable \(X\), the probability of each possible outcome always sum up to one.
\[\sum_{x \, \in \, \Omega} \mathbb{P}[X=x] = 1\]The probability of an event not occuring is given by
\[\mathbb{P}[\neg (X = x)] = 1 - \mathbb{P}[X=x]\]The probability of a disjunction of two independent events is given by
\[\mathbb{P}[X=x \lor X=y] = \mathbb{P}[X=x] + \mathbb{P}[X=y]\]
Calculus#
We also uses some basic calculus, so it is important to get a basic understand and fluency with the exponents, logarithms and simple summations.
Exponents#
We use a simple superscript notation to raise a number to the n-th power, as followed.
There are a few basic calculus rules that may come up handy at times:
\(x^0 = 1\)
\((x \times y)^a = x^a \times y^a\)
\(x^a \times x^b = x^{a+b}\)
\((x^a)^b = x^{a \times b}\)
\(\frac{x^a}{x^b} = x^{a-b}\)
Logarithms#
We will use logarithms quite a bit, so it is important to review this concept.
Raising a number to a given power is unfortunately not a commutative operation, that is \(a^b \neq b^a\). There are thus two ways to reverse this process. Consider for instance the expression \(a^b = c\):
Given \(c\) and \(b\), we can ask what number was raised to the power \(b\) to get \(c\). The n-th root operation gives us the solution: \(a = \sqrt[b]{c}\)
Given \(c\) and \(a\), we can ask the question to what power \(a\) was raised to get \(c\). This operation is the logarithm and we denote it as \(b = \log_a(c)\). When the exponent is the number \(e\), we use \(\ln\) and omit the exponent.
Here are a few calculus rules that I found useful to remember:
\(\log_b(1) = 0\)
\(\log_b(b) = 1\)
\(\log_b(b^x) = x\)
\(\log_b(x^k) = k \times \log_b(x)\)
\(b^{\log_b(x)} = k\)
\(\log_b(x \times y) = \log_b(x) + \log_b(y)\)
\(\log_b(\frac{x}{y}) = \log_b(x) - \log_b(y)\)
\(\log_b(x) = \frac{\log_c(x)}{\log_c(b)}\)
Summations#
Here are a few useful formulas
\(\sum_{i=1}^{n} c = \overbrace{c + c + \ldots + c}^{\textrm{n times}} = c \times n\)
\(\sum_{i=a}^{b} c = c \cdot (b - a + 1)\)
\(\sum_{i=1}^{n} i = \frac{n (n+1)}{2}\)
\(\sum_{i=1}^{n} c \cdot f(i) = c \cdot \sum_{i=1}^{n} f(i)\)
\(\sum_{i=1}^{n} i^k \approx \frac{1}{k+1} n^{k+1}\)
Products#
From time to time, we will meet “products”. Here are a few formulas that can be helpful:
\(\prod_{i=1}^{n} i = 1 \times 2 \times 3 \times \ldots \times n\)
\(\prod_{i=1}^{n} f(i)g(i) = \prod_{i=1}^{n} f(i) \prod_{i=1}^{n} g(i)\)
\(\prod_{i=1}^{n} x^i = x^{\sum_{x=1}^{n}i}\)
Factorial#
One special product is of importance, the factorial, which is the product of all the positive integers smaller or equal to a given number \(n\).
Here are two useful facts about factorials:
\(0! = 1\)
\(n! = n \times (n-1)!\)
Combinatorics#
In this course, we will often count how many ways there are arrange items into a collection. There are two concepts that are useful here permutations and combinations. In both cases, we have to look at two cases, with and without “repetitions”.
Permutations#
With permutations, the order of things matters. For instance, if we are try to find the PIN code of our mobile phone we have forgotten, in principle, we must try all the permutations of four digits (0, 1, 2, 3, …, 9).
More generally, there \(n^k\) permutations of \(k\) items chosen among \(n\) (with repetition).
When repetitions are not allowed this number \(P(n, k)\) is given by:
Combinations#
Sometimes, the order does not matter. For instance, we have to create a team of 3 persons in a company counting 20 employees. How many of such teamss can we create? The order does not matter, the team Hugo, Lisa, John is the same as the team John, Hugo, Lisa (these are sets of persons). This number \(C(n,k)\) (of combinations without repetitions) is given by the formula:
When repetitions are allowed, this number is given by \(C(n+k-1, k)\).