Tutorials › Linear Algebra › Network Analysis Workshop: From Edge List to Laplacian

Applications in Networks, Economics and Data · Tutorial 961 of 1000

Network Analysis Workshop: From Edge List to Laplacian

Convert a weighted network’s edge list into matrices, then use their entries and the Laplacian to answer neighborhood and connectivity questions.

Intermediate 10 min read

What You'll Learn

  • Convert an undirected weighted edge list into an adjacency matrix in a specified vertex order.
  • Compute weighted degrees and form the degree and Laplacian matrices.
  • Read a vertex’s neighbors from its adjacency-matrix row.
  • Check connectivity from an edge list or by examining the Laplacian’s null space.
  • Explain why the Laplacian detects connected components using an energy identity.

From an Edge List to Matrices

A network can be recorded compactly as a list of its vertices and the weighted edges joining them. Matrices make the same information available to systematic calculations: an adjacency matrix records which pairs are connected and with what weights, a degree matrix records the total weight incident to each vertex, and the Laplacian combines the two. These representations are useful only when the vertex order and the meaning of each entry are kept explicit.

In this tutorial, a network is a finite, undirected graph with no loops. Every edge has a positive real weight, and each unordered pair of vertices appears at most once in the edge list. If an input lists the same pair more than once, combine those weights before building the matrices. Fix an order \(v_1,\dots,v_n\) of all vertices, including any isolated vertices. Two vertices are neighbors if an edge joins them.

Definition: The weighted adjacency matrix \(\mathbf{A}\in\mathbb{R}^{n\times n}\) has entry \(a_{ij}=w\) when an edge of weight \(w\) joins \(v_i\) and \(v_j\), and \(a_{ij}=0\) when there is no such edge. The weighted degree, also called the strength, of \(v_i\) is \(d_i=\sum_{j=1}^{n}a_{ij}\). The degree matrix is the diagonal matrix \(\mathbf{D}=\operatorname{diag}(d_1,\dots,d_n)\), and the (combinatorial) Laplacian is \(\mathbf{L}=\mathbf{D}-\mathbf{A}\).

Because the graph is undirected, \(a_{ij}=a_{ji}\), so \(\mathbf{A}\) is symmetric. The no-loops assumption gives \(a_{ii}=0\). A vertex’s number of neighbors is not generally the same as its weighted degree: the number counts adjacent vertices, whereas the weighted degree adds the incident edge weights. An isolated vertex has a zero row and column in \(\mathbf{A}\), and its diagonal entry in \(\mathbf{D}\) is zero.

To build the matrices, choose and keep one vertex order, place each edge weight in both corresponding off-diagonal positions of \(\mathbf{A}\), and leave all other entries zero. Then add each row of \(\mathbf{A}\) to obtain its weighted degree, place those degrees on the diagonal of \(\mathbf{D}\), and subtract \(\mathbf{A}\) from \(\mathbf{D}\). The following example shows every entry.

Worked Example: Build the Three Matrices

Use the vertex order \(A,B,C,D\) and the edge list \(AB\) of weight \(2\), \(AC\) of weight \(1\), \(BC\) of weight \(3\), and \(CD\) of weight \(4\). Each listed edge contributes its weight to two symmetric positions in \(\mathbf{A}\). Thus

$$ \mathbf{A}= \begin{bmatrix} 0&2&1&0\\ 2&0&3&0\\ 1&3&0&4\\ 0&0&4&0 \end{bmatrix}. $$

Summing each row gives the weighted degrees \(d_A=0+2+1+0=3\), \(d_B=2+0+3+0=5\), \(d_C=1+3+0+4=8\), and \(d_D=0+0+4+0=4\). Therefore

$$ \mathbf{D}= \begin{bmatrix} 3&0&0&0\\ 0&5&0&0\\ 0&0&8&0\\ 0&0&0&4 \end{bmatrix}, \qquad \mathbf{L}=\mathbf{D}-\mathbf{A}= \begin{bmatrix} 3&-2&-1&0\\ -2&5&-3&0\\ -1&-3&8&-4\\ 0&0&-4&4 \end{bmatrix}. $$

Check: Multiplying \(\mathbf{A}\) by the all-ones column gives \(\mathbf{A}(1,1,1,1)^{\top}=(3,5,8,4)^{\top}\), the degree list. Subtracting the displayed \(\mathbf{A}\) from \(\mathbf{D}\) gives the displayed \(\mathbf{L}\), and \(\mathbf{L}(1,1,1,1)^{\top}=(0,0,0,0)^{\top}\). The edge list also appears symmetrically in \(\mathbf{A}\): for example, \(a_{CD}=a_{DC}=4\), and \(a_{BD}=a_{DB}=0\).

