Graph Theory Flashcards

1
Q

Formal definition of a graph

A

A graph G is a pair (V(G), E(G)) where V(G) is a nonempty set of vertices/nodes and E(G) is a set of unordered pairs {u, v} where u, v ∈ V(G) and u =/= v, indicating there is an edge between u and v

V(G) and E(G) are often written as V and E, and {u, v} is written as uv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Digraph

A

Directed graph - edges can have directions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Multi-graph

A

Multiple edges allowed between two vertices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Pseudo-graph

A

Edges of the form uu (loops) are allowed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Weighted graphs

A

Vertices and edges can have weights

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Neighbourhood of a vertex

A

N(v) is the set of neighbours of v, i.e. N(v) = {u ∈ V : uv ∈ E}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Degree of a vertex

A

deg(v) is the number of neighbours of v, i.e. the size of N(v)
δ(G) is the smallest degree in G
∆(G) is the largest degree in G
degree 0 = isolated vertex
degree 1 = end/pendant vertex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Subgraph

A

A subgraph G’ = (V’, E’) of G = (V, E) is a graph with V’ ⊆ V and E’ ⊆ E
It’s proper if G’ =/= G, and spanning if V’ = V (it has all the vertices of the original)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Induced subgraph

A

A subgraph that is made by just removing some vertices and their edges (no edges are removed unnecessarily)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Handshaking Lemma

A

In a graph G = (V, E): the sum of the degrees of the vertices is twice the number of edges

Proof: Every edge has two endpoints and contributes one to each of their degrees, so it contributes two to the sum of the degrees of the vertices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Path

A

Denoted by P_n, the graph with vertex set V = {v1, v2, …, v_n} and edge set E = {v1v2, v2v3, …, v_n-1 v_n}
Straight line of vertices
n-1 edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Cycle

A

Denoted by C_n
The same as P_n but with an extra edge linking v_n and v_1
n edges
Length = number of edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Complete bipartite graph

A

Denoted by K_p,q
A graph consisting of two sets of vertices (sizes p and q) connected in all possible ways (members of the same set are not connected)
pq edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Complete graph

A

Denoted by K_n
A graph which contains all the possible edges between pairs of vertices
0.5n(n-1) edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

n-dimensional hypercube

A

A graph whose vertex set is {0, 1}^n (2^n vertices), and with an edge between vertices x and y if and only if they differ in exactly one bit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Proof that an n-dimensional hypercube is bipartite

A

Let V1 contain all the vertices with an odd number of 1s
Let V2 contain all the vertices with an even number of 1s
This is a partition of V into two disjoint sets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Connected graph

A

Formal definition: Graph where any two vertices are connected by a path
Informal definition: A graph which is all in one piece, without any disconnected floating parts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an Eulerian circuit?

A

A circuit which traverses each edge exactly once and ends where it started

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a Hamiltonian cycle?

A

A cycle which visits each vertex exactly once and ends where it started

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Circuit vs cycle vs path

A

All types of walk
Path = Does not repeat vertices or edges
Cycle = Does not repeat vertices or edges, starts and ends on the same vertex
Circuit = Repeats vertices but not edges

Length = number of edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Eulerian circuit theorem

A

A connected graph with at least two vertices has an Eulerian circuit if and only if each of its vertices has an even degree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Using the TSP to detect Hamiltonian cycles

A

For each vertex v, create a city c_v
For each pair of distinct u, v ∈ V, set the distance between c_u and c_v to 1 if uv ∈ E, and 2 otherwise

If G has a Hamiltonian cycle, then it’s a route of cost n. This is because if there’s a route of cost n then it can’t use pairs with cost 2, so it must go through all edges of G.

Therefore the problem of finding a Hamiltonian cycle has been reduced to a TSP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Forests and trees

A

A forest is an acyclic graph (one without cycles)
A tree is a connected forest (i.e. a connected graph without cycles)

24
Q

Spanning trees

A

A subgraph of a graph is spanning if it has the same set of vertices

25
Q

Spanning trees theorem

A

Every connected graph contains a spanning tree (a spanning subgraph that is a tree)

26
Q

Proof of the spanning trees theorem

A

Let G be a connected graph
If G has no cycles, it is a tree and therefore a spanning tree of itself
If it has a cycle, we can remove an edge from this cycle and the new graph will still be connected. We can repeat this until all cycles are destroyed and we have a spanning tree.
Therefore trees are the smallest connected structures.

27
Q

Leaves in trees

A

A leaf is a vertex of degree 1

28
Q

Leaf lemma

A

Every tree on at least two vertices contains a leaf

29
Q

Proof of leaf lemma

A

By contradiction:
Assume that every vertex does not have degree 1
If a vertex has degree 0 then the graph is not connected and is therefore not a tree
If every vertex has degree 2+, then we can start at a vertex and go to one of its neighbours, and from there go to another neighbour until we encounter a vertex we’ve already visited. This implies that the graph contains a cycle and is therefore not a tree.

30
Q

