check if a tree is subtree of another tree

Sdílet
Vložit
  • čas přidán 19. 02. 2017
  • Given two binary. Check whether one tree is a subtree of another tree.

Komentáře • 34

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi Před 4 lety +8

    You teach slowly , it becomes very easy to grasp the concept. Thank you so much for making videos !! Keep ti up

  • @RohitSharma-bu6lc
    @RohitSharma-bu6lc Před 4 lety

    This man right here deserves all the views. Great tutorial!

  • @mohamedelkayal8871
    @mohamedelkayal8871 Před 7 lety +1

    Thank you that was extremely helpful!!!

  • @TechGamerz1
    @TechGamerz1 Před 5 lety +4

    time complexity is o(n*m) where n and m is size of both

  • @liyuanzhang2206
    @liyuanzhang2206 Před 2 lety

    Very helpful. Thank you!

  • @nabnitpatnaik7762
    @nabnitpatnaik7762 Před 4 lety

    Nice video!! Do you have any videos for finding all the permutations possible for a given string?

  • @gandhijainamgunvantkumar6783

    Thank you so much for amazing explanation :)

  • @AkashVerma-vl7vq
    @AkashVerma-vl7vq Před rokem +1

    Keep it up sir...

  • @MohitKumar-rb5vl
    @MohitKumar-rb5vl Před 3 lety +2

    but.. time complexity is o(n^2) so this solution will give TLE in coding platform ...

  • @ankitaggarwal8556
    @ankitaggarwal8556 Před 2 lety

    Absolutely informative video.

  • @joeycopperson
    @joeycopperson Před 7 lety +8

    This is best explanation i have seen so far ...
    programming rocks \m/

  • @ryan-bo2xi
    @ryan-bo2xi Před 4 lety +1

    Hi also can i have a preorder traversal of the main tree and store the result in an array. Next i run preorder traversal for the subtree to be checked and match each node with the sequence in the array. Ideally both the preorder results should match. This is just another thought with extra space (array) .

  • @esraamohamed5601
    @esraamohamed5601 Před 5 lety

    Thank you very much !

  • @anishasrivastava8365
    @anishasrivastava8365 Před 6 lety +1

    Hi Vivekanand. Thank you for your video. I have one question checking for an identical subtree within this problem.
    Can there also be a true case when the subtree has no more nodes (so p2 == null) but the main tree still has nodes remaining (p1 != null). In this case, the subtree has already been found without traversing all the way down to tree 1's leaf nodes.
    From your video on checking if a tree is identical, can you explain how the true case (p1 == null && p2 == null) covers the scenario where the subtree has already been found, but nodes remain in the "main" tree?
    Thank you!

    • @ssiddique_info
      @ssiddique_info Před 2 lety

      According to the above explanation, no it won't be a subtree because we are checking for the identical tree. ut if the interviewer says to return True, in your case, you have to customize the code.

  • @gayatriarora4088
    @gayatriarora4088 Před 6 lety

    Sir I will be grateful to u if u post vedio solutions for following questions
    1. Inorder transversal of a binary tree without recursion and without stack
    2. Program to Construct a binary tree using given inorder and preorder transversal
    2.

  • @dhruv2014
    @dhruv2014 Před 2 lety

    Great tutorial 🔥🔥🔥

  • @yorulatte8208
    @yorulatte8208 Před 2 lety

    Very Good Explanation sir

  • @tango2olo
    @tango2olo Před 5 lety +2

    Play at 1.5x speed.

  • @sangappam217
    @sangappam217 Před 7 lety

    some algorithms on hashing

  • @JJ-Bond
    @JJ-Bond Před 5 lety +3

    can someone elaborate the time and space complexity here?

    • @ShreyaSingh-vr9qi
      @ShreyaSingh-vr9qi Před 4 lety

      Time Complexity must be O(n^2) using this concept, as we are checking each subtree of main tree.

  • @SumitKumar-pj9uo
    @SumitKumar-pj9uo Před 5 lety +1

    Time Complexity O(n)?

  • @deliveringIdeas
    @deliveringIdeas Před 2 lety

    Thank you sirji.

  • @kennash4916
    @kennash4916 Před 7 lety +4

    Sir, Your videos on Dynamic programming are awesome. Please make following videos if possible, Sir :
    1) Given a string, determine if a permutation of the string could form a palindrome.
    2) Count All Palindrome Sub-Strings in a String
    3) Find all distinct palindromic sub-strings of a given string
    4) Longest common substring
    5) Longest Palindromic Substring
    6) Print all palindrome permutations of a string
    7) Print all palindromic partitions of a string

  • @sangappam217
    @sangappam217 Před 7 lety

    sir, can you do some problems on hashing also

  • @Idris_icon
    @Idris_icon Před rokem

    انا عربي وافتهمت شكرا😂😂 فقط من الرسم

  • @chkmystyle
    @chkmystyle Před 5 lety +1

    Sir
    This code only works when subtree is part of main tree till leaf.
    We can have a subtree in middle of the main tree. Please revisit

    • @harishr5620
      @harishr5620 Před 4 lety +1

      No bro..In the base condition if the s pointer is null, then it returns 1.So it even works when it is in the middle