Algo::GetElementDependencies

Sorts the given range in leaf to root order: For every pair of elements (A,B) where SortedIndex(A) < SortedIndex(B), either B is not reachable from A, or A and B are mutually reachable.