The result of a database join is that hierarchical information is returned as a 2 dimensional result with repeating values. The problem is to take the joined list and reverse the process back into a hierarchy as it was originally.
I am a bit lacking in time to reproduce all the workings of this algorithm, but the short reply is that it uses a recursive divide and conquer technique to divide each column recursively until a solution is found. The solution is demonstrated in the attached Excel VBA macro worksheet attached.