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

  Рет қаралды 15,130

Hello World

Hello World

2 жыл бұрын

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

Пікірлер: 52
@shashwatkrishnashukla2284
@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🔥
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Thank you so much!!
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
Bro, placement lag gaya kya tumara ?
@vijay9183
@vijay9183 Жыл бұрын
Just 1 doubts, left and right ki value bhi check krra h n ? Root k value k saat saat
@jeelanibasha3984
@jeelanibasha3984 11 ай бұрын
Sir can we also use any other travesals also
@sohebshaikh3344
@sohebshaikh3344 2 жыл бұрын
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 2 жыл бұрын
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 Жыл бұрын
Bro, placement lag gaya kya tumara ?
@manojkhan5639
@manojkhan5639 Жыл бұрын
Mind-blowing explanation
@shridharsarraf2188
@shridharsarraf2188 2 жыл бұрын
Prince bhaiya this channel is literally gold😍😍
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks brother ☺️
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
Bro , a and b me kya store horaha hai ?? What kind of bool val
@shashikantrai5463
@shashikantrai5463 Жыл бұрын
@@PIYUSH-lz1zq a stores the left matched part and b stores the right matched part.
@gayatridhekane6131
@gayatridhekane6131 2 жыл бұрын
Thank you so much
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks a ton Bass pura playlist complete karo aap ... Uske baad aur confidence aa jayega
@ankita7119
@ankita7119 7 ай бұрын
amazing explanation!
@HelloWorldbyprince
@HelloWorldbyprince 7 ай бұрын
Thanks a lot
@techybhoot
@techybhoot Жыл бұрын
i think this code has a time comnplexity of n^2
@vitocarleone7197
@vitocarleone7197 2 жыл бұрын
ye taste case to liya hi nahi aapne------- root---= 1 / \ 1 subroot=== 1 / \ NUL NUll
@ankitaggarwal8556
@ankitaggarwal8556 2 жыл бұрын
Inorder means Left, root right. Why you mention root at the end or after bool b=(inorder(root->right, subroot->right))
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
Bro, placement lag gaya kya tumara ?
@pranavsharma7479
@pranavsharma7479 Жыл бұрын
simple solutionm thnks
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Thanks buddy
@Georgesoros-amrica-wale
@Georgesoros-amrica-wale Жыл бұрын
Nice teacher brother
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
It's my pleasure
@Georgesoros-amrica-wale
@Georgesoros-amrica-wale Жыл бұрын
@@HelloWorldbyprince bro make videos on Trie data structure playlist please
@trueevil2590
@trueevil2590 2 жыл бұрын
26 / \ subtree 10 30 Tree 26 / \ 10 30 / \ 26 / \ 10 30 It gives wrong answer on this case ?
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
Bro , a and b me kya store horaha hai ?? What kind of bool val
@Coder_DhruvArora
@Coder_DhruvArora 2 жыл бұрын
Subtree ka definition padho bro leetcode pe
@theone-pq9tp
@theone-pq9tp 2 жыл бұрын
bhai specific diagonal matrix ka bhai videos bnow na
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Matrix pe playlist hai mere channel pe Please go and watch
@somveerkhaunkar6191
@somveerkhaunkar6191 2 жыл бұрын
Bhaiya it's time complexity?
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
Bro, placement lag gaya kya tumara ?
@Alokkumar-xu8sf
@Alokkumar-xu8sf 2 жыл бұрын
Sir find the median of array sir es pe ek viedo
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
I think I already have please have a look around on my channel
@TarunKumar-cn6in
@TarunKumar-cn6in 2 жыл бұрын
What about time complexity for thi solution??
@Anurag-wv6ri
@Anurag-wv6ri 2 жыл бұрын
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 Жыл бұрын
Bro, placement lag gaya kya tumara ?
@pritishpattnaik4674
@pritishpattnaik4674 Жыл бұрын
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
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
nice way of learning bro
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
Bro, placement lag gaya kya tumara ?
@viditvaish7317
@viditvaish7317 10 ай бұрын
Traversal postorder chala rahe hai haina ??
@HelloWorldbyprince
@HelloWorldbyprince 9 ай бұрын
haan
@AdarshKumar-hf8mi
@AdarshKumar-hf8mi Ай бұрын
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
@f1__30__rahulkumarsingh4
@f1__30__rahulkumarsingh4 Жыл бұрын
Bhaiya honestly ye maine bhi socha tha adress wala
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
nice bro keep learning Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@priyanshgarg1292
@priyanshgarg1292 25 күн бұрын
// 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
@AbdulKhalid-hk8ty
@AbdulKhalid-hk8ty Жыл бұрын
2x is still slow.!!!
@sheikhinzaman8491
@sheikhinzaman8491 Жыл бұрын
koi muqabla nhi sir apka
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Hahahah Thanks a lot dost, Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 42 МЛН
check if a tree is subtree of another tree
7:40
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 33 М.