Graph Algorithms

Can represent with an adjacency list or matrix.

Touching every vertex and edge is $O(|V|+|E|)$.

For an undirected graph, the maximum number of edges on $n$ nodes is: $\dfrac{n(n-1)}{2} = O(n^2)$.

Definition: A graph is dense if $|E| = O(n^2)$. A graph is sparse if $|E| = O(n)$.

Definition: A cycle of size $k$ is a sequence of connected nodes where all nodes are distinct (except for the last node), and the first node is the same as the last node.

Definition: A undirected graph is a tree if it connected and has no cycles.

Definition: A rooted tree is a tree with a special node called root.

Definition: An implicitly represented graph has a polynomial time algorithm that given a name of a node, outputs its adjacency list.

Definition: A weighted graph $(V,E)$ has a function $f: E \to \mathbb{E}$.

Traversal of Undirected Graphs

Bipartite Graphs

Definition: A graph is bipartite if all nodes are colored red or black such that there are no edges between the same colored nodes.

Observation: We cannot color any odd cycle red-black.

How do we color a bipartite graph red-black or find an odd length cycle?

Do a breadth first search, coloring red then black. If there is an edge between two edges on the same level, there is an odd length cycle (go to level in $n$ steps, go another node on the same level in $1$ step, go back to root in $n$ steps—that is an odd number of edges).