Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 4

Special Graph Types: Bipartite, Complete, and Cyclic

Recommended resources

Welcome to the fourth lesson in our module on graph theory foundations. In our previous lesson, we examined the local properties of nodes and edges, such as degree and weights. Now, we'll zoom out to explore the global structure of graphs.

This lesson focuses on identifying several fundamental "archetypes" of graphs: complete, cyclic, and bipartite graphs. Recognizing these structures is crucial because they appear frequently in real-world problems and have unique properties that influence the design and behavior of graph algorithms, including Graph Neural Networks. For example, some GNN layers are specifically designed to work with bipartite graphs, which are common in recommendation systems.

Let's begin by looking at a gallery of these special graph types.

A collection of special graph structures, including some of the types we will discuss today: Path, Cycle, Star, Complete, Complete Bipartite, and others.

Complete Graphs: Maximum Connectivity

The simplest special graph type to consider is one where every possible connection exists. This is called a complete graph.

A complete graph on vertices, denoted , is a simple graph where every pair of distinct vertices is connected by a unique edge. Think of it as a network with maximum density, where everyone is directly connected to everyone else.

To see this in action, the following video provides a clear definition and shows what the first few complete graphs look like.

Discrete Math - 10.2.2 Special Types of Graphs

This video from Kimberly Brehm's Discrete Math series introduces complete graphs and their notation.

Please watch the first minute of the video, covering complete graphs. Notice how the number of edges grows rapidly as the number of vertices increases.

As you saw, is a triangle, is a square with its two diagonals, and so on. Given your data science background, you might recognize that the number of edges in is the same as the number of ways to choose 2 items from a set of , which is given by the combination formula:

This quadratic growth in edges relative to nodes makes large complete graphs very dense.


Cycles and Cyclic Graphs: Loops and Paths

Next, we'll look at graphs that contain closed loops, which are fundamental structures in graph theory. It's important here to distinguish between two related terms: cycle graphs and cyclic graphs.

A cycle graph, denoted , consists of a single cycle connecting vertices in a closed loop (where ). Each vertex has a degree of exactly 2. It's the most basic form of a closed network.

A cyclic graph, on the other hand, is any graph that contains at least one cycle. Therefore, every cycle graph is also a cyclic graph, but not all cyclic graphs are cycle graphs. For example, a complete graph is cyclic because it contains several subgraphs (triangles), but it is not a cycle graph itself.

This distinction is subtle but important. The following image and reading will help clarify it.

On the left is a Cycle Graph (\$C_4\$), which is a single closed loop. On the right is a Cyclic Graph, which contains a cycle (\$3 \to 1 \to 4 \to 3\$) but has additional edges and vertices not part of a single, all-encompassing loop.

Graph Theory - Types of Graphs

This resource from Tutorialspoint provides clear, separate definitions for cycle graphs and cyclic graphs.

Read the two short sections on Cycle Graph and Cyclic Graph. Pay close attention to how a "cycle graph" is a specific structure, while "cyclic graph" is a broader property.

Understanding cycles is essential for many algorithms. For instance, some algorithms only work on acyclic graphs (graphs with no cycles), such as trees. The presence of a cycle can mean that information can flow back to where it started, a key consideration for message passing in GNNs.


Bipartite Graphs: Two Sets of Nodes

The final category, bipartite graphs, is one of the most significant for machine learning applications.

A graph is bipartite if its vertices can be divided into two disjoint and independent sets, let's call them and , such that every edge connects a vertex in to one in . Crucially, no edge connects two vertices within the same set.

A classic real-world example is a user-item graph for a recommendation system. One set of nodes represents users (), and the other set represents items like movies or products (). An edge exists if a user has rated, viewed, or purchased an item. There are no edges connecting user-to-user or item-to-item directly in this model.

But how can you determine if an arbitrary graph is bipartite? The standard method is an algorithm called two-coloring. You attempt to "color" the graph with just two colors (say, blue and green) according to one rule: no two adjacent vertices can have the same color.

  • If you can successfully color the entire graph this way, it is bipartite. The two sets of vertices are simply all the blue nodes and all the green nodes.
  • If you find a contradiction—a situation where an edge connects two nodes that must have the same color—the graph is not bipartite.

The next video provides an excellent, detailed walkthrough of this process.

Discrete Math - 10.2.2 Special Types of Graphs

This segment from Kimberly Brehm's lecture explains the concept of bipartite graphs and demonstrates the two-coloring technique.

Please watch this detailed explanation from bipartite graphs and the coloring technique. The video works through one graph that is bipartite and another that is not, clearly showing how a contradiction arises in the second case.

As the video demonstrated, this coloring process is a simple but powerful way to test for bipartiteness. An interesting consequence you can prove with this technique is that a cycle graph is bipartite if and only if is even. An odd-length cycle will always create a coloring contradiction.

Just as we have complete graphs, we also have complete bipartite graphs, denoted . This is a bipartite graph with vertices in the first set and in the second, where every vertex in the first set is connected to every vertex in the second set.

The following short clip concludes the previous video by defining this type.

Discrete Math - 10.2.2 Special Types of Graphs

This final clip introduces the complete bipartite graph, which combines the properties of completeness and bipartiteness.

Watch the segment from this timestamp to understand the structure of K_{m,n}.


Conclusion

In this lesson, we classified graphs based on their high-level structure, identifying three important families. These structures are not just academic curiosities; they define the "shape" of data in many GNN applications and determine which algorithms are suitable.

Here are the key takeaways:

  • Complete Graph (): Every vertex is connected to every other vertex. It represents maximum density.
  • Cycle Graph () vs. Cyclic Graph: A cycle graph is a single closed loop. A cyclic graph is any graph that contains one or more cycles.
  • Bipartite Graph: The vertices can be partitioned into two sets where edges only connect vertices from different sets. They are common in matching and recommendation problems.
  • Two-Coloring: A simple and effective algorithm to test if a graph is bipartite.
  • Complete Bipartite Graph (): A bipartite graph with all possible connections between the two vertex sets.

So far, we have focused on describing graphs—their components and their overall structure. In our next lesson, we will begin to operate on them. We will learn about Breadth-First Search (BFS), a fundamental algorithm for systematically exploring a graph's vertices and edges.