Reading Neighbors and Checking Connectivity

Once the vertex order is fixed, row \(i\) of \(\mathbf{A}\) gives the weights of the edges incident to \(v_i\). Its nonzero positions identify the neighbors, and the corresponding values give the edge weights. In the first example, row \(C\) is \((1,3,0,4)\): \(C\) is adjacent to \(A\), \(B\), and \(D\), with weights \(1\), \(3\), and \(4\). Its weighted degree is their sum, \(8\), while it has three neighbors.

A graph is connected if every pair of vertices can be joined by a path of edges; otherwise it is disconnected. Edge weights do not change this definition here: every listed edge has positive weight, so connectivity depends on whether an edge exists, not on its numerical weight. For example, in the first network, \(A\) connects to \(B\) and \(C\), and \(C\) connects to \(D\). Hence every vertex can be reached from \(A\), so the network is connected.

Theorem (Laplacian energy identity): For a finite undirected graph with positive edge weights, let \(\mathbf{L}=\mathbf{D}-\mathbf{A}\). For every \(\mathbf{x}=(x_1,\dots,x_n)^{\top}\in\mathbb{R}^n\), $$ \mathbf{x}^{\top}\mathbf{L}\mathbf{x} = \sum_{\{i,j\}\text{ an edge}} a_{ij}(x_i-x_j)^2, $$ where each unordered edge is included once in the sum.

Proof. Since \(\mathbf{D}\) is diagonal, \(\mathbf{x}^{\top}\mathbf{D}\mathbf{x}=\sum_{i=1}^n d_i x_i^2\). Each edge \(\{i,j\}\) of weight \(a_{ij}\) contributes \(a_{ij}x_i^2\) to this sum through \(d_i\), and contributes another \(a_{ij}x_j^2\) through \(d_j\). Because the graph is undirected, \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}=\sum_{i,j}a_{ij}x_ix_j\); the edge \(\{i,j\}\) contributes \(2a_{ij}x_ix_j\), once from each of the two symmetric positions. There are no loop contributions. Subtracting the adjacency expression from the degree expression therefore gives, edge by edge, \(a_{ij}x_i^2+a_{ij}x_j^2-2a_{ij}x_ix_j=a_{ij}(x_i-x_j)^2\). Summing over the edges proves the identity. \(\square\)

Theorem (Laplacian null space and connectivity): For a finite undirected graph with positive edge weights, \(\mathbf{L}\mathbf{x}=\mathbf{0}\) holds exactly when the entries of \(\mathbf{x}\) are constant on each connected component. In particular, the graph is connected if and only if every solution of \(\mathbf{L}\mathbf{x}=\mathbf{0}\) is a constant vector.

Proof. Suppose first that \(\mathbf{L}\mathbf{x}=\mathbf{0}\). Then \(\mathbf{x}^{\top}\mathbf{L}\mathbf{x}=0\). By the energy identity, this is a sum of terms \(a_{ij}(x_i-x_j)^2\). Every edge weight is positive and every square is nonnegative, so a zero sum forces \(x_i=x_j\) across every edge. Along any path, equality carries from one vertex to the next; therefore the entries are constant on each connected component.

Conversely, suppose the entries of \(\mathbf{x}\) are constant on each connected component. In row \(i\) of \(\mathbf{L}\mathbf{x}\), the result is \(\sum_{j:\{i,j\}\text{ an edge}}a_{ij}(x_i-x_j)\). Each neighbor \(j\) lies in the same component as \(i\), so \(x_i-x_j=0\) for every term. Thus every row gives zero and \(\mathbf{L}\mathbf{x}=\mathbf{0}\). If the graph is connected, it has one component, so the solutions are exactly the constant vectors. If it is disconnected, assign value \(1\) on one component and \(0\) on another; this is a nonconstant vector that is constant on each component and hence solves \(\mathbf{L}\mathbf{x}=\mathbf{0}\). This proves both directions of the connectivity statement. \(\square\)

This result gives a matrix-based test in principle: inspect the solutions of \(\mathbf{L}\mathbf{x}=\mathbf{0}\). In a small network, it is often quicker to trace paths directly from the edge list or to inspect the nonzero pattern of \(\mathbf{A}\). The theorem explains why the Laplacian carries the same component information: vectors in its null space may choose one constant value per component, but cannot vary across an edge.

