Graph concepts: ties, density, paths and centrality
Basic graph concepts for social networks: definitions of ties, graph density, paths (walk/trail/path/geodesic), and centrality measures (degree, closeness, betweenness, eigenvector) with formulas, derivations and worked exam-style examples.
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
Social networks are modeled as graphs. Engineers use ties, density, paths and centrality to (1) measure how connected a system is (useful for routing, information spread, fault analysis) and (2) identify important nodes (useful for recommendation, caching, influence or vulnerability analysis).
Key ideas
Start from the basic object: a graph G = (V, E) where V is the set of nodes (also called vertices) and E is the set of edges (also called ties). We assume a simple graph (no parallel edges and no self-loops) and note differences for directed or weighted graphs where relevant.
- Node (vertex): an entity in V. Define before using.
- Edge (tie): an unordered pair {u, v} ∈ E in an undirected graph, representing a relation between nodes u and v.
- Directed edge: an ordered pair (u, v) if the relation has direction.
- Strong tie / Weak tie: informal social terms. A strong tie means frequent, reciprocal interactions (close friendship); a weak tie means less frequent or less intense interaction. In network models we represent strength as an edge weight; if no weight is given, treat ties as equal.
Handshake lemma (exact statement and derivation):
- Statement: In any undirected graph G = (V, E), the sum of degrees of all nodes equals twice the number of edges: Σ_{v∈V} deg(v) = 2|E|.
- Assumptions: undirected graph, simple or with multiple edges; with self-loops, count each loop as contributing 2 to degree, and the statement still holds counting multiplicity.
- Derivation (step-by-step): each undirected edge {u, v} contributes 1 to deg(u) and 1 to deg(v), so each edge contributes 2 to the sum of degrees. Summing over all edges gives 2|E|. For directed graphs, Σ_v outdeg(v) = Σ_v indeg(v) = |E|.
Density (definition and derivation):
- Density ρ of an undirected simple graph with n = |V| and m = |E| is the fraction of possible edges that exist. Maximum possible edges is n(n−1)/2. Therefore ρ = m / [n(n−1)/2] = 2m / [n(n−1)]. Assumes simple undirected graph without self-loops. For a simple directed graph without self-loops, the maximum is n(n−1), so ρ = m / [n(n−1)].
Walks, trails, paths, cycles, geodesics:
- Walk: a sequence of nodes where consecutive nodes are connected by edges; nodes/edges may repeat.
- Trail: a walk with no repeated edges.
- Path (simple path): a walk with no repeated vertices (hence no repeated edges). Universities often call a simple path just a "path".
- Cycle: a closed walk with all vertices distinct except that the first equals the last; length ≥ 3.
- Geodesic / shortest path: a path between u and v with minimum number of edges (or minimum total weight in weighted graphs).
Connectedness, diameter, average path length:
- Connected graph: for every pair u, v ∈ V there is a path between them (in undirected graphs). For directed graphs: strongly connected means a directed path from u to v and v to u for all u, v; weakly connected means the underlying undirected graph is connected.
- Connected component: a maximal connected subgraph.
- Eccentricity of v: the maximum shortest-path distance from v to any other node (within the same component; in a disconnected graph, eccentricity may be taken as ∞).
- Diameter: max eccentricity over all nodes (the longest shortest-path in the graph).
- Average path length (for connected graph): average of shortest-path distances over all unordered pairs.
Centrality measures (definitions, assumptions and exact formulas given in Formulas section):
- Degree centrality: centrality proportional to node degree; normalized by n−1 for undirected graphs.
- Closeness centrality: based on inverse of total distance from node to others; normalized forms differ—use (n−1)/Σ distances for connected graphs.
- Betweenness centrality: fraction of shortest paths between all pairs that pass through the node. Assume shortest paths are counted; for ties distribute counts equally.
- Eigenvector centrality: importance proportional to the importance of neighbors; leads to eigenvector equation A x = λ x where A is adjacency matrix. Assumes non-negative adjacency matrix and Perron–Frobenius conditions for a unique positive principal eigenvector.
Diagrams to draw (exam style):
- To illustrate definitions and compute measures, draw 5 nodes labelled A, B, C, D, E. Place A, B, C close to form a triangle (A–B, B–C, A–C). From C connect to D, and from D connect to E (chain). Label each node with its letter and draw edges accordingly. This diagram is enough to compute degrees, shortest paths, density and centralities.
Formulas
m = |E| — m is number of edges, unit: dimensionless, applies to any graph.
n = |V| — n is number of nodes, unit: dimensionless.
Σ_{v∈V} deg(v) = 2m — handshake lemma; deg(v) is degree of v; applies to undirected graphs.
density ρ = 2m / (n·(n−1)) — ρ ∈ [0,1], unit: dimensionless, applies to simple undirected graphs without self-loops.
d(u,v) — shortest-path distance (number of edges for unweighted graphs) between nodes u and v; unit: hops (dimensionless).
diameter = max_{v∈V} max_{u∈V} d(u,v) — maximum shortest-path length; unit: hops. average_path_length L = (2/(n(n−1))) · Σ_{u<v} d(u,v) — for connected graphs; unit: hops.
degree_centrality(v) = deg(v) / (n−1) — normalized degree; unit: dimensionless; for undirected graphs.
closeness_centrality(v) = (n−1) / Σ_{u≠v} d(v,u) — normalized closeness for connected graphs; unit: dimensionless.
betweenness_centrality(v) = Σ_{s≠v≠t} [σ_{st}(v) / σ_{st}] — raw betweenness; σ_{st} is number of shortest paths between s and t, σ_{st}(v) is number of those that pass through v. Unit: dimensionless.
normalized_betweenness(v) = betweenness(v) / ((n−1)(n−2)/2) — for undirected graphs; unit: dimensionless.
eigenvector centrality: x satisfies A x = λ x — A is adjacency matrix, x is centrality vector (principal eigenvector), λ is largest eigenvalue. Unit: dimensionless. Assumes A ≥ 0 and that the graph is connected (undirected) or strongly connected (directed) so Perron–Frobenius guarantees a unique positive principal eigenvector.
Worked examples
Example 1 — compute density and degrees (numerical, exam-style) Graph: nodes A,B,C,D,E (n = 5). Edges: A–B, A–C, B–C, C–D, D–E (m = 5). Steps:
- Write n = 5, m = 5.
- Use formula
ρ = 2m / (n(n−1)). ρ = 2·5 / (5·4) = 10 / 20 = 0.5. Final answer: Density ρ = 0.5 (dimensionless). Also degrees: deg(A)=2, deg(B)=2, deg(C)=3, deg(D)=2, deg(E)=1.
Example 2 — compute degree, closeness and betweenness centralities for the same graph Steps (show all arithmetic):
- Degree centrality (normalized): degree / (n−1) where n−1 = 4.
- A: 2/4 = 0.5
- B: 2/4 = 0.5
- C: 3/4 = 0.75
- D: 2/4 = 0.5
- E: 1/4 = 0.25 Final: Degree centralities: A=0.5, B=0.5, C=0.75, D=0.5, E=0.25.
- Shortest-path distances (compute matrix mentally or list):
- Distances from A: to B=1, C=1, D=2, E=3; sum = 7.
- From B: to A=1, C=1, D=2, E=3; sum = 7.
- From C: to A=1, B=1, D=1, E=2; sum = 5.
- From D: to A=2, B=2, C=1, E=1; sum = 6.
- From E: to A=3, B=3, C=2, D=1; sum = 9.
- Closeness centrality = (n−1) / sum distances = 4 / sum.
- A: 4/7 ≈ 0.5714
- B: 4/7 ≈ 0.5714
- C: 4/5 = 0.8
- D: 4/6 ≈ 0.6667
- E: 4/9 ≈ 0.4444 Final: Closeness: C highest at 0.8.
- Betweenness centrality (count shortest-paths passing through v):
- Consider unordered source-target pairs (10 pairs). Only pairs whose shortest paths go through intermediate nodes: A–D (via C), A–E (via C,D), B–D (via C), B–E (via C,D), C–E (via D). For each such pair, count σ_{st}=1 and whether C or D lie on the unique shortest path.
- C lies on A–D, A–E, B–D, B–E → count = 4.
- D lies on A–E, B–E, C–E → count = 3.
- A,B,E are not intermediate on any shortest path → count = 0.
- Normalize by (n−1)(n−2)/2 = (4·3)/2 = 6.
- Normalized betweenness: C = 4/6 ≈ 0.6667, D = 3/6 = 0.5, others = 0. Final: Betweenness (normalized): C≈0.6667, D=0.5, A=B=E=0.
Example 3 — short theory model answer (exam long question) Question model: "Define betweenness centrality and show how to compute it on a small network. Explain assumptions." Answer model: Define betweenness as Σ_{s≠v≠t} σ_{st}(v)/σ_{st}. Explain σ counts shortest paths; when multiple shortest paths exist, split counts equally across them. State assumption: unweighted or edge-weighted case (use path length = sum weights). Show computation on a 4-node chain A–B–C–D: only B and C have betweenness >0; list pair A–C (via B), A–D (via B,C) etc., compute raw counts and normalize by (n−1)(n−2)/2. Conclude with numeric values (for A–B–C–D: raw betweenness B=2, C=2; normalized = 2/3 each; A=D=0).
Common mistakes
- Counting endpoints when computing betweenness (do not count pairs where v is source or target).
- Not splitting counts when multiple shortest paths exist (σ_{st} >1).
- Confusing walk/trail/path; repeating vertices when a simple path was required.
- Applying closeness formula to a disconnected graph without clarifying infinite distances (must handle components or use harmonic closeness).
For your exam
Kinds of questions: short definitions, short notes, derivations (handshake lemma, density), diagram-draw & compute centralities, numericals with a small graph, comparison questions (which centrality suits what application). What a full-marks answer includes:
- Precise definitions with bold naming (graph, node, edge, walk/path, geodesic).
- Assumptions stated (undirected/simple/connected/unweighted) before using formulas.
- Step-by-step derivations for lemmas (e.g., handshake lemma) and formulas (density).
- If asked to compute measures: draw the graph, list node degrees, list pairwise shortest distances, show sums and arithmetic, give final answers with units (dimensionless).
- If multiple shortest paths exist, show how σ_{st} and σ_{st}(v) are counted and split.
Quick check
- State the handshake lemma in one sentence.
- Give the density formula for a simple undirected graph with n nodes and m edges.
- For a connected graph with n nodes, what denominator is used to normalize betweenness centrality (undirected)? Answers: 1) Sum of degrees = 2·m. 2) ρ = 2m / (n(n−1)). 3) (n−1)(n−2)/2
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?