build a data structure representing a tree of connections