Worked Example: Identify Components with the Laplacian

Take vertices \(1,2,3,4\) in that order, with edges \(12\) of weight \(2\) and \(34\) of weight \(5\). The adjacency matrix, weighted degrees, and Laplacian are

$$ \mathbf{A}= \begin{bmatrix} 0&2&0&0\\ 2&0&0&0\\ 0&0&0&5\\ 0&0&5&0 \end{bmatrix}, \qquad (d_1,d_2,d_3,d_4)=(2,2,5,5), $$
$$ \mathbf{L}= \begin{bmatrix} 2&-2&0&0\\ -2&2&0&0\\ 0&0&5&-5\\ 0&0&-5&5 \end{bmatrix}. $$

The edge list shows two components: \(\{1,2\}\) and \(\{3,4\}\). The Laplacian equations are \(2x_1-2x_2=0\), \(-2x_1+2x_2=0\), \(5x_3-5x_4=0\), and \(-5x_3+5x_4=0\). They reduce to \(x_1=x_2\) and \(x_3=x_4\), with no equation requiring the two component values to agree. For instance, \(\mathbf{x}=(7,7,-2,-2)^{\top}\) satisfies \(\mathbf{L}\mathbf{x}=\mathbf{0}\).

Check: Multiplication gives first coordinate \(2(7)-2(7)=0\), second coordinate \(-2(7)+2(7)=0\), third coordinate \(5(-2)-5(-2)=0\), and fourth coordinate \(-5(-2)+5(-2)=0\). The nonconstant solution agrees with the theorem’s conclusion that this graph is disconnected.

Extracting a Local Neighborhood

Worked Example: Find One Vertex’s Neighbors

Return to the first network and ask for the neighbors of \(B\), their edge weights, the number of neighbors, and the weighted degree. The \(B\)-row of \(\mathbf{A}\), in the order \(A,B,C,D\), is \((2,0,3,0)\). The nonzero entries are in positions \(A\) and \(C\), so \(B\)'s neighbor set is \(\{A,C\}\), with weights \(2\) and \(3\). It has two neighbors, and its weighted degree is \(2+3=5\).

Check: The \(B\)-diagonal entry of \(\mathbf{D}\) is \(5\), agreeing with the sum of row \(B\) of \(\mathbf{A}\). The Laplacian row is \((-2,5,-3,0)\), whose entries also sum to \(-2+5-3+0=0\).

Common Mistake: Forgetting the Undirected Pair

A common error is to enter an undirected edge in only one position of \(\mathbf{A}\). For the edge \(AB\) of weight \(2\), a mistaken entry \(a_{AB}=2\) with \(a_{BA}=0\) makes the matrix asymmetric. It also makes the row sums disagree with the intended weighted degrees: vertex \(B\) would appear to receive no weight from \(A\). The correction is to enter both \(a_{AB}=2\) and \(a_{BA}=2\), then sum each complete row.

A second check catches errors early: every row sum of \(\mathbf{A}\) must equal the corresponding diagonal entry of \(\mathbf{D}\). Consequently, every row sum of \(\mathbf{L}=\mathbf{D}-\mathbf{A}\) is zero. In an undirected, loop-free weighted graph, \(\mathbf{A}\) and \(\mathbf{L}\) must also be symmetric. These checks do not replace careful construction, but they expose many misplaced or omitted entries.

Check Your Understanding

Use the vertex order given in each question, and show how the matrix entries follow from the edge list.

  1. For vertices \(P,Q,R\) and edges \(PQ\) of weight \(3\), \(QR\) of weight \(2\), write \(\mathbf{A}\), \(\mathbf{D}\), and \(\mathbf{L}\).
  2. In the network from Question 1, state the neighbors of \(Q\), their edge weights, and its weighted degree.
  3. For vertices \(1,2,3\) with only edge \(13\) of weight \(4\), identify the connected components and explain how vertex \(2\) appears in \(\mathbf{A}\) and \(\mathbf{D}\).
  4. Explain why a nonconstant solution of \(\mathbf{L}\mathbf{x}=\mathbf{0}\) shows that the graph is disconnected, under the positive-weight assumptions.
  5. Give two matrix checks that can reveal an incorrectly constructed adjacency or Laplacian matrix.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon