<p>This is called the <strong>tree to tree correction problem</strong> or the <strong>tree to tree editing problem</strong>. Most of the literature dealing with this explicitly relates to comparing XML trees for some reason, so searching for "XML diffing algorithm" yields a lot of results. In addition to Nikos's list of links, I found these:</p>

<ul>
<li><a href="https://osr.cs.fau.de/wp-content/uploads/2015/11/doc014f-dohrn.pdf" rel="nofollow noreferrer">Fine-grained Change Detection in Structured Text
Documents</a> (2014)</li>
<li><a href="https://www.researchgate.net/publication/241180098_Change_Detection_by_Level_CDL_An_efficient_algorithm_to_detect_change_on_XML_documents/link/554795870cf2e2031b37203c/download" rel="nofollow noreferrer">Change Detection by Level (CDL): An Efficient Algorithm to Detect Change on XML Documents</a> (2010)</li>
<li><a href="https://era.library.ualberta.ca/items/377060f4-3a31-4dc9-b7f0-ea2dda3cf38a" rel="nofollow noreferrer">Comparing XML Documents as Reference-aware Labeled Ordered Trees</a> (2011) <strike>The code for this - <a href="https://users.encs.concordia.ca/~nikolaos/vtracker.html" rel="nofollow noreferrer">VTracker</a> still exists!</strike> Edit: actually the interesting bit of code is not included. This pointed me to...</li>
<li><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.66.3343&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">UMLDiff: An Algorithm for Object-Oriented
Design Differencing </a> (2005).</li>
<li><a href="https://arxiv.org/pdf/1805.06869.pdf" rel="nofollow noreferrer">Revisiting the tree edit distance and its backtracing: A tutorial</a> (2018) - looks like a good tutorial for the Zhang-Shasha algorithm, which seems to be the "classic" solution, but has terrible time complexity because it compares every sub-tree with every other sub-tree.</li>
</ul>

<p>I also strongly recommend reading <a href="https://pdfs.semanticscholar.org/40f3/fb27f0708a69153006ee1debee7c94663dca.pdf" rel="nofollow noreferrer">Change Detection in XML Trees: a Survey</a> but it is from 2005 so barely any of the tools it mentions exist anymore. <em>Comparing XML Documents as Reference-aware Labeled Ordered Trees</em> has the best intuitive description of some of the algorithms that I have found so far (start at section 2.1.2).</p>

<p>Unfortunately there doesn't seem to be much open source code available that does this and isn't ancient. Just a lot of overly-complex papers. :-/</p>
Calculate minimal operations to make two tree structures identical
<p>This is more of a CS question, but an interesting one :</p>

<p>Let's say we have 2 tree structures with more or less the same nodes reorganized. How would you find</p>

<ol>
<li><em>any</em> </li>
<li>in some sense <em>minimal</em></li>
</ol>

<p>sequence of operations </p>

<ul>
<li><code>MOVE(A, B)</code> - moves node A under node B (with the whole subtree)</li>
<li><code>INSERT(N, B)</code> - inserts a <strong>new</strong> node N under node B </li>
<li><code>DELETE (A)</code> - deletes the node A (with the whole subtree)</li>
</ul>

<p>that transforms one tree to the other.</p>

<p>There might obviously be cases where such transformation is not possible, trivial being root A with child B to root B with child A etc.). In such cases, the algorithm would simply deliver an result "<em>not possible</em>".</p>

<p>Even more spectacular version is a generalization for networks, i.e. when we assume that a node can occur multiple times in the tree (effectively having multiple "parents"), while cycles are forbidden.</p>

<p>Disclaimer : This is <strong>not</strong> a homework, actually it comes from a real business problem and I found it quite interesting wondering if somebody might know a solution.</p>