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.

Graph-based structural representation

Graph-based structural representation uses graphs (nodes and edges, with possible attributes) to model structure in patterns; it supports matching, comparison and feature extraction for pattern-recognition tasks such as object recognition, shape analysis and structural clustering.

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

Graph-based structural representation is used when the pattern to recognise has relational or structural information that vector features cannot capture. Engineers use it for object recognition (parts and their relationships), analysing shapes and skeletons, structural clustering, and as an intermediate representation between raw features (see Pattern representation and feature extraction) and classifiers or grammars (see Syntactic pattern recognition with grammars).

Key ideas

Start from first principles.

  • Graph: A graph G is an ordered pair (V, E) where V is a finite set of vertices (or nodes) and E is a set of edges. If edges have direction the graph is a directed graph (digraph); otherwise it is undirected. If multiple edges between same nodes or self-loops are allowed, call it a multigraph or allow loops explicitly.

  • Attributed graph: An attributed graph adds attribute mappings: vertex attributes a_v : V -> A_V and edge attributes a_e : E -> A_E (for example labels, coordinates, weights). This is the basic structural representation in pattern recognition because attributes encode measurement values while edges encode relations.

  • Adjacency matrix: For an undirected graph with n=|V|, the adjacency matrix A is an n×n matrix with A_{ij}=1 if an edge exists between vertices i and j (or the edge weight, for weighted graphs), otherwise 0. In simple graphs A_{ii}=0. Categorical labels are stored as vertex/edge attributes, not in A. For directed graphs, A need not be symmetric.

  • Degree and Laplacian: The degree d_i of node i is the sum of adjacency row i (for weighted graphs, sum of weights). The (combinatorial) graph Laplacian is L = D - A where D is diagonal with D_{ii}=d_i. Important theorem (used often in spectral methods): the multiplicity of eigenvalue 0 of L equals the number of connected components of the graph. Assumptions: finite simple graph; proof sketch below.

    Proof sketch (standard exam derivation): write quadratic form x^T L x = 1/2 sum_{i,j} A_{ij} (x_i - x_j)^2 which is >=0, so L is positive semi-definite and 0 is an eigenvalue. If graph has k connected components, indicator vectors of each component lie in nullspace, giving multiplicity at least k. Conversely, any vector in nullspace must be constant on each connected component, so multiplicity is exactly k.

  • Graph isomorphism: Two graphs G1=(V1,E1) and G2=(V2,E2) are isomorphic if there exists a bijection f:V1->V2 such that (u,v)∈E1 iff (f(u),f(v))∈E2 and attributes match under f. In matrix form, if A1 and A2 are adjacency matrices with the same vertex ordering, isomorphism exists iff there is a permutation matrix P with A2 = P^T A1 P.

  • Subgraph isomorphism: G1 contains a subgraph isomorphic to G2 if there exists an injective mapping f: V2 -> V1 such that (u,v)∈E2 implies (f(u),f(v))∈E1 (and attributes match under f). If we additionally require that non-edges are preserved, we get induced subgraph isomorphism. The decision versions of both problems are NP-complete in general.

  • Graph matching and graph edit distance (GED): Graph matching is the problem of finding a correspondence between nodes of two graphs that best preserves structure and attributes. A common formalisation is the graph edit distance: the minimum total cost to transform G1 into G2 using allowed edit operations (node insertion/deletion/substitution, edge insertion/deletion/substitution). Graph edit distance is flexible (can handle attributes) but is NP-hard to compute exactly. Typical exam assumption: finite simple attributed graphs, costs non-negative and metric-like.

  • Spectral representation: Use eigenvalues and eigenvectors of adjacency or Laplacian matrices as compact structural features (graph spectrum). Eigenvalues (the spectrum) are invariant to vertex ordering and capture global structure; eigenvectors depend on the chosen basis and vertex ordering (up to rotations within eigenspaces and sign), so use them via invariant constructions or after alignment. They are used in spectral clustering and as features for classifiers.

  • Approximate matching: Because exact matching is expensive, approximate methods are used: assignment-based (reduce to bipartite matching using costs), spectral matching (match eigenvectors), relaxation labeling, and graph kernels (kernel methods to compare graphs by counting walks/subtrees). Many algorithms trade accuracy for polynomial running time.

What to draw in exams: when asked to illustrate graphs, draw nodes as circles with labels (numbers or letters), draw undirected edges as straight lines connecting nodes. For adjacency matrices, draw an n×n table with rows and columns labeled by the nodes and fill entries with 0/1. For permutations show arrows mapping vertices from G1 to G2.

Formulas

L = D - A where L is Laplacian (unit: unitless), D is diagonal degree matrix (unitless), A is adjacency matrix (unitless). Applies to combinatorial Laplacian of finite simple graphs. Normalized Laplacians used in spectral methods: L_sym = I - D^{-1/2} A D^{-1/2} and L_rw = I - D^{-1} A (assumes all degrees d_i > 0).

x^T L x = 1/2 Σ_{i,j} A_{ij} (x_i - x_j)^2 for undirected graphs (A symmetric, weights ≥ 0), where x is any real vector of length n (unitless). This shows L is positive semi-definite; used in spectral proofs.

