Binary tree - 33: Check if Two Trees are Mirror to each other

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 10

  • @AbhishekKumar-qr5ql
    @AbhishekKumar-qr5ql 4 роки тому +1

    Short and Clear explanation , Good job!

  • @deeproy2719
    @deeproy2719 2 роки тому

    time complexity would be min(n1, n2)
    where n1 is no of nodes in tree1, n2 is no of nodes in tree2... let me know if it's correct

  • @Prince-yz1tc
    @Prince-yz1tc 4 роки тому +2

    Hey, your all videos are great, but can you please upload some more videos on Graphs!!

    • @CodingSimplified
      @CodingSimplified  4 роки тому

      I'll try to upload on Graph soon. Thanks for your interest.

  • @tilakrajrao2753
    @tilakrajrao2753 4 роки тому

    sir can we find mirror of any one tree and then compare the inorder of both the trees if same then return true else false

    • @reshmah1497
      @reshmah1497 3 роки тому

      No. It will give wrong answer

  • @pqazx1
    @pqazx1 4 роки тому +1

    bool width(node* root,node* root2)
    {
    if(root==NULL&&root2==NULL)
    {
    return true;
    }
    if(root==NULL||root2==NULL)
    {
    return false;
    }
    if(root->val==root2->val)
    {
    return true;
    }
    if(root->val!=root2->val)
    {
    return false;
    }
    return width(root->left,root2->right)&&width(root->right,root2->left);
    }
    why does this code not work ???? it is returning true always even if not mirror trees..

    • @CodingSimplified
      @CodingSimplified  4 роки тому

      The problem seems to be here:
      if(root->val==root2->val)
      {
      return true;
      }
      - If your root values are equal , it'll return true. It won't check further.
      - Remove this code & it should work fine.