{
  "id": "adjacency-matrix",
  "title": "Adjacency Matrix",
  "lang": "en",
  "source_lang": "en",
  "summary": "An adjacency matrix represents a graph by recording connections between ordered pairs of vertices, enabling algebraic analysis of its structure and efficient computation of network properties.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "Vertex adjacency matrix",
    "Connection matrix"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/adjacency-matrix/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/adjacency-matrix/",
      "json": "https://aiwiki.page/zh/adjacency-matrix.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "An adjacency matrix is a square matrix that represents a finite graph by recording which pairs of vertices are connected by edges. Its rows and columns correspond to vertices in a specified order, and each entry indicates the presence, number, or weight of edges between the corresponding vertices. Adjacency matrices provide a fundamental connection between graph theory and linear algebra, allowing graph structure to be studied through matrix operations, eigenvalues, and computational algorithms."
    },
    {
      "heading": "Definition and conventions",
      "text": "Let \\(G\\) be a graph with ordered vertex set \\(V=\\{v_1,\\ldots,v_n\\}\\). For a simple undirected graph—one with neither loops nor multiple edges—its adjacency matrix \\(A=(a_{ij})\\) is defined by\n\n\\[a_{ij}= \\begin{cases} 1,&\\text{if }v_i\\text{ and }v_j\\text{ are joined by an edge},\\\\ 0,&\\text{otherwise}. \\end{cases}\\]\n\nThus \\(A\\) is an \\(n\\times n\\) matrix with entries in \\(\\{0,1\\}\\). It is symmetric, and all its diagonal entries are zero.\n\nFor a directed graph, a common convention is\n\n\\[a_{ij}=1 \\quad\\text{if there is an edge from }v_i\\text{ to }v_j.\\]\n\nUnder this convention, rows describe outgoing connections and columns describe incoming connections. Some authors and software systems use the opposite convention, so the interpretation must be checked when comparing representations. Reversing every edge replaces \\(A\\) by its transpose \\(A^{\\mathsf T}\\).\n\nMultiple edges, loops, and weights\n\nThe definition extends to other graph types:\n\n- Multiple edges: \\(a_{ij}\\) can record the number of edges from \\(v_i\\) to \\(v_j\\).\n- Loops: diagonal entries record edges joining a vertex to itself.\n- Weighted edges: \\(a_{ij}\\) can record an edge weight, or the sum of the weights of parallel edges.\n\nFor undirected loops, two conventions are common: each loop contributes either \\(1\\) or \\(2\\) to the diagonal entry. Counting it twice makes row sums equal vertex degrees when a loop contributes two to degree; counting it once is natural when matrix entries record individual edge traversals. Formulas involving degrees or powers must be interpreted according to the chosen convention.\n\nA weighted adjacency matrix commonly uses zero to indicate the absence of an edge. If zero-weight edges are allowed, the weight matrix alone may not distinguish them from missing edges; a separate record of edge presence may be required."
    },
    {
      "heading": "Example and elementary properties",
      "text": "Consider the undirected path with vertices \\(v_1,v_2,v_3\\) and edges \\(\\{v_1,v_2\\}\\) and \\(\\{v_2,v_3\\}\\). Its adjacency matrix is\n\n\\[A= \\begin{pmatrix} 0&1&0\\\\ 1&0&1\\\\ 0&1&0 \\end{pmatrix}.\\]\n\nFor a simple undirected graph, the degree \\(d_i\\) of vertex \\(v_i\\) is the sum of row \\(i\\):\n\n\\[d_i=\\sum_{j=1}^{n}a_{ij}.\\]\n\nWriting \\(\\mathbf 1\\) for the column vector whose entries are all \\(1\\), the vector of degrees is \\(A\\mathbf 1\\). If the graph has \\(m\\) edges, then\n\n\\[\\sum_{i=1}^{n}\\sum_{j=1}^{n}a_{ij}=2m,\\]\n\nbecause each edge contributes two symmetric entries.\n\nFor a directed graph under the row-source convention, row sums give out-degrees and column sums give in-degrees. With weighted edges, these sums instead give outgoing and incoming weighted degrees, also called strengths.\n\nDependence on vertex order\n\nThe matrix depends on the ordering of the vertices, but the underlying graph does not. If \\(P\\) is a permutation matrix representing a change of order, the reordered adjacency matrix has the form\n\n\\[A'=P^{\\mathsf T}AP.\\]\n\nConsequently, graphs are isomorphic precisely when their adjacency matrices are related by such a simultaneous permutation of rows and columns. This is a special case of matrix similarity, so eigenvalues, the characteristic polynomial, and other similarity invariants do not depend on vertex labeling."
    },
    {
      "heading": "Matrix powers, walks, and reachability",
      "text": "A principal reason for using adjacency matrices is that their powers count walks. A walk is a sequence of consecutive edges in which vertices and edges may repeat. For an unweighted graph, using edge-count entries and counting each loop once,\n\n\\[(A^k)_{ij} = \\text{number of walks of length }k \\text{ from }v_i\\text{ to }v_j.\\]\n\nThis follows from matrix multiplication:\n\n\\[(A^{k+1})_{ij} = \\sum_{\\ell=1}^{n}(A^k)_{i\\ell}a_{\\ell j}.\\]\n\nEach term counts walks that reach \\(v_\\ell\\) after \\(k\\) steps and then traverse an edge to \\(v_j\\).\n\nFor the three-vertex path,\n\n\\[A^2= \\begin{pmatrix} 1&0&1\\\\ 0&2&0\\\\ 1&0&1 \\end{pmatrix}.\\]\n\nThe central diagonal entry is \\(2\\), corresponding to the walks \\(v_2,v_1,v_2\\) and \\(v_2,v_3,v_2\\). These are not simple paths: matrix powers count walks, not only routes with distinct vertices.\n\nFor a weighted adjacency matrix, \\((A^k)_{ij}\\) is the sum, over length-\\(k\\) walks, of the products of their edge weights.\n\nClosed walks and subgraph counts\n\nThe trace of \\(A^k\\) counts closed walks of length \\(k\\), including their choice of starting vertex. For a simple undirected graph,\n\n\\[\\operatorname{tr}(A^2)=2m, \\qquad \\text{number of triangles} = \\frac{\\operatorname{tr}(A^3)}{6}.\\]\n\nEach triangle contributes three possible starting vertices and two traversal directions.\n\nBoolean reachability\n\nUsing Boolean algebra instead of ordinary arithmetic—logical OR for addition and logical AND for multiplication—matrix powers indicate whether walks exist rather than how many exist.\n\nFor \\(n\\geq 1\\), the Boolean matrix\n\n\\[I\\lor A\\lor A^2\\lor\\cdots\\lor A^{n-1}\\]\n\nrecords reachability, including zero-length walks through the identity matrix \\(I\\). The bound \\(n-1\\) suffices because whenever one vertex is reachable from another, a path without repeated vertices exists."
    },
    {
      "heading": "Spectral properties",
      "text": "The eigenvalues and eigenvectors of an adjacency matrix constitute its spectral information. For an undirected graph with real symmetric weights, the spectral theorem ensures that all eigenvalues are real and that an orthonormal basis of eigenvectors exists.\n\nSeveral structural properties have spectral interpretations:\n\n- If the graph is \\(d\\)-regular, meaning that every vertex has degree \\(d\\), then \\(A\\mathbf 1=d\\mathbf 1\\).\n- For a simple undirected graph, the largest eigenvalue is at most the maximum vertex degree.\n- If a simple undirected graph is connected, its largest eigenvalue has an eigenvector with strictly positive entries, unique up to scaling.\n- A simple undirected graph is bipartite if and only if its eigenvalues are symmetric about zero, including multiplicities.\n\nIf the eigenvalues are \\(\\lambda_1,\\ldots,\\lambda_n\\), then\n\n\\[\\operatorname{tr}(A^k)=\\sum_{i=1}^{n}\\lambda_i^k.\\]\n\nThus spectral data determine closed-walk counts. They do not, however, determine the graph uniquely: nonisomorphic graphs can have identical adjacency eigenvalues. Such graphs are called cospectral.\n\nFor directed graphs, the adjacency matrix need not be symmetric. Its eigenvalues may be complex, and it need not have a full basis of eigenvectors."
    },
    {
      "heading": "Related matrices and representations",
      "text": "Graph Laplacian\n\nFor an undirected graph with nonnegative edge weights, let \\(D\\) be the diagonal matrix of weighted degrees. The graph Laplacian is\n\n\\[L=D-A.\\]\n\nFor a loopless graph,\n\n\\[x^{\\mathsf T}Lx = \\frac12\\sum_{i,j}a_{ij}(x_i-x_j)^2\\geq 0.\\]\n\nThe Laplacian is therefore positive semidefinite. The multiplicity of its zero eigenvalue equals the number of connected components. Laplacian matrices are central to graph partitioning, diffusion, and clustering.\n\nRandom-walk transition matrix\n\nWhen all degrees are positive, normalizing rows gives\n\n\\[P=D^{-1}A.\\]\n\nFor an unweighted graph, \\(P_{ij}\\) is the probability that a random walk at vertex \\(v_i\\) moves next to \\(v_j\\). The resulting transition matrix defines a Markov chain. Isolated vertices require a separate convention, such as making them absorbing states.\n\nBipartite graphs\n\nIf a bipartite graph has vertex classes of sizes \\(p\\) and \\(q\\), an appropriate ordering gives\n\n\\[A= \\begin{pmatrix} 0&B\\\\ B^{\\mathsf T}&0 \\end{pmatrix}.\\]\n\nThe \\(p\\times q\\) matrix \\(B\\), called a biadjacency matrix, records edges between the two classes. Unlike the full adjacency matrix, it can be rectangular.\n\nComplement graphs\n\nFor a simple undirected graph, the adjacency matrix of its complement is\n\n\\[\\overline A=J-I-A,\\]\n\nwhere \\(J\\) is the all-ones matrix. The subtraction of \\(I\\) ensures that the complement has no loops."
    },
    {
      "heading": "Computational uses and limitations",
      "text": "Adjacency matrices support algebraic graph algorithms, network analysis, and matrix-based models in machine learning. They are particularly convenient for dense graphs, repeated edge queries, and computations that exploit optimized numerical hardware.\n\nA full \\(n\\times n\\) representation requires \\(\\Theta(n^2)\\) storage locations, regardless of the number of edges. In a standard random-access representation, testing whether a particular edge exists takes \\(O(1)\\) time, while listing all neighbors of a vertex requires scanning a row and takes \\(O(n)\\) time. These bounds use asymptotic notation.\n\nFor graphs with relatively few edges, an adjacency list usually stores the structure more compactly, using \\(O(n+m)\\) space. A sparse matrix representation can preserve many algebraic advantages while storing only nonzero entries, though lookup and modification costs depend on the storage format.\n\nThe algebra used with a matrix also matters. Ordinary multiplication counts walks; Boolean operations test reachability; replacing addition by minimum and multiplication by addition supports certain shortest-path computations. Treating a weighted adjacency matrix as though it were an unweighted one, or confusing walks with simple paths, can therefore produce incorrect interpretations."
    }
  ],
  "links": [
    "matrix",
    "graph-theory",
    "linear-algebra",
    "directed-graph",
    "matrix-transpose",
    "matrix-similarity",
    "characteristic-polynomial",
    "matrix-multiplication",
    "matrix-trace",
    "boolean-algebra",
    "identity-matrix",
    "eigenvalues-and-eigenvectors",
    "spectral-theorem",
    "graph-laplacian",
    "cluster-analysis",
    "random-walk",
    "transition-matrix",
    "markov-chain",
    "machine-learning",
    "big-o-notation",
    "adjacency-list",
    "sparse-matrix"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}