# What algorithm can solve the conversion engine problem?

I was once asked a question, given a series of units and their ratios, such as inch, cm, gram vs pound, and a lot of potentially cryptic units and ratios, such as A, B, C, D, ... if I am given n times to do the add() to the table, and m time to do lookup() to get the conversion, such as from "mile" to "inch" and to "cm" and to "meter" if that was the originally given ratio pairs, then what is the time complexity? (Big O). (I think this is the question -- can't remember every single detail. Probably not temperature F conversion to C, because 0°F is not 0°C, while all other conversions are like 0 inch = 0 cm, meaning they can be converted by multiplying by a k factor).

Does this problem actually belong to Union-Find, and therefore can be solved by Weighted Quick Union as described by Sedgewick? Or does it belong to any other areas in CS?

• it can be a modified version of union-find. I think the person asking is mostly interested whether I can come up with a $O((m+n) \log (m+n))$ type of algorithm vs a $O(m^2+n^2)$ one – nonopolarity Aug 27 '19 at 14:31