A2 = P^T A1 P where A1,A2 are adjacency matrices and P is a permutation matrix (entries 0/1, each row/column has exactly one 1). Applies when graphs are isomorphic and rows/columns are ordered correspondingly.

GED(G1,G2) = min over edit sequences Σ cost(operation) where cost(operation) ≥ 0 and unit is chosen by user (unitless). GED is the minimum-cost sequence of node/edge edits transforming G1 to G2.

cost_match = Σ_i c_node(v1_i -> v2_{σ(i)}) + Σ_{(i,j)} c_edge((i,j)->(σ(i),σ(j))) where σ is a partial mapping; unitless. This expresses matching cost used in assignment approximations.

Complexity notes (informal): graph isomorphism is not known to be NP-complete; the best general algorithm runs in quasipolynomial time (Babai, 2016; subsequent refinements). Subgraph isomorphism is NP-complete; exact GED is NP-hard.

Worked examples

Example 1 — adjacency, isomorphism (diagram answer expected) Given two undirected labelled graphs G1 and G2 with 3 nodes each. G1: nodes {1,2,3}, edges {(1,2),(2,3)} (a path of length 2). Labels: all nodes unlabeled. G2: nodes {a,b,c}, edges {(a,b),(b,c)}. Step 1: write adjacency matrices in order [1,2,3] and [a,b,c]. A1 = [[0,1,0],[1,0,1],[0,1,0]] A2 = [[0,1,0],[1,0,1],[0,1,0]] Step 2: observe A1 == A2, so identity permutation P=I works. Conclude graphs are isomorphic; one can draw mapping 1->a,2->b,3->c. (If vertex order differed, find permutation matrix P with A2 = P^T A1 P.)

Example 2 — graph edit distance (numerical) G1: nodes {1,2}, edge {(1,2)}. G2: single node {a} (no edges). Costs: node deletion = 1, node insertion = 1, node substitution (different label) = 1, edge deletion/insertion = 1. Assume node labels in G1 differ from the label of node a in G2 so a substitution incurs cost; otherwise, with unlabeled nodes, GED would be 1 by a single node deletion. Goal: compute GED(G1,G2). Option A: delete node 1 (cost 1), delete node 2 (cost 1), insert node a (cost 1) → total 3. Option B: substitute node 1 -> a (cost 1), delete node 2 (cost 1). The incident edge is removed automatically with the node deletion in the standard model. Total = 2. This is cheaper and minimal: GED = 2. Show steps and justify minimality by enumerating small edit sequences.

Example 3 — Laplacian eigenvalues (theory + numbers) Compute L and eigenvalues for (a) path P3 (nodes 1–2–3) and (b) complete graph K3 (triangle). P3: A = [[0,1,0],[1,0,1],[0,1,0]], D = diag(1,2,1), so L = [[1,-1,0],[-1,2,-1],[0,-1,1]]. Solve characteristic polynomial (exam derivation): det(L-λI) factors to λ(1-λ)(λ-3) giving eigenvalues λ = 0, 1, 3. Interpretation: single zero eigenvalue => connected graph. K3: A = [[0,1,1],[1,0,1],[1,1,0]], D = diag(2,2,2), L = [[2,-1,-1],[-1,2,-1],[-1,-1,2]]. Eigenvalues are 0, 3, 3 (show by observing vector [1,1,1] maps to 0 and any orthogonal vector maps to 3). Multiplicity of eigenvalue 3 is n-1 as for K_n.

Common mistakes

  • Mis-stating Laplacian properties: the nullspace dimension equals number of connected components (not number of nodes!).
  • Using spectral features without noting they may be ambiguous: different non-isomorphic graphs can have same spectrum (cospectral graphs).
  • Claiming graph isomorphism is NP-complete — that is incorrect; its exact complexity class is not resolved (it is not known to be NP-complete under usual assumptions).

For your exam

Types of questions:

  • Definitions (define graph, attributed graph, adjacency matrix, Laplacian, graph isomorphism, graph edit distance).
  • Short notes (advantages and limits of graph models; spectral features; GED and complexity).
  • Derivations (derive x^T L x expression; show multiplicity of 0 eigenvalue equals components; show A2 = P^T A1 P for isomorphism).
  • Numericals (compute adjacency/Laplacian matrices and eigenvalues; compute a small GED exactly by enumerating edits).
  • Diagrams (draw graphs and show a permutation mapping; draw bipartite assignment for approximate matching).

What a full-marks answer includes:

  • Clear definitions with symbols; assumptions stated (simple/attributed, directed/undirected).
  • Step-by-step derivation for spectral/Laplacian results with the quadratic form.
  • For numerical problems, show matrices, all intermediate calculations, and final numeric answers with units (unitless for graph counts).
  • If describing algorithms, state complexity, where approximations are used, and limitations.

Quick check

  1. Define an attributed graph in one sentence.
  2. Give the matrix equation that shows two graphs are isomorphic.
  3. For which property of the Laplacian does the quadratic form x^T L x = 1/2 Σ A_{ij} (x_i - x_j)^2 prove usefulness? Answers: 1) A graph with attribute functions assigning labels/weights to vertices and edges. 2) A2 = P^T A1 P where P is a permutation matrix. 3) It proves L is positive semi-definite and that zero eigenvalues correspond to constant values on connected components (connectivity/nullspace property).

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

Stuck on something here?