
Distance Formulas
Algorithms like K-Nearest Neighbor and most clustering methods need a way to answer one basic question: how far apart are two data points? The answer depends on which distance formula you pick, so it is worth knowing the three you will run into most often.
Euclidean Distance

The Euclidean distance, also called the L2 distance or L2 norm, is the "ordinary" straight-line distance between two points, exactly as you would measure it with a ruler in everyday geometric space. It is the default choice for most KNN implementations, including the one I use in the K-Nearest Neighbor article.
Manhattan Distance

Manhattan distance measures the distance you would travel along a grid, like a taxi driving along city blocks, instead of cutting a straight line through space. It sums the absolute differences across each dimension, which makes it more robust to outliers than Euclidean distance in some datasets.
Cosine Distance

Cosine distance does not measure distance in the geometric sense at all, it measures the angle between two vectors. Two points can be far apart in magnitude but still point in nearly the same direction, which is exactly the case cosine distance is built for: text similarity, recommendation systems, anywhere magnitude shouldn't dominate the comparison.
Picking the right formula matters more than people expect, the wrong distance metric can make an otherwise correct algorithm perform badly. Thanks for reading.
Related reading

K-Nearest Neighbor
How the K-Nearest Neighbor algorithm works, and a from-scratch C# implementation used to power an article recommendation example.

Machine Learning
Machine learning algorithms power more of daily life than most people realize. This article breaks down how they work, how they differ, and where the most widely used ones actually show up in the real world.

Naive Bayes
How the Naive Bayes algorithm works, why it performs surprisingly well despite a naive assumption, and a from-scratch C# implementation for text classification.

AI Over-Engineering: When the Smartest Tool Is Not the Right One
LLMs aren't always the answer. Learn why engineers over-engineer with AI when classical ML models are faster, cheaper, and more accurate for most real-world problems.