Subtree of Another Tree | Tree Data Structure playlist C++ | Hello World | LeetCode

Sdílet
Vložit
  • čas přidán 2. 09. 2021
  • This is the video under the series of DATA STRUCTURE & ALGORITHM in a TREE Playlist. We are going to understand How to make Subtree of Another Tree.
    Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
    complete DSA preparation: github.com/Prince-1501/Comple...
    ► 572. A subtree of Another Tree
    Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.
    A subtree of a binary tree is a tree that consists of a node in the tree and all of this node's descendants. The tree could also be considered as a subtree of itself.
    Input:
    T: 1 S: 3
    / \ /
    2 3 4
    / \ /
    N N 4
    Output: 1
    Explanation: S is present in T
    We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
    ----------------------------------------------------------------------------------------:
    Check if subtree: practice.geeksforgeeks.org/pr...
    A subtree of Another Tree: leetcode.com/problems/subtree...
    code in This Video: github.com/Prince-1501/Hello_...
    ----------------------------------------------------------------------------------------
    *Follow me *
    LinkedIn► / iamprince
    Facebook► / helloworldofficials
    Instagram► / helloworldbyprince
    Twitter► / prince_king_
    Telegram► telegram.me/helloworldbyprince
    ----------------------------------------------------------------------------------------
    ►Our Playlists on:-
    ► Tree: • Tree Data Structure & ...
    ► Hashing: • Hashing Data Structure...
    ► Matrix: • Matrix (Multidimension...
    ► STL: • Standard Template Libr...
    ► Leetcode: • LeetCode Solutions And...
    ►Competitive Programming: • Full course in Competi...
    ►C++ Full Course : • C++ full Course in HINDI
    ►Algorithms: • L-01 || Prefix Sum Arr...
    ►Data Structure: • Data Structures with C...
    ------------------------------------------------------------------------
    🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
    ✨ Tags ✨
    A subtree of Another Tree
    Check if subtree
    The tree Data structure in Hindi
    Use of Tree Data structure in real Life
    question asked in Google
    off-campus placement
    how to learn to code for beginners
    Practice Tree data structure
    tree in data structure
    Best Telegram channel for Off-campus Placement drive
    Tree in a data structure in Hindi
    Tree Full playlist for Beginners
    #Tree #Leetcode #programming

Komentáře • 52

  • @shashwatkrishnashukla2284

    Randomly found you while searching companies that offer WFH,and found your dsa playlist,it's soooo goooood,so underrated,keep up the good work sir🔥

  • @shridharsarraf2188
    @shridharsarraf2188 Před 2 lety +4

    Prince bhaiya this channel is literally gold😍😍

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +2

      Thanks brother ☺️

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq Před 2 lety

      Bro , a and b me kya store horaha hai ?? What kind of bool val

    • @shashikantrai5463
      @shashikantrai5463 Před rokem

      @@PIYUSH-lz1zq a stores the left matched part and b stores the right matched part.

  • @vijay9183
    @vijay9183 Před rokem

    Just 1 doubts, left and right ki value bhi check krra h n ? Root k value k saat saat

  • @sohebshaikh3344
    @sohebshaikh3344 Před 2 lety +1

    Hello Prince Bhaiya bs ye playlist ki 4 video aur baccha phir saath hi chalenge bhot accha aap explain krte h keep it up

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +1

      Thanks buddy ❤️
      Keep sharing my channel, playlist , videos
      Because your support is important for me
      Atleast share it with your friends

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq Před rokem

      Bro, placement lag gaya kya tumara ?

  • @manojkhan5639
    @manojkhan5639 Před rokem

    Mind-blowing explanation

  • @gayatridhekane6131
    @gayatridhekane6131 Před 2 lety +1

    Thank you so much

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +1

      Thanks a ton
      Bass pura playlist complete karo aap ...
      Uske baad aur confidence aa jayega

  • @ankita7119
    @ankita7119 Před 6 měsíci

    amazing explanation!

  • @jeelanibasha3984
    @jeelanibasha3984 Před 11 měsíci

    Sir can we also use any other travesals also

  • @techybhoot
    @techybhoot Před rokem +1

    i think this code has a time comnplexity of n^2

  • @pranavsharma7479
    @pranavsharma7479 Před rokem

    simple solutionm thnks

  • @ankitaggarwal8556
    @ankitaggarwal8556 Před 2 lety +1

    Inorder means Left, root right. Why you mention root at the end or after bool b=(inorder(root->right, subroot->right))

  • @vitocarleone7197
    @vitocarleone7197 Před 2 lety +1

    ye taste case to liya hi nahi aapne-------
    root---=
    1
    / \
    1
    subroot===
    1
    / \
    NUL NUll

  • @AdarshKumar-hf8mi
    @AdarshKumar-hf8mi Před 28 dny

    class Solution {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
    ArrayList mt = new ArrayList();
    ArrayList st = new ArrayList();
    inorder( root, mt);
    inorder(subRoot, st);
    if (st.size() == 0) return true;
    if (mt.size() < st.size()) return false;

    for(int i= 0 ;i

  • @Alokkumar-xu8sf
    @Alokkumar-xu8sf Před 2 lety +1

    Sir find the median of array sir es pe ek viedo

  • @theone-pq9tp
    @theone-pq9tp Před 2 lety +1

    bhai specific diagonal matrix ka bhai videos bnow na

  • @f1__30__rahulkumarsingh4

    Bhaiya honestly ye maine bhi socha tha adress wala

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      nice bro keep learning Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @Georgesoros-amrica-wale

    Nice teacher brother

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před rokem

    I have tried and attempted on my own first and then see the solution , understood where I am doing wrong , In my approach out of 180 testcases 161 passed

  • @priyanshgarg1292
    @priyanshgarg1292 Před 13 dny

    // If both nodes are null, they are identical
    if (root == null && subroot == null) {
    return true;
    }
    // If one of the nodes is null, they are not identical
    if (root == null || subroot == null) {
    return false;
    }
    // Check if the left subtrees are identical
    boolean leftIdentical = areIdentical(root.left, subroot.left);
    // Check if the current nodes' values are identical
    boolean currentIdentical = (root.val == subroot.val);
    // Check if the right subtrees are identical
    boolean rightIdentical = areIdentical(root.right, subroot.right);
    // The trees are identical if all three conditions are true
    return leftIdentical && currentIdentical && rightIdentical;
    checkout this way

  • @trueevil2590
    @trueevil2590 Před 2 lety +2

    26
    / \ subtree
    10 30
    Tree 26
    / \
    10 30
    / \
    26
    / \
    10 30
    It gives wrong answer on this case ?

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq Před 2 lety

      Bro , a and b me kya store horaha hai ?? What kind of bool val

    • @Coder_DhruvArora
      @Coder_DhruvArora Před 2 lety

      Subtree ka definition padho bro leetcode pe

  • @TarunKumar-cn6in
    @TarunKumar-cn6in Před 2 lety

    What about time complexity for thi solution??

    • @Anurag-wv6ri
      @Anurag-wv6ri Před 2 lety

      O(n) worst case, because suppose if you the have the same subTree as parentTree, then you have to check every node value. Similarly Auxiliary space complexity is O(h).

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq Před rokem

      Bro, placement lag gaya kya tumara ?

  • @viditvaish7317
    @viditvaish7317 Před 10 měsíci

    Traversal postorder chala rahe hai haina ??

  • @somveerkhaunkar6191
    @somveerkhaunkar6191 Před 2 lety

    Bhaiya it's time complexity?

  • @AbdulKhalid-hk8ty
    @AbdulKhalid-hk8ty Před rokem

    2x is still slow.!!!

  • @sheikhinzaman8491
    @sheikhinzaman8491 Před rokem

    koi muqabla nhi sir apka

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      Hahahah Thanks a lot dost, Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