Bite-Sized Mathematics for Computer Science

Notes on MIT's 6.042J

Eda Eren
Table of Contents

Introduction

Prerequisites & Resources

Unit 1: Proofs

00. Introduction to Proofs

01. (Two) Proof Methods

02. The Well Ordering Principle

03. Logic & Propositions

04. Quantifiers and Predicate Logic

05. Sets

06. Binary Relations

07. Induction

08. State Machines — Invariants

09. Recursive Definitions

10. Infinite Sets

Unit 2: Structures

11. GCDs

12. Congruences

13. Euler's Theorem

14. RSA Encryption

16. Directed Acyclic Graphs

17. Partial Orders and Equivalence

18. Degrees & Isomorphism

19. Coloring & Connectivity

20. Trees

21. Stable Matching

Unit 3: Counting

22. Sums & Products

23. Asymptotics

24. Counting with Bijections

25. Repetitions & Binomial Theorem

26. Pigeonhole Principle, Inclusion-Exclusion

Unit 4: Probability

27. Intro to Discrete Probability

28. Conditional Probability

29. Independence & Causality

30. Random Variables, Density Functions

31. Expectation

32. Deviation: Markov & Chebyshev Bounds

33. Sampling & Confidence

34. Random Walks & PageRank

Digraphs: Walks and Paths

A digraph (directed graph) is a type of graph to represent how things are connected together.
As with many other graphs, digraphs have nodes (or, vertices) and directed edges. That's what gives their name: their edges are directed.

Digraph example

One example is the World Wide Web itself, we can think of webpages as vertices, and the hyperlinks as edges.

A directed edge ee starts at what is called a tail vertex, and ends at the head vertex.
If we denote it as e=uve = \textlangle{u \rightarrow v} \textrangle, then, uu is the tail vertex, and vv is the head vertex. We can represent this edge as an ordered pair as well, such as: (u, v)(u, \ v).

The set of vertices in a directed graph GG, denoted as V(G)V(G), is a binary relation where the domain and the codomain are the same set VV.

The set of edges in GG are denoted as—you guessed it—E(G)E(G).

So, we can write the set of vertices of the example graph above as V={1, 2, 3, 4}V = \{1, \ 2, \ 3, \ 4\}, and the set of edges as E={(1, 2), (1, 3), (3, 2), (3, 4),(4, 3)}E = \{(1, \ 2), \ (1, \ 3), \ (3, \ 2), \ (3, \ 4), (4, \ 3)\}.


There are some terms we need to be familiar with.

The in-degree of a vertex is the number of arrows coming into it:

If GG is a digraph, and vV(G)v \in V(G):

indeg(v)={eE(G)  head(e)=v}\text{indeg}(v) = |\{e \in E(G) \ | \ \text{head}(e) = v\}|

The out-degree of a vertex is the number of arrows coming out of it:

outdeg(v)={eE(G)  tail(e)=v}\text{outdeg}(v) = |\{e \in E(G) \ | \ \text{tail}(e) = v\}|

The total number of in-degrees and out-degrees will be the number of edges in the graph, E(G)|E(G)|:

vV(G)indeg(v) =vV(G)outdeg(v)=E\displaystyle\sum_{v \in V(G)} \text{indeg}(v) \ = \displaystyle\sum_{v \in V(G)} \text{outdeg}(v) = |E|

A walk is a sequence of edges you follow. In the above diagram, for example, we can start at 1, go to 3, then go to 4, then go to 3 again. The length of a walk will be the number of edges that we go through (one less than the number of vertices), not the number of vertices we visit.
A path is a special type of walk where you don't visit the same vertex twice. So, if we go back to 3 after visiting 4, it won't be a path.

We can represent a walk vv as such:

v=v0 〈v0v1〉 v1 〈v1v2〉 v2 ... 〈vk1vk〉 vkv = v_0 \ \textlangle{v_0 \rightarrow v_1} \textrangle \ v_1 \ \textlangle{v_1 \rightarrow v_2} \textrangle \ v_2 \ ... \ \textlangle{v_{k - 1} \rightarrow v_k} \textrangle \ v_k

where vivi+1E(G)\textlangle{v_i \rightarrow v_{i + 1}} \textrangle \in E(G) for i[0,k)i \in [0, k).

In order for this walk to be a path, all viv_i's should be different, because if iji \neq j then vivjv_i \neq v_j.

A walk that begins and ends at the same vertex is called a closed walk.
A cycle is a closed walk where vertices are different except for the beginning and end vertices. Cycles must have a positive length.


What about a single vertex?

If a digraph has only one vertex, its length is zero, as it is considered to begin and end at itself. It is a closed walk as well, but since its length is not positive, it is not a cycle.

When is a walk not a walk?

An example: cb〉 〈ba〉 〈ad\textlangle{c \rightarrow b} \textrangle \ \textlangle{b \leftarrow a} \textrangle \ \textlangle{a \rightarrow d} \textrangle.
This is not considered a walk because its edges are in a wrong direction.


Just like your daily walk, we can also have rests during these walks, too. For example, if a walk ff ends at vertex vv, and a walk rr starts with this same vertex vv, their merge (denoted as f v ^r\textbf{f} \widehat{ \ v \ } \textbf{r} ) is the walk starting with ff, continuing with rr.

Note that the term merge does not really imply concatenation because the vertex vv would appear twice in such case.

The length of a merge is exactly as you thought it would be: the sum of those two walks: f v ^r=f+r|\textbf{f} \widehat{ \ v \ } \textbf{r}| = |\textbf{f}| + |\textbf{r}|.


We can represent a digraph using an adjacency matrix.
Simply, we put 11 where there is an edge between two vertices, and 00 otherwise.
Let AGA_G define the adjacency matrix of a graph GG:

(AG)ij={1if 〈vivjE(G),0otherwise.(A_G)_{ij} = \begin{cases} 1 \quad \text{if } \textlangle{v_i \rightarrow v_j} \textrangle \in E(G), \\ 0 \quad \text{otherwise.} \end{cases}

Let's use the diagram example we have at the start of this section.
Remember that its set of edges is E={(1, 2), (1, 3), (3, 2), (3, 4),(4, 3)}E = \{(1, \ 2), \ (1, \ 3), \ (3, \ 2), \ (3, \ 4), (4, \ 3)\}.
Its adjacency matrix will then look like this:

 1  2  3  4  1  0  1  1  0  2  0  0  0  0  3  0  1  0  1  4  0  0  1  0  \begin{array}{|c|c|c|c|c|} \hline & \ \textbf{1} \ & \ \textbf{2} \ & \ \textbf{3} \ & \ \textbf{4} \ \\ \hline \ \textbf{1} \ & \ 0 \ & \ 1 \ & \ 1 \ & \ 0 \ \\ \hline \ \textbf{2} \ & \ 0 \ & \ 0 \ & \ 0 \ & \ 0 \ \\ \hline \ \textbf{3} \ & \ 0 \ & \ 1 \ & \ 0 \ & \ 1 \ \\ \hline \ \textbf{4} \ & \ 0 \ & \ 0 \ & \ 1 \ & \ 0 \ \\ \hline \end{array}

One of the questions we can ask of a digraph is whether there is a walk from one vertex to another — in other words, whether they are connected, or whether one is reachable from the other.

We can denote this walk relation as:

u G v=there is a walk in G from u to vu \ G^* \ v = \text{there is a walk in } G \text{ from } u \text{ to } v

Also, a positive walk relation as:

u G+ v=there is a positive length walk in G from u to vu \ G^+ \ v = \text{there is a positive length walk in } G \text{ from } u \text{ to } v