def METHOD_NAME(relationships: Sequence[RelationshipTuple]) -> Node:
    """
    Most of the complication of this algorithm is here. This takes a list of joins of the form
    a -> b, b -> c etc. and converts it to a linked list, where the parent entity is the root node
    and the children each keep a reference to their join parent.
    Example:
    [a -> b, b -> c] ==> a() -> b(a) -> c(b), where `b(a)` denotes entity `b` with a reference to `a` as a parent.
    Since joins can be received in any order, we keep track of all the linked lists that are not connected (roots).
    Once we find a connection between two lists, the child list is inserted into the parent list and removed
    from the roots. Once all the joins have been added, there should be exactly one root left. New joins that are
    children of existing roots are pushed into that roots children. We also keep a backreference of the children
    which keeps a reference to the Node for a given entity. This is to avoid having to scan through the roots
    every time we want to find a specific Node.
    Example:
    Input: [a -> b, c -> d, b -> c]
    After processing the first two joins, we will have two roots: `a() -> b(a)` and `c() -> d(c)`. Once the third
    join is processed, it will see that `c` is a child of `b`, and add it as a child: `b() -> c(b) -> d(c)`.
    This tree will then be added to the root `a` list, and `c` will be removed from the roots, resulting in
    one root: `a() -> b(a) -> c(b) -> d(c)`.
    """
    roots: MutableMapping[EntityKey, Node] = {}
    children: MutableMapping[EntityKey, Node] = {}
    def update_children(child: Optional[Node]) -> None:
        while child is not None:
            children[child.entity] = child
            child = child.child
    for rel in relationships:
        lhs = Node(rel.lhs)
        rhs = Node(rel.rhs, rel.data)
        orphan = roots.get(rhs.entity)
        if orphan:
            if not orphan.has_child(lhs.entity):
                # The orphan is a child of this join. Combine them.
                if orphan.child:
                    rhs.push_child(orphan.child)
                del roots[orphan.entity]
        if lhs.entity in roots:
            roots[lhs.entity].push_child(rhs)
            update_children(rhs)
        else:
            if lhs.entity in children:
                children[lhs.entity].push_child(rhs)
                update_children(rhs)
            else:
                lhs.push_child(rhs)
                roots[lhs.entity] = lhs
                update_children(rhs)
    if len(roots) > 1:
        raise ParsingException("invalid join: join is disconnected")
    if len(roots) < 1:
        raise ParsingException("invalid join: join is cyclical")
    key = list(roots.keys())[0]
    return roots[key]