Z
Z
Zubchick2011-10-19 12:40:56
Algorithms
Zubchick, 2011-10-19 12:40:56

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

3 answer(s)
T
TheHorse, 2011-10-19
@TheHorse

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;

P
philpirj, 2011-10-19
@philpirj

First, you compare common features - bark, leaves / needles, height ...
It seems like the session is not coming soon?
Several algorithms are here .

E
eliah_lakhin, 2011-10-19
@eliah_lakhin

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 question

Ask a Question

731 491 924 answers to any question