Hacker News new | ask | show | jobs
by IshKebab 1935 days ago
Tree diffing algorithms have very bad complexity (e.g. O(N^4)!) so this will probably only work on really small examples.
1 comments

I have a use case for diffing trees, so would love to know of any optimal algorithms you may know of; I'm operating generally with less than 100 nodes, so it's not a huge concern, but I'm finding that discovering _any_ algorithms for this has been tough.
Yeah I found the same. It seems that there hasn't really been much research in this area, and somewhat annoyingly there isn't a widely agreed term for the problem, though for some reason most of the algorithms are described in terms of diffing XML so if you search for "XML difference" you can find some papers.

There's a few algorithms like XDiff, XyDiff, XChange etc. but be prepared to find very old code on sourceforge or more likely no code at all.

I couldn't find anything with a decent complexity that either had code or was simple/well described enough that I could implement it so I gave up.