Graph Edit Distance (GED) is a graph similarity metric quantifying the minimum number of edit operations—node insertions, deletions, and substitutions, along with corresponding edge modifications—needed to make two graphs isomorphic. It generalizes string edit distance to graph-structured data, providing a flexible, application-agnostic measure of structural dissimilarity that can be tuned via domain-specific cost functions for individual edit operations.
Glossary
Graph Edit Distance (GED)

What is Graph Edit Distance (GED)?
Graph Edit Distance (GED) is a quantitative measure of dissimilarity between two graphs, defined as the minimum cost of a sequence of edit operations required to transform one graph into the other.
Computing exact GED is NP-hard, making it intractable for large graphs. Practical applications in cheminformatics and pattern recognition therefore rely on approximation algorithms, such as bipartite graph matching heuristics or neural network-based predictors, to estimate GED efficiently. This metric is fundamental for tasks like molecular similarity searching, where it quantifies the structural distance between molecular graphs, and for evaluating the performance of graph generative models.
Key Characteristics of GED
Graph Edit Distance (GED) is defined by several core computational properties that govern its flexibility, interpretability, and computational complexity in pattern recognition.
Edit Operation Cost Functions
The core of GED is a user-defined cost function that assigns a penalty to each atomic graph edit operation. Standard operations include:
- Node Insertion/Deletion: Adding or removing an isolated vertex.
- Edge Insertion/Deletion: Adding or removing a connection between existing vertices.
- Node Substitution: Replacing a vertex label (e.g., changing a carbon atom to a nitrogen atom). The flexibility to weight these operations differently allows domain experts to tune the metric; for example, deleting a node can be penalized more heavily than substituting its label, reflecting chemical stability constraints.
NP-Completeness and Computational Limits
Computing the exact GED between two graphs is an NP-complete problem, meaning the worst-case runtime grows exponentially with graph size. This is formally proven by reduction from the subgraph isomorphism problem. For practical applications, exact computation via A* search with bipartite heuristics is typically limited to graphs with fewer than 16 nodes. For larger molecular graphs, practitioners rely on approximation algorithms or neural network-based regression models that predict GED directly from learned embeddings.
Metric Properties and Axioms
When cost functions satisfy specific constraints, GED defines a proper distance metric in the space of graphs. The required axioms are:
- Non-negativity: The distance is always zero or positive.
- Identity of Indiscernibles: The distance is zero if and only if the graphs are isomorphic.
- Symmetry: The distance from graph A to B equals the distance from B to A.
- Triangle Inequality: The direct distance between two graphs is never greater than the sum of distances via an intermediate graph. These properties make GED suitable for metric indexing structures like BK-trees for fast similarity search.
Bipartite Graph Matching Heuristic
A widely used approximation algorithm, often called BP-GED, reformulates the edit distance problem as an assignment problem on a cost matrix. The algorithm:
- Constructs a complete bipartite graph between the node sets of the two input graphs.
- Assigns costs to node substitutions, insertions, and deletions based on local structural context.
- Solves the resulting linear sum assignment problem using the Hungarian algorithm in cubic time. This method provides a fast upper bound on the true GED and is the default approach in many cheminformatics libraries.
Chemical Edit Distance and Molecular Similarity
In cheminformatics, GED is often specialized as Chemical Edit Distance where edit costs are derived from chemical principles. Key adaptations include:
- Bond-breaking penalties: Edge deletions are weighted by bond dissociation energies.
- Stereo-aware substitution: Node substitution costs account for chirality and stereochemistry mismatches.
- Maximum Common Subgraph (MCS) connection: For specific cost functions, GED is mathematically equivalent to the size of the MCS, linking it to substructure-based similarity metrics. This makes GED a gold standard for quantifying lead optimization changes in medicinal chemistry.
Deep Graph Similarity Learning
To bypass the NP-complete bottleneck, modern approaches train Graph Neural Networks (GNNs) to directly regress GED values. The standard paradigm involves:
- A Siamese GNN architecture where two graphs are encoded into fixed-length embedding vectors by weight-shared networks.
- A Neural Tensor Network or attention-based interaction layer that computes a similarity score from the pair of embeddings.
- Training on synthetically generated graph pairs with pre-computed exact GED labels for small graphs, then generalizing to larger structures. Models like SimGNN and GraphSim achieve sub-second inference with high correlation to true GED.
GED vs. Other Graph Similarity Metrics
A feature-level comparison of Graph Edit Distance against alternative graph similarity and kernel methods commonly used in molecular informatics and pattern recognition.
| Feature | Graph Edit Distance | Weisfeiler-Lehman Kernel | Graph Isomorphism Network |
|---|---|---|---|
Similarity Type | Exact cost-based distance | Implicit kernel embedding | Learned embedding distance |
Handles Node Labels | |||
Handles Edge Labels | |||
Handles Continuous Attributes | |||
Substructure Sensitivity | Edit path granularity | Subtree pattern counts | Injective neighborhood aggregation |
Computational Complexity | NP-hard (A* approximate) | O(N * h * d) | O(N * d^2) |
Interpretability | Explicit edit operations | Implicit feature map | Black-box embedding |
Theoretical Power (WL Test) | Exceeds 1-WL | Equivalent to 1-WL | Maximally 1-WL powerful |
Frequently Asked Questions
Concise answers to the most common technical questions about Graph Edit Distance (GED), its computational complexity, and its role in molecular similarity analysis.
Graph Edit Distance (GED) is a quantitative graph similarity metric defined as the minimum total cost of a sequence of edit operations required to transform a source graph into a target graph. The edit operations typically include node insertion/deletion, edge insertion/deletion, and node/edge substitution (relabeling). Each operation carries a user-defined cost, and the GED is the sum of the costs along the optimal edit path. Formally, it generalizes string edit distance to the graph domain, making it applicable to attributed and labeled graphs. In molecular informatics, GED quantifies the structural dissimilarity between two molecular graphs, where nodes represent atoms and edges represent bonds. The primary challenge is that computing the exact GED is NP-hard, meaning the runtime grows exponentially with graph size, necessitating heuristic or neural network-based approximations for practical use in drug discovery pipelines.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core algorithms, architectures, and theoretical foundations that underpin graph comparison and the computation of Graph Edit Distance.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us