Edges of trees theorem

A

A connected graph on n vertices is a tree if and only if it has n-1 edges

31
Q

What is a walk

A

A sequence of edges v0v1, v1v2, v2v3, …, v_n-1 v_n
v0, v1, …, v_n is also a walk in G
Closed walk = ends on the same vertex it started on

32
Q

Distance between vertices

A

The length of a shortest path from u to v if a path exists, infinity otherwise

33
Q

Diameter of a graph

A

Largest distance between two vertices

34
Q

What is a connected component

A

A connected subgraph which is not part of any larger connected subgraph. Every graph contains at least |V| - |E| connected components

35
Q

What does it mean if a directed graph G is weakly connected?

A

The graph obtained from G by removing directions is connected

36
Q

What does it mean if a directed graph G is strongly connected?

A

Any two distinct vertices are connected by directed paths in both directions

37
Q

What is a strongly connected component of a digraph?

A

A strongly connected subgraph which is not part of any larger strongly connected subgraph.

38
Q

Unique path lemma

A

If T is a tree containing two distinct points u and v, there is only one path between u and v
This is because if there were two paths, then those paths would form a cycle, which violates the definition of a tree

39
Q

What is a rooted tree

A

A tree in which one vertex is fixed as the root, and every edge is directed away from it.
If a vertex in a rooted tree has children, it’s an internal vertex

40
Q

Number of leaves in a tree on at least 2 vertices where at least n vertices have degree at least 3

A

n + 2

41
Q

Isomorphic graphs

A

Two graphs are isomorphic if there exists a bijective function f: V => V’ such that for every u, v ∈ V we have: uv ∈ E if and only if f(u)f(v) ∈ E’
Then we write: G ~= G’

Essentially this means that the vertices in G’ can be renamed to make it coincide with G

Isomorphic graphs share all their structural characteristics

42
Q

Isomorphism on rooted trees

A

In a rooted tree T with root r, the level L(i) is the set of vertices at distance i from the root r

43
Q

Determining if two rooted trees T1 and T2 are isomorphic

A

If r is a leaf of T1 then label it 10
Otherwise recurse into every child of r
Sort the labels of the children of r in decreasing order
Label the root “1” + all the labels of its children + “0”
Repeat this process for T2

44
Q

m-ary tree

A

A rooted tree where each internal vertex has at most m children. It is a full m-ary tree if each internal vertex has exactly m children.
2-ary trees = binary trees
A full m-ary tree with i internal nodes has n = mi + 1 vertices

45
Q

Balanced m-ary tree

A

All leaves in it have height h-1 or h

46
Q

Adjacency list of a graph

A

For each vertex v, list all the vertices adjacent to it

47
Q

Adjacency matrix of a graph

A

The entry in row i column j is 1 if vertex j shares an edge with vertex i, and 0 otherwise

48
Q

Breadth-first Search

A

Create a queue which contains vertices which have been discovered but are waiting to be processed. Colour the vertices: white = undiscovered, grey = discovered and unprocessed, black = processed
Create an array d (distance from source s). If we discover a new vertex v while processing u, set d[v] = d[u] + 1

Add source vertex to queue
While the queue is not empty, remove the first vertex from the queue (oldest), change it to black and add its white neighbours to the queue and distance array (also change them to grey)

49
Q

BFS analysis

A

Initialisation = O(V)
All queuing operations = O(V)
Each adjacency list is read once, their combined length is O(E)
Total running time is O(V+E)

50
Q

Breadth-first tree

A

All the edges used to discover other vertices. A path from s to another vertex v through the tree is the shortest path between s and v. We can build up this tree by recording all the predecessors as we do the BFS.

51
Q

Distance of two vertices in a graph

A

The length of the shortest path which connects them

52
Q

Depth-first search

A

DFS(G, n)
Mark n as grey (visited)
Increment time by 1
Time when n was discovered := time
For each white (unvisited) node n’ adjacent to n: add n’ to predecessor array, DFS(G, n’)
Mark n as black
Time when n was finished := time

53
Q

BFS vs DFS

A

BFS: searches layer-by-layer, computes shortest paths, removes the element which has been in S the longest (queue/FIFO)
DFS: digs deeper until no longer possible, removes the element which has been in S the shortest (queue/LIFO), mainly used for connectivity-type problems (i.e. reachability problems)

Both appropriate for graph exploration, linear time (very fast), list all vertices reachable from start vertex

54
Q

DFS analysis

A

Initialisation takes time O(V)
O(V) is spent on incrementing time, updating d and f, and colouring vertices
O(E) is spent considering each vertex in each adjacency list

Overall time = O(V+E)

55
Q

Depth-first forest

A

The predecessor subgraph, which has the same vertex set as the graph, is a depth-first forest

In the original graph:
- Tree edges are edges which are also in the DFS forest
- Back edges are edges that join a vertex to an ancestor
- Forward edges are edges not in the forest which join a vertex to its descendant
- Cross edges are all other edges

In an undirected graph, every edge is a tree edge or a back edge