L33. Requirements needed to construct a Unique Binary Tree | Theory

  Рет қаралды 85,857

take U forward

take U forward

2 жыл бұрын

Entire DSA Course: takeuforward.org/strivers-a2z...
Check our Website:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
#treeSeries #striver #placements

Пікірлер: 98
@takeUforward
@takeUforward 2 жыл бұрын
Please likeeee, shareeee and subscribeeeeeeee :) Also follow me at Insta: Striver_79
@amishasahu1586
@amishasahu1586 2 жыл бұрын
Understood sir!!!
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
// NOTE: Q. How does inorder+preorder/postorder construct unique binary tree? -> Imagine that you have the following pre-order traversal: a,b,c,d,e,f,g. What does that tell you? You know that a is the root of the tree, this follows from the definition of a pre-order traversal. So far, so good. You also know that the rest of your list is the traversal of the left subtree followed by the traversal of the right subtree. Unfortunately you don't know where the split is. It could be that all of them belong to the left tree, it could be that all of them belong to the right tree, or b,c go left and d,e,f,g go right and so on. How to resolve the ambiguity? Well, let's take a look at the in-order traversal, what is its defining property? Any elements in the left subtree of a will come before a in the in-order traversal and any elements in the right subtree will come after a. Again, this follows from the definition of in-order traversal. So what we need to do is take a look at the in-order traversal (let's say it's c,b,a,d,e,f,g). We can see that b and c come before a, therefore they're in the left subtree, while d,e,f and g are in the right subtree. In other words, as position in the in-order traversal uniquely determines which nodes will be in its left/right subtrees. And this is great because we can now go on and solve the two subtrees recursively: pre-order b,c/in-order c,b and pre-order d,e,f,g/in-order d,e,f,g. And you can continue this recursively until all subtrees only contain a single element, where the solution is trivially unique. And since at each step we could prove that there is only one valid way to continue, the result is that a given pair of in-order and pre-order traversals can only belong to a single tree. NOTE: found this on Quora. It might help.
@nagame859
@nagame859 8 ай бұрын
thanks, sir.
@ritikshrivastava9442
@ritikshrivastava9442 8 ай бұрын
one more thing to note u can construct unique bt only when all the values in bt is unique
@rishabhgupta1222
@rishabhgupta1222 23 күн бұрын
@@ritikshrivastava9442 nope it depends on node's address and not value
@stith_pragya
@stith_pragya 8 ай бұрын
Thank You So Much for this wonderful video..................🙏🙏🙏
@aswinikumarsahoo6459
@aswinikumarsahoo6459 Жыл бұрын
Recalled @Jenny's lectures CS/IT NET&JRF suddenly after 2 years, seeing the concept.
@sanchitsanyam7359
@sanchitsanyam7359 Ай бұрын
Really Bhaiya , your effort means allot to Student community, Your videos are awesome.
@anonymousvoid6356
@anonymousvoid6356 2 жыл бұрын
This guy has the same enthusiasm in all videos!
@priyanshkumariitd
@priyanshkumariitd 4 ай бұрын
thanks for awesome explanation striver bhaiya :)
@shauryatomer1058
@shauryatomer1058 Ай бұрын
thanks for the great content
@pratikmhatre4815
@pratikmhatre4815 8 ай бұрын
Very helpful
@bisssss21
@bisssss21 6 ай бұрын
the best teacher
@user-tk2vg5jt3l
@user-tk2vg5jt3l 3 ай бұрын
Thank you Bhaiya
@cinime
@cinime Жыл бұрын
Understood! Such an amazing explanation as always, thank you very much!!
@judgebot7353
@judgebot7353 9 ай бұрын
thanks
@sysfailureexe6038
@sysfailureexe6038 5 күн бұрын
Thanks u
@KartikeyTT
@KartikeyTT Ай бұрын
tysm sir
@ANURAGSINGH-nl2ll
@ANURAGSINGH-nl2ll 8 ай бұрын
Understand
@vivekreddy820
@vivekreddy820 4 ай бұрын
understood sir
@avanishmaurya2034
@avanishmaurya2034 5 ай бұрын
Nice
@atharvakulkarni2024
@atharvakulkarni2024 2 жыл бұрын
Excellent Explanation!!!
@SHASHANKRUSTAGII
@SHASHANKRUSTAGII 2 жыл бұрын
If you have a perfect binary tree, then given only the PREORDER and POSTORDER, you can construct your unique binary tree Source: NPTEL IIT DELHI, DR. Naveen Garg
@niranjansaha5135
@niranjansaha5135 Жыл бұрын
if it is a perfect binary tree, then with a single order traversal we can construct the tree. Am I saying anything wrong???
@parthsalat
@parthsalat Жыл бұрын
By perfect, you mean a complete binary tree, right?
@parthsalat
@parthsalat Жыл бұрын
@@niranjansaha5135 I guess, you are right
@SHASHANKRUSTAGII
@SHASHANKRUSTAGII Жыл бұрын
@@parthsalat right
@rishabhgupta1222
@rishabhgupta1222 23 күн бұрын
@@parthsalat no its wrong both are different
@anshulbhardwaj2666
@anshulbhardwaj2666 2 жыл бұрын
i best understood the concept from your videos sir thank you
@abhinanda7049
@abhinanda7049 2 ай бұрын
understood
@poojabennabhaktula4883
@poojabennabhaktula4883 2 жыл бұрын
Kudos to your effort!
@UjjawalSaran
@UjjawalSaran Ай бұрын
🔥
@Yash-uk8ib
@Yash-uk8ib 2 жыл бұрын
sir, what is the reason behind the fact that the inorder traversal along with any one of the remaining two traversals gives a unique binary tree and why not any other combination??
@sparshsharma6068
@sparshsharma6068 2 жыл бұрын
I think that, Since In inorder traversal, we can identify the left and right subtrees of a node but, the same won't be true in the case of the remaining traversals. Consider the following tree: 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / 8 9 10 Inorder traversal of this tree will be: [8,4,9,2,10,5,1,6,3,7] (LNR) postorder traversal of this tree will be: [8,9,4,5,2,6,7,3,1] (LRN) preorder traversal of this tree will be: [1,2,4,8,9,5,10,3,6,7] (NLR) Now, from this traversal, we can easily see that all the nodes on the left side of node 2 in the inorder traversal will form the left subtree. So that's why inorder along with post/preorder must give unique BTree.
@Yash-uk8ib
@Yash-uk8ib 2 жыл бұрын
@@sparshsharma6068 i think u have got a point!! Agreed!! Thanks for ur kind reply.
@sparshsharma6068
@sparshsharma6068 2 жыл бұрын
@@Yash-uk8ib Happy to help😊
@vibhu613
@vibhu613 2 жыл бұрын
@@sparshsharma6068 great Explaination
@sparshsharma6068
@sparshsharma6068 2 жыл бұрын
@@vibhu613 Thanks😄
@animeshmaru16
@animeshmaru16 2 жыл бұрын
One exception for this is.. If we have only one node in binary tree then we can construct unique binary tree from preorder and postorder traversal. Preorder: 1 Postorder: 1 Unique binary tree: 1 (Root node) Sounds like funny but we can explain this edge case in interview and can have more advantage 🙂
@ShivamJha00
@ShivamJha00 Жыл бұрын
bruh
@tarun_sahnan
@tarun_sahnan Жыл бұрын
if you have only one node that only there is no need for 2 traversal only one traversal will give you the solution. Preorder -> 10 10 is the root node
@editorera239
@editorera239 2 жыл бұрын
Thanks bro for prior explanation
@DilpreetSingh-cs7yz
@DilpreetSingh-cs7yz 2 жыл бұрын
why the inorder traversal along with any one of the remaining two traversals gives a unique binary tree and why not any other combination??
@priyanshkumariitd
@priyanshkumariitd 4 ай бұрын
Because we need to know not only the root but the left subtree & right subtree as well. So, one of the traversal should be inorder to identify UNIQUE BT.
@nileshsinha7869
@nileshsinha7869 2 жыл бұрын
Gonna complete the series tonight
@sangdilbiswal30
@sangdilbiswal30 18 күн бұрын
Hell yeah
@nagavedareddy5891
@nagavedareddy5891 2 жыл бұрын
Huge respect ❤👏
@momilijaz271
@momilijaz271 2 жыл бұрын
great tip!
@srivatsa1193
@srivatsa1193 2 жыл бұрын
this is awesome !
@lavanyaprakashjampana933
@lavanyaprakashjampana933 Жыл бұрын
we love your content and we love you.....🖤
@user-jg2me8ry7l
@user-jg2me8ry7l Жыл бұрын
you are just amazing sir
@amitswami3139
@amitswami3139 2 жыл бұрын
Very Good content striver
@tanishsharma5440
@tanishsharma5440 Жыл бұрын
Excellent Bro, perfect
@Professor-du2pf
@Professor-du2pf 5 ай бұрын
"US"
@tanyagupta4247
@tanyagupta4247 2 жыл бұрын
understood!
@SatyamEdits
@SatyamEdits Жыл бұрын
Hi Tanya ...!! Nice to see you ...again...!!! if you remember.....😅
@alesblaze4745
@alesblaze4745 Жыл бұрын
thanks mate!
@bhaveshkumar6842
@bhaveshkumar6842 2 жыл бұрын
Thank you bro!!
@shivangisrivastava1158
@shivangisrivastava1158 2 жыл бұрын
Amazing 👏👏
@UECAshutoshKumar
@UECAshutoshKumar 11 ай бұрын
Thank you sir
@cricketjanoon
@cricketjanoon Жыл бұрын
Undersstod! 👍
@naman_goyal
@naman_goyal 2 жыл бұрын
Best content brother
@parthsalat
@parthsalat Жыл бұрын
Understood kaka
@Ayush-lq3fz
@Ayush-lq3fz 2 жыл бұрын
understood :)))
@pawankumarpandit1822
@pawankumarpandit1822 Жыл бұрын
thank you striver bhaiya
@jaiminsolanki5478
@jaiminsolanki5478 2 жыл бұрын
Understood!
@vagabondfoodie5788
@vagabondfoodie5788 Жыл бұрын
Done till now 🥺🥺🥺 thankyou striver ❣️❣️
@Anonymous-uj3jx
@Anonymous-uj3jx 2 жыл бұрын
Thanks :)
@BG-lj6fw
@BG-lj6fw Жыл бұрын
understood.
@utkarshsharma6650
@utkarshsharma6650 2 жыл бұрын
understoooood
@Sumeet_100
@Sumeet_100 Жыл бұрын
Keep making this videos bhaiya
@dreamyme543
@dreamyme543 Жыл бұрын
Understood:)
@mriduljain1981
@mriduljain1981 11 ай бұрын
completed lecture 33 of free ka tree series.
@jayyy311
@jayyy311 Жыл бұрын
💚
@sujan_kumar_mitra
@sujan_kumar_mitra 2 жыл бұрын
Understood
@user-up6sl2gq8p
@user-up6sl2gq8p 8 ай бұрын
................
@stevefox2318
@stevefox2318 2 жыл бұрын
Bawaal🔥💪
@shreyasvishwakarma8979
@shreyasvishwakarma8979 2 жыл бұрын
noice video
@harshit8525
@harshit8525 Жыл бұрын
Striver Bhaiya zindabad!!!
@09_himanshusingh44
@09_himanshusingh44 2 жыл бұрын
Wow waiting for this 👍
@peddikarthik7832
@peddikarthik7832 Жыл бұрын
what if all the nodes have same value then answer wont be unique
@DoCTeRSinS
@DoCTeRSinS 8 ай бұрын
boooooooooooooooooooooooooooooooooooooooom
@suvanshmahajan5902
@suvanshmahajan5902 Жыл бұрын
"us"
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
reach++
@yashgupta-fk3zc
@yashgupta-fk3zc 2 жыл бұрын
first :)
@ojasdighe991
@ojasdighe991 2 жыл бұрын
🔺🔺
@harshitjaiswal9439
@harshitjaiswal9439 4 ай бұрын
understood
@abdulrazzak2934
@abdulrazzak2934 2 жыл бұрын
understood!
@aftabalam7103
@aftabalam7103 Жыл бұрын
Understood
@pratikshadhole6694
@pratikshadhole6694 Жыл бұрын
understood
@rishabhgupta9846
@rishabhgupta9846 Жыл бұрын
understood
@manojnavinjamuri5867
@manojnavinjamuri5867 Жыл бұрын
understood
@chinu_.16
@chinu_.16 Жыл бұрын
understood
@VikasGupta-ok9lh
@VikasGupta-ok9lh Жыл бұрын
Understood
@roopeshn3301
@roopeshn3301 Жыл бұрын
Understood
L31. Minimum time taken to BURN the Binary Tree from a Node | C++ | Java
18:24
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 4,7 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 12 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 105 МЛН
G-45. Prim's Algorithm - Minimum Spanning Tree - C++ and Java
19:10
take U forward
Рет қаралды 200 М.
L7. N Meeting in One Room | Greedy Algorithms Playlist
13:12
take U forward
Рет қаралды 7 М.
G-46. Disjoint Set | Union by Rank | Union by Size | Path Compression
42:15
10.1 AVL Tree - Insertion and Rotations
43:08
Abdul Bari
Рет қаралды 1,1 МЛН
DP 33. Edit Distance | Recursive to 1D Array Optimised Solution 🔥
37:39
BS-8. Single Element in Sorted Array
22:16
take U forward
Рет қаралды 119 М.