private Deque<Node> findRoots() {
        nodes.clear(); // Reset current nodes

        // Create Node for each child
        for (int i = 0; i < getChildCount(); i++) {
            View view = getChildAt(i);
            nodes.put(view.getId(), new Node(view));
        }

        // Build dependencies for each View
        for (String viewId : nodes.keySet()) {
            Node node = nodes.get(viewId);
            RelativeLayout.LayoutParameters parameters = (RelativeLayout.LayoutParameters) node.view.getLayoutParameters();
            // Add dependencies for the Node
            for (Rule rule : parameters.dependencies.keySet()) {
                String childId = parameters.dependencies.get(rule);
                Node dependency = nodes.get(childId);
                if (dependency != null) {
                    node.dependencies.add(dependency);
                    dependency.dependents.add(node);
                }
            }
        }

        // Return all Nodes that do not have dependencies
        Deque<Node> roots = new ArrayDeque<Node>();
        for (Node node : nodes.values()) {
            if (node.dependencies.isEmpty()) {
                roots.addLast(node);
            }
        }

        return roots;
    }