c++ both DFS ( recursion ) and BFS (iterative) solutions
Solution 1: DFS (recursion)\n\n\nbool helper_dfs(TreeNode* root1, TreeNode* root2)\n    {\n        if(root1==NULL && root2==NULL)\n            return true;\n   
Solution 1: DFS (recursion)\n\n```\nbool helper_dfs(TreeNode* root1, TreeNode* root2)\n    {\n        if(root1==NULL && root2==NULL)\n            return true;\n        if(root1==NULL || root2==NULL)\n            return false;\n        if(root1->val!=root2->val)\n            return false;\n        \n        return (helper_dfs(root1->left,root2->left) && helper_dfs(root1->right,root2->right)) || (helper_dfs(root1->left,root2->right) && helper_dfs(root1->right,root2->left));\n    }\n bool flipEquivDFS(TreeNode* root1, TreeNode* root2) {\n        return helper_dfs(root1,root2);\n    }\n```\nComplexity: \nTC: O(min(n1,n2)) \nSC: O(min(n1,n2))\n\nSolution 2: BFS(iterative)\n```\nbool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        queue<TreeNode*> q;\n        TreeNode* temp1,*temp2;\n        q.push(root1);\n        q.push(root2);\n        while(q.size()!=0)\n        {\n            temp1 = q.front();\n            q.pop();\n            temp2=q.front();\n            q.pop();\n            if(temp1==NULL && temp2==NULL)\n                continue;\n            else if(temp1==NULL || temp2==NULL || temp1->val!=temp2->val)\n                return false;\n            else if(issamechildren(temp1->left,temp2->left) && issamechildren(temp1->right,temp2->right))\n            {\n                q.push(temp1->left);\n                q.push(temp2->left);\n                q.push(temp1->right);\n                q.push(temp2->right);\n            }\n            else if(issamechildren(temp1->left,temp2->right) && issamechildren(temp1->right,temp2->left))\n            {\n                q.push(temp1->left);\n                q.push(temp2->right);\n                q.push(temp1->right);\n                q.push(temp2->left);\n            }\n            else\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n        // BFS helper\n    bool issamechildren(TreeNode* root1, TreeNode* root2)\n    {\n        if(root1==NULL && root2==NULL)\n            return true;\n        if(root1==NULL || root2==NULL || root1->val!=root2->val)\n            return false;\n        return true;\n    }\n```\nComplexity:\nTC: O(n1+n2) \nSC: O(n1+n2)
[]