Please tell me what is time complexity of this simple & standard Tree problem

Revision en1, by Gajanana, 2023-09-03 10:04:46

Is Time Complexity O(N), O(2N) or something else, why?

Please tell me space complexity also for this.

   bool solve(Node *root1, Node *root2)
    {
        if(root1 == NULL && root2 == NULL)
            return true;

        if((root1 == NULL) || (root2 == NULL))
            return false;

        if(root1->data != root2->data)
            return false;

        bool v1 = myfunc(root1->left, root2->left);
        bool v2 = myfunc(root1->left, root2->right);
        bool v3 = myfunc(root1->right, root2->right);
        bool v4 = myfunc(root1->right, root2->left);

        return (v1 & v3) | (v2 & v4);
    }

    
    bool isIsomorphic(Node *root1, Node *root2)
    {
        return solve(root1, root2);
    }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Gajanana 2023-09-03 10:04:46 841 Initial revision (published)