[PATCH] Fix bug that CompareAtoms::compare is not transitive.

Sean Silva silvas at purdue.edu
Fri Oct 18 21:17:28 PDT 2013


On Fri, Oct 18, 2013 at 8:16 PM, Rui Ueyama <ruiu at google.com> wrote:

>
>   OK, so O(n^3) is probably not good even for debugging.


Where is the O(n^3)? I see a double loop that does O(n^2) work, but I don't
see anything O(n^3).


> I'll rewrite it with the same algorithm as topological sort, as
> topological sort can detect a cycle in a graph. That is much cheaper than
> this naive algorithm.
>

If the problem is the fully general problem "given n elements, and a
relation <, determine whether < is transitive", I don't think that
topological sorting is going to be of any help here, since it takes time
O(#vertices + #edges).

Another way to think about it is that when topologically sorting, for each
node you have to iterate over all its children. Since you can't assume
anything about the ordering (because that's what you're trying to verify!),
you have to do a linear scan of *all* the other nodes in order to find the
children.

-- Sean Silva


>
> http://llvm-reviews.chandlerc.com/D1980
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131019/ad39925b/attachment.html>


More information about the llvm-commits mailing list