Ready to begin
No records have been processed. Start with Next step.
![Compare the same five columns. Abhinav [3,8,2,0,1] and Akshaya [3,13,4,0,1] have gaps [0,5,2,0,0], so distance 7.](/images/computational-thinking/week-7/absolute-distance.png)
Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.
Ready
No records have been processed. Start with Next step.
Predict the next key, whether it already exists, and the value that will be stored.
Procedure distance(A,B)
total = 0
foreach category in categories {
total = total + abs(A[category] - B[category])
}
return(total)
End distanceabs means absolute value: abs(8−13)=5 and abs(13−8)=5. Every gap is non-negative, so a larger Food count cannot cancel a smaller Utilities count. The sum of these absolute gaps is called Manhattan or rectilinear distance. Smaller distance means closer under THIS chosen representation and distance rule.
Distance from a profile to itself is zero. Distance is symmetric: D(A,B)=D(B,A). Zero between two different customers means their counted profiles match, not that they are the same person. Category row counts are the features; spending in rupees is not being measured here.
What is the distance between the two illustrated customers?
0+5+2+0+0=7.
Why not add signed differences?
Positive and negative gaps could cancel, hiding differences in category patterns.
Does distance 0 prove two customers are the same person?
No. Different customers can have identical observed profiles.