Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Link analysis and community structure

Link analysis studies edges and their importance (e.g., edge betweenness, cuts) while community structure finds groups of nodes more connected internally than to the rest (e.g., modularity, Girvan–Newman, Louvain).

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Link analysis and community structure help engineers find groups (communities) and important connections in networks: detect clusters of users, spot bridges whose removal disconnects groups, speed up search and recommendation, and analyse resilience. You use these in social media analytics, recommender systems, fraud detection, and graph partitioning for parallel processing.

Key ideas

Start from the graph fundamentals. A graph G = (V, E) is a set V of nodes (vertices) and a set E of edges (unordered pairs for undirected graphs). An edge (u, v) connects nodes u and v. The degree k_i of node i is the number of edges incident to i (for undirected graphs). The total number of edges is m = |E|.

A community (also called cluster or module) is a set of nodes that are more densely connected to each other than to nodes outside the set. This is an intuitive definition — formal measures are needed to score partitions.

A cut between two node sets S and T is the set of edges with one endpoint in S and the other in T. The size of a cut is the number of such edges. The conductance of a set S (a standard quality score) is phi(S) = (# edges leaving S) / min(sum of degrees in S, sum of degrees in V \ S). Low conductance means well-separated community.

Modularity (Newman--Girvan modularity) is the most-used global quality function to score a partition of the graph. It compares the actual fraction of edges inside communities to the fraction expected under a random-graph null model that preserves node degrees (configuration model). Formally:

  • For undirected graphs with m edges and node degrees k_i, the expected number of edges between i and j in the null model is (k_i * k_j) / (2m). Modularity Q of a partition {C} is Q = (1 / 2m) * sum_{i,j} [A_{ij} - (k_i * k_j)/(2m)] delta(c_i, c_j), where A_{ij} is the adjacency (1 if edge between i and j, else 0), c_i is i's community, and delta is 1 when c_i = c_j, else 0. Assumptions: undirected, unweighted; for weighted graphs replace A_{ij} by w_{ij}, k_i by node strength s_i, and 2m by 2W (total weight); for directed graphs replace degrees by out-/in-degrees and use expected edges (k_i^{out} k_j^{in})/m; null model preserves degree/strength sequence.

Common algebraic rearrangement (useful in exams): let L_c be the number of edges wholly inside community c (each undirected edge counted once), and K_c = sum_{i in c} k_i the sum of degrees in c. Then modularity can be written as: Q = sum_c [L_c / m - (K_c / (2m))^2]. This form is derived by replacing the double-sum over i,j by sums per community and using S_c = sum_{i,j in c} A_{ij} = 2 L_c. This expression is convenient to compute Q from community edge counts and degree sums.

Edge betweenness centrality: the edge betweenness b(e) of an edge e is the sum over all unordered node pairs s,t of the fraction of shortest s–t paths that pass through e. Formally, b(e) = sum_{s<t} (sigma_{s,t}(e) / sigma_{s,t}), where sigma_{s,t} is the number of shortest paths between s and t, and sigma_{s,t}(e) is how many of those pass through e. The Girvan–Newman algorithm uses edge betweenness to find community boundaries: repeatedly compute edge betweenness, remove the edge(s) with largest betweenness, and recalculate until the graph splits into components.

Limitations and resolution: modularity optimization has a known resolution limit — it can fail to detect small communities when the graph is large. Also, maximizing modularity is NP-hard; practical methods use greedy heuristics (Louvain), spectral methods, or hierarchical divisive approaches (Girvan–Newman). Expect algorithms to give approximate or different results on the same graph.

Diagrams to draw in answers (describe exactly):

  • For the worked examples use a 6-node diagram: draw two triangles side by side. Label left triangle nodes 1,2,3 with edges (1-2),(2-3),(3-1). Label right triangle nodes 4,5,6 with edges (4-5),(5-6),(6-4). Draw a single bridge edge (3-4). Put node labels next to each vertex and clearly show all edges.

Formulas

m = |E| — total number of edges, unitless. Applies to any simple graph. k_i = degree(i) — number of edges incident on node i, unitless. Q = (1 / (2m)) * sum_{i,j} [A_{ij} - (k_i * k_j)/(2m)] * delta(c_i, c_j) — modularity. A_{ij} is 1 (edge) or 0 (no edge). Units: dimensionless, applies to undirected graphs with degree-preserving null model. Q = sum_c [L_c / m - (K_c / (2m))^2] — modularity per community (L_c = # internal edges, K_c = sum degrees in c). Dimensionless. b(e) = sum_{s < t} sigma_{s,t}(e) / sigma_{s,t} — edge betweenness centrality (sum over unordered pairs). Dimensionless. conductance(S) = cut_edges(S, V\S) / min(sum_deg(S), sum_deg(V\S)) — conductance of set S, dimensionless. PageRank: p = alpha * P^T * p + (1 - alpha) * v — for a directed graph; P is the column-stochastic transition matrix (with dangling-node handling), 0 < alpha < 1 is damping, v is the teleport vector (often uniform), and sum_i p_i = 1. Dimensionless. HITS: a ∝ A^T h, h ∝ A a — authority vector a and hub vector h are the principal eigenvectors of A^T A and A A^T, respectively; normalize per iteration. Dimensionless.

Worked examples

Example 1 — compute modularity for the two-triangle graph (exact steps):

  1. Draw and label nodes 1..6 as described. Count edges: two triangles give 3+3 = 6 internal edges, plus bridge (3-4) gives m = 7.
  2. Choose partition C1 = {1,2,3}, C2 = {4,5,6}.
  3. For C1: L_1 = number of edges inside C1 = 3 (triangle). K_1 = sum degrees = k1+k2+k3 = 2+2+3 = 7 (nodes 1 and 2 degree 2, node 3 degree 3 because it has the bridge). For C2: L_2 = 3, K_2 = 3+2+2 = 7.
  4. Use formula Q = sum_c [L_c / m - (K_c / (2m))^2]. Compute L_1 / m = 3 / 7 ≈ 0.428571. Compute (K_1 / (2m))^2 = (7 / 14)^2 = (0.5)^2 = 0.25. Contribution of C1 = 0.428571 - 0.25 = 0.178571. Same for C2. So Q = 2 * 0.178571 = 0.357142 ≈ 0.3571.
  5. Final answer: Q ≈ 0.3571. This is positive, so the partition is better than the degree-preserving random null model.

Example 2 — Girvan–Newman on the same graph (step-by-step, exam style):

  1. Compute edge betweenness conceptually: every shortest path between any node in {1,2,3} and any node in {4,5,6} must pass through the bridge edge (3-4). There are 3 × 3 = 9 unordered pairs across the two groups, and each pair has a unique shortest path that uses (3-4), so the bridge edge has betweenness exactly 9. Internal triangle edges have much smaller betweenness.
  2. Remove edge (3-4) first (largest betweenness). The graph splits into two connected components {1,2,3} and {4,5,6} immediately.
  3. If you measure modularity of the resulting partition you get the Q from Example 1. Thus GN successfully found the natural split by removing the inter-community bridge.

Note: In an exam you may be asked to compute exact edge-betweenness values for each edge by enumerating all shortest paths; for this small graph you can enumerate pairs and count paths to show the bridge has the highest value.

Common mistakes

  • Using directed-formula when graph is undirected (or vice versa) without adjusting definitions.
  • Thinking Girvan–Newman always gives best community split — it is greedy and can be slow (naively O(n m^2) overall for unweighted graphs, since recomputing betweenness is O(n m) and done after many removals) and re-computes betweenness after each removal.
  • Ignoring the resolution limit of modularity: small communities can be merged incorrectly when maximizing Q.
  • Mixing ordered and unordered pairs in betweenness counts. State clearly which convention you use.

For your exam

Question types you will see: definitions (define modularity, edge betweenness, cut, conductance, PageRank, HITS), short notes (compare modularity and conductance, strengths and weaknesses), derivations (derive the alternative modularity formula from the double sum), numericals (compute Q for small graphs, compute conductance, compute PageRank on a small directed graph, compute HITS hub/authority scores), algorithms (describe Girvan–Newman or Louvain steps and complexity), diagrams (draw small graphs and label edges to show cuts). A full-marks answer usually includes:

  • Precise definitions with symbols (e.g., state m, k_i, A_{ij}).
  • Step-by-step algebra for derivations; show where factors 2 or 1/2m appear.
  • Correct diagram with labels when asked; label nodes and edge counts used in calculations.
  • Final numerical answers with intermediate steps and explanations.

Quick check

  1. What is the null model used in modularity (brief)?
  2. Give the modularity formula in the per-community form using L_c and K_c.
  3. In Girvan–Newman, which edges are removed first and why? Answers: 1) Degree-preserving random graph (configuration model). 2) Q = sum_c [L_c / m - (K_c / (2m))^2]. 3) Edges with highest edge betweenness (they lie on many shortest paths), because they likely connect communities.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?