Subtree of Another Tree | Tree Data Structure playlist C++ | Hello World | LeetCode
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
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🔥
Thank you so much!!
Bro, placement lag gaya kya tumara ?
Prince bhaiya this channel is literally gold😍😍
Thanks brother ☺️
Bro , a and b me kya store horaha hai ?? What kind of bool val
@@PIYUSH-lz1zq a stores the left matched part and b stores the right matched part.
Just 1 doubts, left and right ki value bhi check krra h n ? Root k value k saat saat
Hello Prince Bhaiya bs ye playlist ki 4 video aur baccha phir saath hi chalenge bhot accha aap explain krte h keep it up
Thanks buddy ❤️
Keep sharing my channel, playlist , videos
Because your support is important for me
Atleast share it with your friends
Bro, placement lag gaya kya tumara ?
Mind-blowing explanation
Thank you so much
Thanks a ton
Bass pura playlist complete karo aap ...
Uske baad aur confidence aa jayega
amazing explanation!
Thanks a lot
Sir can we also use any other travesals also
i think this code has a time comnplexity of n^2
simple solutionm thnks
Thanks buddy
Inorder means Left, root right. Why you mention root at the end or after bool b=(inorder(root->right, subroot->right))
Bro, placement lag gaya kya tumara ?
ye taste case to liya hi nahi aapne-------
root---=
1
/ \
1
subroot===
1
/ \
NUL NUll
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
Sir find the median of array sir es pe ek viedo
I think I already have please have a look around on my channel
bhai specific diagonal matrix ka bhai videos bnow na
Matrix pe playlist hai mere channel pe
Please go and watch
Bhaiya honestly ye maine bhi socha tha adress wala
nice bro keep learning Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
Nice teacher brother
It's my pleasure
@@HelloWorldbyprince bro make videos on Trie data structure playlist please
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
nice way of learning bro
Bro, placement lag gaya kya tumara ?
// 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
26
/ \ subtree
10 30
Tree 26
/ \
10 30
/ \
26
/ \
10 30
It gives wrong answer on this case ?
Bro , a and b me kya store horaha hai ?? What kind of bool val
Subtree ka definition padho bro leetcode pe
What about time complexity for thi solution??
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).
Bro, placement lag gaya kya tumara ?
Traversal postorder chala rahe hai haina ??
haan
Bhaiya it's time complexity?
Bro, placement lag gaya kya tumara ?
2x is still slow.!!!
koi muqabla nhi sir apka
Hahahah Thanks a lot dost, Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