Note that I’ve already gone through How to detect a loop in a hierarchy of javascript elements In our case, we’re not dealing with a linked-list, but a hierarchical graph where each node may have multiple children linked to it. For example, In this graph, we should detect the loop a -> b -> c -> a. Answer If you