Interview Q&A / Machine Learning

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between Euclidean and Manhattan distance, and which should KNN use?

SHORT ANSWER

Euclidean is the straight-line distance, sqrt of the sum of squared differences. Manhattan is the sum of absolute differences, like walking along city blocks. Euclidean is the default; Manhattan can be better in high dimensions or with many outliers.

Explain it simply

Between two points in Mumbai, Euclidean distance is how far a crow flies. Manhattan distance is how far an auto-rickshaw drives, going along the grid of roads, never cutting across buildings.

Example

Points P = (1, 2) and Q = (4, 6).

text
Differences: dx = 3, dy = 4

Euclidean = sqrt(3^2 + 4^2) = sqrt(25) = 5
Manhattan = |3| + |4|       = 7

Both are special cases of Minkowski distance with power p: p = 2 gives Euclidean, p = 1 gives Manhattan.

python
from sklearn.neighbors import KNeighborsClassifier
KNeighborsClassifier(n_neighbors=5, p=1)   # Manhattan
KNeighborsClassifier(n_neighbors=5, p=2)   # Euclidean (default)

Squaring makes Euclidean distance more sensitive to one large difference in a single feature. Manhattan treats each feature's gap in proportion. For binary or text-like features, other measures (Hamming, cosine) are also common.

What to say in the interview

"Euclidean is the L2 straight-line distance and Manhattan is the L1 sum of absolute differences; both are Minkowski distances. I start with Euclidean on scaled features and treat the metric as a hyperparameter to compare by cross-validation."

Common mistakes

  • Using any distance on unscaled features.
  • Using Euclidean on categorical data coded as integers.

#knn#distance#euclidean

Related questions

Practise more Machine Learning questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Machine Learning quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.