top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Quasi-Isomorphic Tree? Give a algorithm for constructing it?

+1 vote
1,138 views
What is Quasi-Isomorphic Tree? Give a algorithm for constructing it?
posted Jun 14, 2014 by Joy Dutta

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Two trees A and B are quasi-isomorphic if A can be transformed into B by swapping left and right children of some of the nodes of A. The values in the nodes are not important in determining quasi-isomorphic trees, only the shape is important.

See the following two quasi-isomorphic trees.
Quasi-isomorphic Trees

Now coming to your second question on construction of Quasi-Isomorphic Tree, since it is between two trees so we can write a function and passing two trees as parameters which can return two or false if quasi-isomorphic or not. Check the following code

struct node
{
  int data;
  struct node *lchild, *rchild;
}

bool is_quasi_isomorphic(struct node *treeA, struct node *treeB)
{
    if (!treeA && !treeB) // Both are NULL so return true
        return true; 
    if((!treeA && treeB) || (treeA && !treeB)) // Only one of them is null so false
        return false;

    return (is_quasi_isomorphic(treeA->lchild, treeB->lchild)
        && is_quasi_isomorphic(treeA->rchild, treeB->rchild)
        || is_quasi_isomorphic(treeA->rchild, treeB->lchild)
        && is_quasi_isomorphic(treeA->lchild, treeB->rchild));
}
answer Jun 15, 2014 by Salil Agrawal
Similar Questions
+5 votes

Example :
Let the list be {2,3,5} and Assume always 1 be included then

2th number is 2
3th number is 3
4th number is 4
5th number is 5
6th number is 6
7th number is 8
8th number is 9
9th number is 10
10th number is 12
11th number is 15 and so on...

...