Graph Theory

See disclaimer about the slides.
See learning objectives and sources.

Graph (definition)

A graph is a pair $(V,E)$, where $V$ is a set of elements called vertices, nodes, or points and $E$ is a set of pairs of vertices called edges or arcs.

Graph (example)

Pictorial representation:

undirect_graph_7.jpg

Component representation: $(\{a,b,c,d\},\{\{a,c\},\{a,d\},\ldots \{d,c\}\})$.
The edges are not ordered, hence are represented as sets.

Graph (example)

directed_graph_7.jpg

Variations

Edges can be directed or undirected.
Edges can be weighted.
Edges can cycle.

Notions

Adjacent nodes.
Initial and terminal node of an edge.
Edge incident to and from a node.
Degree of a vertes, isolated (0), pendant (1).
In-degree $deg^-(v)$ and out-degree $deg^+(v)$ of a node $v$.
Show these concepts on the above graph during the lecture.

Some Theorems

$(V,E)$ is an undirected graph: $2|E| = \sum_{v \in V} deg(v)$. (Handshaking)

An undirected graph has an even number of odd degree vertices.

$(V,E)$ is a directed graph: $\sum_{v \in V} deg^-(v) = \sum_{v \in V} deg^+(v) = |E|$.

Special Graphs

$n$-cube, complete, bipartite.

Representation

Adjiacency matrix

Marginal entries are the nodes.
Tabular entries are the arcs (0/1, count, weight) between nodes.

adjiacency_7.jpg

Incidence matrix

Marginal Column are the nodes.
Marginal row are the arcs.
Tabular entries are ''incidence'' of arc to node.

incidence_7.jpg

Adjiacency list

Every node stores a list of adjiacent nodes.
Compute it for the above graph during the lecture.

Graph isomorphism

$G_1=(V_1,E_1)$ and $G_2=(V_2,E_2)$ are graphs.
$G_1$ and $G_2$ are isomorphic iff there exists bijections $f : V_1 \to V_2$ and $g : E_1 \to E_2$ such that $g((v,w))=(f(v),f(w))$.
If two graphs are isomorphic you can rename nodes and arcs of one to get the other.
Find a (planar = no edge crossing) graph isomorphic to the first example.

Paths and Circuits

Path: a sequence of nodes $v_0,v_1,\ldots,v_n$ such that $(v_{k-1},v_k)$ is an arc.
Circuit: path with $v_0=v_n$.
Simple: path that does not repeat any arc.
Connected graph: there is a path betwen any two nodes.
Euler path/circuit: traverses every arc exactly once.
Has circuit iff connected and every node has even degree.
Hamilton path/circuit: contains every node exactly once.
Example: Traveling Salesperson Problem Hamilton circuit of minimum length.

Shortest Path

The problem: find the shortest path from any given vertex to some other vertex in a connected weighted graph.
Symbols: $w$ weights of edges, $a$ origin vertex, $z$ destination vertex, $L$ shortest distance.

dijkstra_7.jpg

execution trace
execution animation

Using graphs

Solve games/puzzles, e.g., missionaries and cannibals, tic-tac-toe.
Maze generation.
Travelling salesman.

Binary relations

A directed graph defines a binary relation on a set and vice versa.
Properties are easier to see on a graph and closures easier to compute.

Spanning trees

Traversal: list all nodes only once.

graph_traversal_7.png

Depth-first: go as far as possible, come back to last choice, take another path. Result: $ABDFECG$.
Breadth-first: all 1 step, all 2 steps, all 3 steps ... Result: $ABCEDFG$.
animations.

Minimal spanning tree

Prim (greedy): add cheapest edge from tree so far to outside nodes. animation.
Kruskal: add cheapest edge to bridge disconnected subtrees. animation (disregard the code).

min-span-tree_7.png