Answer the question
In order to leave comments, you need to log in
Compare two trees
Hello, I can’t find a description of any algorithm for comparing two trees, please tell me
Answer the question
In order to leave comments, you need to log in
function compare(tree1, tree2): boolean;
var i : integer;
begin
result := true;
if tree1.childCount <> tree2.childCount then
begin
result := false;
exit;
end;
for i:= 0 to tree1.childCount - 1 do
begin
if tree1.child[i].value <> tree2.child[i].value then
result := false
else
result := compare(tree1.child[i], tree2.child[i]);
if result = false then break;
end;
end;
First, you compare common features - bark, leaves / needles, height ...
It seems like the session is not coming soon?
Several algorithms are here .
I recommend looking here: stackoverflow.com/questions/523307/semantic-diff-utilities. In particular to the comment of Ira Baxter.
As my own option, I can suggest you, for example, make a tree representation in the form of a list (just a sequential traversal of all the vertices), and then apply the usual diff to this list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question