Skip to main content

Graph Connectivity

Path

A path is a sequences of vertices [v1,v2,v3,,vj][v_1, v_2, v_3,\dots, v_j] such that:

  • No vertex appears more than once.
  • vkv_k is adjacent to vk+1v_{k+1}. for each k=1j1k = 1 \dots j-1.
  • The length of the path is j1j-1 which is the number of edges.
Example

path example

  • A,D,C,BA,D,C,B is a path of length 3.
  • A,CA,C is a path of length 1.
  • D,C,AD,C,A is a path of length 2.

Cycle

A cycle is just like a path, but v1=vjv_1 = v_j, so that it loops back on itself.

  • The length of a cycle is j1j-1, which is the number of edges, and also the number of vertices.
  • We don't care about the starting vertex of a cycle. So A,B,C,AA,B,C,A is the same cycle as B,C,A,BB,C,A,B.
  • We might not use the above notation (duplicate the start/end vertex) to represent a cycle. Instead we will use "cycle A,B,CA,B,C". Note: this is different from path, path can be represented by "path A,B,CA,B,C".
Example

cycle example

  • A,D,C,AA,D,C,A is a cycle of length 3.

Connectedness

If there is a path from uu to vv for every u,vVu,v \in V, then we say that GG is connected. Otherwise, we say GG is disconnected.

Example

connected component example

The graph is connected.

Connected Component

If for every u,vSVu,v \in S \subseteq V there is a path between uu and vv, and there are no paths to any vertices outside SS.

Then we call SS is a connected component of GG.

Example

disconnected graph example

The graph is disconnected.

The connected components are {B}\{B\} and {A,C,D}\{A,C,D\}

Distance

The distance between vertices uu and vv is the length of a shortest path from uu to vv.

Calculating Distances

Given a fixed vertex uu, we define:

  • DjD_j to be the set of vertices that is jj distance from uu. (explored)
  • VjV_j to contain the set of vertices that has distance at least jj from uu. (unexplored)
Vj={V:j=0Vj1Dj1:j>0V_j= \begin{cases} V & :j=0 \\ V_{j-1} \setminus D_{j-1} & :j>0 \end{cases}
Dj={{u}:j=0NG(Vj,Dj1):j>0 D_j= \begin{cases} \{u\} & :j=0 \\ N_G(V_j, D_{j-1}) & :j>0 \end{cases}

The visualization of the graph can be found here.

_assets-07/distance_classes.py
def distance_classes(V:set, E:set, u):
"""
V: a set of vertices.
E: a set of edges.
u: the starting vertex.

return: A list D. The vertices in D[1] is 1 distance from u.
"""
D = [{u}]
V_unexplored = V - {u}

return distance_classesR(V_unexplored, E, D)

def distance_classesR(V,E, D):
V_unexplored = V - D[-1]
if len(V_unexplored) == 0:
return D
D_new = NS(V_unexplored, E, D[-1])
D = D + [D_new]
return distance_classesR(V_unexplored, E, D)

def NS(V,E,S):
return {v for u in S for v in V if (u,v) in E}

V = {"A", "B", "C", "D", "E"}
E = {
("A","B"),("B","A"),
("A","C"),("C","A"),
("B","C"),("C","B"),
("B","D"),("D","B"),
("D","E"),("E","D")
}
print(distance_classes(V,E, "A"))
# [{'A'}, {'C', 'B'}, {'D'}, {'E'}]

Bipartite Graph

If we are able to separate/partition vertices into two sets (A,B)(A,B) such that vertices within each set are not adjacent, then we call (A,B)(A,B) a bipartition of GG.

Theorem

A graph GG is bipartite iff GG has no cycles of odd length.

What is a Bipartite Graph? | Graph Theory

Vocabulary

Cannot find definitions for "bipartite".

References