Reputation: 1
There are several people, lets call them A, B, C. Difference in weight between A and B is 20 kg. Difference in weight between B and C is 30 kg. What's the difference between A and C?
I am looking for the fastest possible method. Implementation in C/C++ would be really helpful.
Upvotes: 0
Views: 75
Reputation: 1386
1) In general meaning of "difference" you have two solution for this problem:
A = 60, B = 80, C = 110 => diff = 50
A = 60, B = 80, C = 50 => diff = 10
It's because diff(X,Y) = abs(X-Y)
2) I think you talk about transitivity or https://en.wikipedia.org/wiki/Transitive_relation
3) Also you may refer to Dijkstra/Floyd-Warshall algorithm for calculating shortest distances between X and Y. Full list here: https://en.wikipedia.org/wiki/Shortest_path_problem
Upvotes: 1