Euclidean distance
Euclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared differences between corresponding coordinates.
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
Euclidean distance is the straight-line distance between two points calculated from the square root of the sum of squared coordinate differences.
- How it is used
- Supplies a straight-line heuristic for maze search and a distance measure for k-means data points.
- How deep it goes
- Derives the two-dimensional formula from geometry and implements it for maze locations and data points with any number of dimensions.
- Examples
- Uses a Swift maze-location function and a three-dimensional point pair whose distance is approximately 4.123.
- What you can do after
- Build it from scratch as a Swift distance function for maze locations or multidimensional DataPoint values.
Advanced Algorithms and Data Structures
Euclidean distance is the straight-line distance between points in Euclidean space, computed from the square root of the sum of squared coordinate differences.
- How it is used
- Measures closeness for nearest-neighbor queries and supplies a straight-line estimate for route search.
- How deep it goes
- Defines straight-line distance and applies it to search decisions, without deriving multidimensional search internals here.
- Examples
- Uses warehouses on a straight road, price-and-rating points, spherical SS-tree nodes, and road-route estimates.
- What you can do after
- Apply it to compare point distances and evaluate when straight-line distance is an appropriate approximation or A* heuristic.
Read how Advanced Algorithms and Data Structures explains Euclidean distance →
Data Without Labels
Euclidean distance is the straight-line distance between points in a coordinate space, computed as the square root of the summed squared coordinate differences.
- How it is used
- Measures similarity for clustering observations and centroids, while serving as a common distance choice in k-means and DBSCAN.
- How deep it goes
- Defines straight-line distance and gives a two-coordinate formula; defers detailed L2-norm treatment and high-dimensionality discussion.
- Examples
- Uses two coordinate points, a visual comparison of distance metrics, and a DBSCAN nearest-neighbor-distance plot.
- What you can do after
- Evaluate/understand it when interpreting centroid proximity and comparing distance choices for clustering.
Natural Language Processing in Action, Second Edition
Euclidean distance is the straight-line distance between two points or vectors computed from the square root of the sum of squared coordinate differences.
- How it is used
- Measures geometric separation between feature vectors in NLP and machine-learning pipelines.
- How deep it goes
- Defines the formula geometrically, works through vector subtraction, and stops short of detailed high-dimensional implementation.
- Examples
- Uses 2D term-frequency vectors, vector diagrams, and geographic latitude–longitude coordinates.
- What you can do after
- Apply it via vector subtraction and NumPy for low-dimensional comparisons, then evaluate cosine distance for high-dimensional vectors.
Read how Natural Language Processing in Action, Second Edition explains Euclidean distance →
Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI
Euclidean distance is the straight-line distance between two points in Euclidean space.
- How it is used
- Uses straight-line separation to engineer geographical features for machine-learning models.
- How deep it goes
- Defines direct-path distance, relates it to the L2 norm, and stops short of a dense mathematical derivation.
- Examples
- Uses Tokyo Airbnb listings, Imperial Palace coordinates, meter conversion, and nearest-location inspection.
- What you can do after
- Evaluate whether straight-line or Manhattan distance better represents a geographical machine-learning feature.
Statistics Slam Dunk
Euclidean distance is the straight-line distance between points computed as the square root of the sum of squared coordinate differences.
- How it is used
- Measures pairwise dissimilarity before hierarchical clustering.
- How deep it goes
- Explains the coordinate formula, works two NBA examples, and applies R distance-matrix computation.
- Examples
- Uses NBA draft pick number, average win shares, R calculations, and a clustering dendrogram.
- What you can do after
- Apply it via base R to calculate pairwise distances and prepare hierarchical clustering.
Optimization Algorithms: AI techniques for design, planning, and control problems
Euclidean distance is the straight-line distance between points calculated from the square root of the sum of squared coordinate differences.
- How it is used
- Guides spatial search, routing, numerical-data comparison, and geometric representations for optimization and machine learning.
- How deep it goes
- Defines the metric and demonstrates applications in A* and TSP, without developing a detailed mathematical derivation.
- Examples
- Uses road-network routing, point-based TSP instances, and Euclidean-distance heatmaps as concrete examples.
- What you can do after
- Apply it as a straight-line heuristic and inspect pairwise distances in TSP experiments.
MongoDB 8.0 in Action, Third Edition
Euclidean distance is the straight-line distance between two points or vectors in Euclidean space.
- How it is used
- Supports vector-search similarity ranking when spatial distance between embeddings is meaningful.
- How deep it goes
- Defines straight-line distance and connects it to HNSW navigation, but does not present a calculation formula.
- Examples
- Uses image recognition, clustering, embedding retrieval, and nearest-neighbor graph navigation as applications.
- What you can do after
- Evaluate similarity metrics for vector search and understand how distance guides approximate or exact nearest-neighbor retrieval.
Read how MongoDB 8.0 in Action, Third Edition explains Euclidean distance →
LLM Evaluation and Alignment, The Foundational Ideas
Euclidean distance is the straight-line distance between two points in a coordinate space.
- How it is used
- Frames the choice between spatial distance and directional similarity when evaluating semantic representations.
- How deep it goes
- Defines straight-line distance and vector magnitude, then stops short of a full implementation or numerical calculation.
- Examples
- Uses weather sentences and contrasting vector lengths to show why distance may diverge from semantic similarity.
- What you can do after
- Evaluate when Euclidean distance is informative and when cosine similarity better preserves semantic direction.
Read how LLM Evaluation and Alignment, The Foundational Ideas explains Euclidean distance →
Also covered in
- Evolutionary Deep Learning: Genetic algorithms and neural networks
- Build an Advanced RAG Application (From Scratch)In early access (MEAP)
- Domain-Specific Small Language Models
- LLMs in Production
- Build AI Drug Discovery PipelinesIn early access (MEAP)
- Knowledge Graphs and LLMs in Action
- Build an AI Agent (From Scratch)
- Graph Algorithms for Data Science
- Retrieval Augmented Generation, The Foundational IdeasIn early access (MEAP)
- Starting Data Analytics with Generative AI and Python
- Cyber Threat Hunting
- Machine Learning Algorithms in Depth
What to know first
- embeddingAn embedding is a numerical vector representation of an item in a feature space, encoding selected properties or relationships for computational tasks such as comparison or retrieval.
- similarity searchSimilarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.
- language modelA language model is a computational model that represents patterns in linguistic sequences to assign probabilities, predict, generate, or evaluate language.
- distanceA distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
Related concepts
- K-means clusteringused by · K-means clustering is an algorithm that partitions data into a specified number of clusters by iteratively assigning observations to the nearest centroid and updating each centroid to the mean of its assigned observations.
- Manhattan distancecontrasts with · Manhattan distance is the sum of the absolute differences between corresponding coordinates of two points or vectors.
- cosine similaritycontrasts with · Cosine similarity measures the directional alignment of two nonzero vectors as the cosine of the angle between them, equal to their dot product divided by the product of their magnitudes.
- minkowski distanceequivalent to · Minkowski distance is a parameterized metric between points based on a positive-order norm, including Manhattan and Euclidean distance as special cases.
- distancekind of · A distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
- cosine distancealternative to · Cosine distance is a measure of directional dissimilarity between nonzero vectors, commonly defined as one minus their cosine similarity.
Questions about Euclidean distance
What is Euclidean distance?
Euclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared differences between corresponding coordinates.
Which Manning books explain Euclidean distance?
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers, Advanced Algorithms and Data Structures, Data Without Labels, Natural Language Processing in Action, Second Edition, Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI, Statistics Slam Dunk, Optimization Algorithms: AI techniques for design, planning, and control problems, MongoDB 8.0 in Action, Third Edition and 1 more.
What should I know before learning Euclidean distance?
Manning books that teach Euclidean distance usually introduce embedding, similarity search, language model and distance first.
What is the difference between Euclidean distance and Manhattan distance?
Euclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared differences between corresponding coordinates. Manhattan distance is the sum of the absolute differences between corresponding coordinates of two points or vectors.
What is Euclidean distance a kind of?
Euclidean distance is a kind of distance. A distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
What is Euclidean distance also called?
Euclidean distance is also called L2 distance or straight-line distance.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.








