Тёмный

Binary Trees in Python: Introduction and Traversal Algorithms 

LucidProgramming
Подписаться 43 тыс.
Просмотров 210 тыс.
50% 1

This video is sponsored by Oxylabs. Oxylabs provides market-leading web scraping solutions for large-scale public data gathering. You can receive data in JSON or CSV format and pay only per successful request. At the moment, Oxylabs offers a free trial.
oxylabs.io/?ut...
In this video, we will go over the binary tree data structure. We then go over how to implement this data structure in Python. We then cover the three recursive depth-first search traversal algorithms (preorder, inorder, and postorder) and implement those recursively in Python.
The software written in this video is available at:
github.com/vpr...
The slides for this video can be found here:
drive.google.c...
Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:
bit.ly/lp_vim
If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
bit.ly/lp_subsc...

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 451   
@LucidProgramming
@LucidProgramming 6 лет назад
Note that @26:30 I call the "inorder" traversal function inside of the "postorder" traversal function and neglected to change it to postorder. This was a copy-paste error. You can fix it by changing the "inorder" call in postorder to the appropriate postorder call. Sorry for the mistake, and thanks for watching!
@Soccercrazyigboman
@Soccercrazyigboman 5 лет назад
How can you go from child back to parent if you don't have a next and previous pointer?
@Soccercrazyigboman
@Soccercrazyigboman 5 лет назад
By next and previous I should say if each node doesnt have a pointer pointing to the one above it as well as to the one below it?
@AshwaniKumar-dj6re
@AshwaniKumar-dj6re 5 лет назад
@@Soccercrazyigboman he is using recursion
@NicholasSilva1380
@NicholasSilva1380 5 лет назад
That changes the expected output from 4-2-5-6-3-7-1- to 4-5-2-6-7-3-1-
@violetkimani3118
@violetkimani3118 5 лет назад
Hi, would be more efficient to add a function from within the class for adding values to the tree? does it help/ would it be more efficient especially during interviews
@safderaree
@safderaree 5 лет назад
Hands down the best explanation, I've struggled for so long trying to get the intuition through my textbook. Thanks!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@safderaree
@safderaree 5 лет назад
@@LucidProgramming Sure, I've subscribed and signed up for the mailing list. You've made my interviewing process so much smoother.
@LucidProgramming
@LucidProgramming 5 лет назад
@@safderaree Awesome, that's really great to hear! :)
@muhammadsalisabdulsalam4016
@muhammadsalisabdulsalam4016 5 лет назад
This is the most simplified video tutorial with good examples, the best I have seen so far. I got everything after watching this video only once. A lot of online tutorials are just too ambiguous and really confusing. Lucid you're the best for sure. Thanks a lot
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@muhammadsalisabdulsalam4016
@muhammadsalisabdulsalam4016 5 лет назад
@@LucidProgramming Sure, I'm interested. But how do I subscribe to your mail list please?
@LucidProgramming
@LucidProgramming 5 лет назад
@@muhammadsalisabdulsalam4016 Just follow the link here: bit.ly/lp_email :)
@bijayamanandhar3890
@bijayamanandhar3890 4 года назад
Thank you for the great tutorial! I am a new developer still looking for a job after graduation from a boot camp. I never had a chance to learn the data-structure, dfs, bfs etc before. Now, it's getting clear to me step by step after watching the videos you posted.
@LucidProgramming
@LucidProgramming 4 года назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@bhaskarbhuyan30
@bhaskarbhuyan30 5 лет назад
Very informative and easy-to-understand tutorial. Thank you for this incredible contribution to the enthusiasts and learners!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@jayaramakapil5295
@jayaramakapil5295 5 лет назад
All Superheroes don't Wear Capes. Some wear Suit too :)
@LucidProgramming
@LucidProgramming 5 лет назад
Haha, well I hope the videos are helpful to you. Cheers, and thanks for watching!
@hemesh5663
@hemesh5663 2 года назад
Dude you earned a subscriber and a fan
@LucidProgramming
@LucidProgramming 2 года назад
Thank you, man! Sincerely appreciate the support and love! Cheers!
@Unknown_22-z8c
@Unknown_22-z8c 2 года назад
very good video for those who want to pick the grasp of binary tree quickly
@LucidProgramming
@LucidProgramming 2 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@CodeX-mhs
@CodeX-mhs 5 месяцев назад
Extremely thankful to you sir.
@LucidProgramming
@LucidProgramming 5 месяцев назад
Thank you for the kind words, glad the videos are useful for you!
@CodeX-mhs
@CodeX-mhs 5 месяцев назад
@@LucidProgramming A very welcome sir. Please keep providing. The growth doesn’t justify ur quality. Keep it up sir.
@ilanaizelman3993
@ilanaizelman3993 2 года назад
Can't be explained better. Thank you!
@LucidProgramming
@LucidProgramming 2 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@ilanaizelman3993
@ilanaizelman3993 2 года назад
@@LucidProgramming Done! :) Are you during Mock Interviews? Or know someone who does?
@LucidProgramming
@LucidProgramming 2 года назад
@@ilanaizelman3993 Thank you, Ilan! Your support is very much appreciated! And yes, I do perform mock interviews, coaching, and consulting services for software-based job preparation. If you're interested in setting something up, you're free to reach out to me in the "About" section of my channel and we can coordinate from there if you like. Cheers, and best of luck in your preparation in any case!
@DanielGarcia-uq8yz
@DanielGarcia-uq8yz Год назад
I'm only 3 min in but love the explanations. Thanks!
@LucidProgramming
@LucidProgramming Год назад
Great to hear, and thank you for the kind words!
@rohith8269
@rohith8269 3 года назад
great explanation!!
@LucidProgramming
@LucidProgramming 3 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@SaltAndVi
@SaltAndVi 3 года назад
phenomenal video, thank you so much!!!
@LucidProgramming
@LucidProgramming 3 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@hoangphuoccao117
@hoangphuoccao117 3 года назад
Great explanations! Thank you very much!!
@LucidProgramming
@LucidProgramming 3 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@toderickson6106
@toderickson6106 2 года назад
good clarification skills, gave it a like
@LucidProgramming
@LucidProgramming 2 года назад
Very much appreciated--thank you for the support!
@DavidKaplanProgramming
@DavidKaplanProgramming 5 лет назад
Really good tutorial man! Thanks
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you, David, I'm very happy to hear that you enjoyed the tutorial! Cheers.
@ramiz3570
@ramiz3570 5 лет назад
Amazing explanation, thanks!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@vnpikachu4627
@vnpikachu4627 6 лет назад
Great work very easy to understand i really appreciate what you are doing to help us
@LucidProgramming
@LucidProgramming 6 лет назад
Hey Huru. Thank you very much for that comment. It's really great to hear that these videos have been helpful to you. I really get a lot of enjoyment from doing so as well, so the benefit is mutual! Cheers and thanks again for watching.
@vnpikachu4627
@vnpikachu4627 6 лет назад
Just 30 minutes i go from nothing to understand a lot more about tree could you please make a tutorial about graph and some algorithm about tree ?
@LucidProgramming
@LucidProgramming 6 лет назад
Really happy to hear that. Yes, graphs are most certainly coming up soon! Thanks for the suggestion and for the comment!
@drcylon
@drcylon 3 года назад
I think there is a little error in the "print_tree()" function, it shouldn't be "tree.root" it should be "self.root" ! Plus the "postorder" error pointed out in some comments below! Still, it is a great effort. Thanks.
@LucidProgramming
@LucidProgramming 3 года назад
Indeed, thank you for the comment!
@turjo119
@turjo119 4 года назад
I was stuck for hours trying to understand this, you made it so simple! Thank you so much
@LucidProgramming
@LucidProgramming 4 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@turjo119
@turjo119 4 года назад
@@LucidProgramming Done and done my good man!
@LucidProgramming
@LucidProgramming 4 года назад
@@turjo119 Cheers, thank you!
@MomoDiff48
@MomoDiff48 2 года назад
Just a small question, is it necessary to make whole class BinaryTree just for the root node? or it has something to do with python versions?
@rhythmsaparia8788
@rhythmsaparia8788 5 лет назад
Your explanation to data structure concepts in python is THE best!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@rohitashpathak260
@rohitashpathak260 4 года назад
I started learning python data structure only after watching your videos. Thank you so much. Do you have some projects in python that can we can go through, it will help to build the overall confidence level in coding.
@LucidProgramming
@LucidProgramming 4 года назад
Great to hear. As for projects, I offer tutoring. You can reach out to my email and I can provide you rates and ideas. Cheers!
@rohitashpathak260
@rohitashpathak260 4 года назад
LucidProgramming Thanks for your response but if you have some free contents that you can share will be a great help.
@LucidProgramming
@LucidProgramming 4 года назад
@@rohitashpathak260 Due to time constraints, I may have to back away. I can suggest the other content on my RU-vid channel, though!
@valentynsson5969
@valentynsson5969 4 года назад
Legend perfect explanation thank´s I like it.
@LucidProgramming
@LucidProgramming 4 года назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@kowyo
@kowyo 4 месяца назад
Thank you for this video
@cdemr
@cdemr 2 года назад
I am on Pycharm and I am a beginner. I do not understand what you're doing at 18:15. I can force-erase the consol but I can't write inside it.
@edgarlip2
@edgarlip2 4 года назад
wow - it is awesome !!! i can tell one analogy that helped me a lot : when do i collect the value : • pre-order - when value collected ?: once I am hovering on a node I am collecting it's value. • in-order - when value collected ?: if the node has no left node or the left node is already visited then add this value. • post-order - when value collected ?: once the node has no left nor right or left and right has been already visited then I will collect the value. HTH
@LucidProgramming
@LucidProgramming 4 года назад
Thanks, and yes that's a great way to remember them!
@ГоранДеспотовић
Thank you sir!
@LucidProgramming
@LucidProgramming Год назад
You're very welcome. Thank you for watching!
@ГоранДеспотовић
@@LucidProgramming I watched many videos on this subject, yours is spot on! You're a great teacher, thanks again!
@LucidProgramming
@LucidProgramming Год назад
@@ГоранДеспотовић thank you for the kind words!
@robn8656
@robn8656 4 года назад
Just incase there's someone like me out there: I struggled forever to understand how this code and recursive data structures generally worked until I finally understood recursion. Al Sweigart has a great video on recursion but essentially recursive functions use a stack method to determine how the functions are called. the subsequent functions can't be called until the previous one has been removed from the stack. each number being appended to the string is that function being removed from the stack. So, counterintuitively, the string begins with one because it's the LAST METHOD to be cleared from the stack. All, the other methods cycle through the tree first, appending their value to the string. It sounds backwards, I know. I don't even know if I explained it well but you have to understand recursion to understand BST. Watch Sweigart's video.
@LucidProgramming
@LucidProgramming 4 года назад
Cool, thanks for sharing and thanks for watching!
@chrisgoehl2745
@chrisgoehl2745 4 года назад
Great Video! Thank you for visualising and really emphasizing on the most basic aspects as this is something which I personally as a Beginner seem to struggle with! Keep up the good work it is really appreciated!
@LucidProgramming
@LucidProgramming 4 года назад
Thanks, Chris! That feedback is really helpful for me and I will try to keep that in mind for future videos. Thanks again for watching and for the comment!
@khavishbhundoo3792
@khavishbhundoo3792 6 лет назад
Could you include the link for the presentation as well.It serves as a quick recap.Thanks for the great explanation.
@LucidProgramming
@LucidProgramming 6 лет назад
At the moment, those slides are a bit all over the place. However, it would certainly not be an issue to clean them up and post a link in the description of this video. Might take me a while to get around to it, but I'll add it to the list. Thanks for the suggestion and thanks for watching! :)
@vitaliano01
@vitaliano01 3 года назад
Thank you.
@LucidProgramming
@LucidProgramming 3 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@deojeetsarkar2006
@deojeetsarkar2006 5 лет назад
Your videos deserve more views
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@faithnwokoma
@faithnwokoma 3 года назад
def postorder_print(self, start, traversal): #Left -> Right -> Root if start: traversal = self.postorder_print(start.left, traversal) traversal = self.postorder_print(start.right, traversal) traversal += (str(start.value) + "-") return traversal
@LucidProgramming
@LucidProgramming 3 года назад
Cool, thanks for sharing!
@user-vj3fs4cq9n
@user-vj3fs4cq9n Год назад
amazing video
@dmgisi
@dmgisi 2 года назад
I appreciate the good video and clear explanation. With a little more editing and attention to detail, it can become more polished and will be excellent.
@LucidProgramming
@LucidProgramming 2 года назад
Thank you! I hope that the videos on this channel keep getting progressively better. Thanks for watching!
@cudanakiju0
@cudanakiju0 3 года назад
@17:04 you type tree.root, shouldn't that be self.root instead?
@bronik7
@bronik7 2 года назад
That's what I thought. It's not clear to me how object will know it's instance
@samkruse6242
@samkruse6242 6 лет назад
This is gold
@LucidProgramming
@LucidProgramming 6 лет назад
Thanks, Sam! I'm glad that this video was useful to you. Thanks for the comment and for watching! Cheers.
@minaliaggarwal
@minaliaggarwal 6 лет назад
Hi- I think the code for post-order traversal might be incorrect. Is it supposed to output: [4, 5, 2, 6, 7, 3, 1]? Saw a similar tree in this article with this as the output: www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/
@LucidProgramming
@LucidProgramming 6 лет назад
Hi Minali. You are absolutely correct. I checked to make sure the other traversals are correct, and they appear to be. As you say though, there seems to be something incorrect about the post-order traversal. I will be updating the code and also adding a note to the video to ensure others are aware of this. Thank you very much for pointing out my error, I sincerely appreciate this as it improves the quality of the content on this channel. Cheers, and thank you again.
@minaliaggarwal
@minaliaggarwal 6 лет назад
No problem! Thanks for fixing it!
@LucidProgramming
@LucidProgramming 6 лет назад
Ah actually, I believe my issue here was I was calling the "inorder" function inside of the "postorder" function. Another helpful commenter pointed this out and I have since fixed the code. D'oh! :) Thanks again for letting me know, and thanks for your help!
@kshitijtewari2025
@kshitijtewari2025 5 лет назад
Thanks Sir, what is difference b/w class Node(object): and class Node:
@LucidProgramming
@LucidProgramming 5 лет назад
No difference at all!
@amithpandit4043
@amithpandit4043 5 лет назад
That's right. No difference. According to the link below: in Python 2.7 and older, you need to add the object inside parenthesis. In Python 3 and above, it doesn't make a difference. introtopython.org/classes.html
@abhinavreddy5350
@abhinavreddy5350 4 года назад
@@amithpandit4043 kk tq :)
@ajayprajapati2453
@ajayprajapati2453 4 года назад
Hi..Thank you so much for uploading video with nice explanation..
@LucidProgramming
@LucidProgramming 4 года назад
Cheers! If you found the video helpful, I would definitely appreciate any a like/subscribe/share! Thanks for watching!
@hackytech7494
@hackytech7494 4 года назад
Thank you so much for your explanation it was wonderful. I am having one doubt we haven't coded to go up if we don't have left or right children, then how it goes up programaticaly
@LucidProgramming
@LucidProgramming 4 года назад
Hi Tammay. Thanks for the comment. You might want to check out my recursion playlist if that part is tripping you up. I think it clarifies your confusion. Cheers!
@hackytech7494
@hackytech7494 4 года назад
@@LucidProgramming Ok Thank you so much sir. I will go through that playlist first.
@LucidProgramming
@LucidProgramming 4 года назад
@@hackytech7494 Cheers!
@asiacaster3663
@asiacaster3663 4 года назад
Im trying to wrap my head around saving the recursive calls in two variables both named traversal in the preorder_print function.. I have spent quite a lot of time learning recursive functions recently (including your videos and others), and thought I understoodd them well for things like binary search and what not, but I still can not picture/map what is going on in my head with those calls in that function, I am getting extremely frustrated right now. Great channel btw, subscribed.
@LucidProgramming
@LucidProgramming 4 года назад
Recursion is one of those things that I think takes a while in wrapping ones head around. I've worked directly with Sam from Byte-by-Byte and he has some really fantastic material on recursion. Specifically, he provides a free e-book on recursion and dynamic programming that has really great visuals of which I haven't really seen elsewhere. I'd recommend giving that a look. And, also, don't get discouraged. Learning these things takes time and practice. Thanks for the support and subscription.
@TechArtGenius
@TechArtGenius Месяц назад
The height and depth concept..I think the depth at the root node is depth 0 and increases by 1 as you go down the tree. And this is the opposite for the heights. But looks like you started counting at 1 instead of 0.
@pythondev2631
@pythondev2631 2 года назад
It is the first time that I come across Instantiate an object of another class without passing it as an argument (Node in BianryTree). Is this a common practise?
@carsonisgayandugly
@carsonisgayandugly 4 года назад
Hi, thank you so much for the video. I am a little confused still about one thing. When in the preorder traversal, when it comes to a leaf that dosn't have a left or right node, in the code how does it go backwards to the previous node or back to the root?
@LucidProgramming
@LucidProgramming 4 года назад
I would encourage you to check out my playlist on recursion, as it seems you have a gap in understanding how recursive calls are treated.
@NoorAli-uh4uq
@NoorAli-uh4uq 5 лет назад
Amazing content but one question, why I thought in Binary trees the left_child should be less than the root, in that case if the root is 1 then the left_child cannot be 2. May be I am wrong but I appreciate if clarify that, thanks again for the amazing content.
@LucidProgramming
@LucidProgramming 5 лет назад
Thanks Noor. Regarding your comment, you're thinking of binary search trees. I have a whole playlist on them as well that you might enjoy. Cheers!
@NoorAli-uh4uq
@NoorAli-uh4uq 5 лет назад
Thanks for reply, I am checking your page but cannot see the Binary Search Tree vidoes, I have seen Data structures which consists of 40 video and the last 7 deals with Trees, I am not sure if they are contained there. Thanks.
@LucidProgramming
@LucidProgramming 5 лет назад
Hi Noor. There is a BST playlist. You can find it here: bit.ly/lp_bst. Cheers!
@NoorAli-uh4uq
@NoorAli-uh4uq 5 лет назад
Thanks @@LucidProgramming
@LucidProgramming
@LucidProgramming 5 лет назад
@@NoorAli-uh4uq No problem! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@someshsangwan3768
@someshsangwan3768 3 года назад
Thnq sir I am facing a TypeError: Binary tree takes no argument . Tell me about this
@LucidProgramming
@LucidProgramming 3 года назад
You might want to check your code against my GitHub code.
@shivamdubey9225
@shivamdubey9225 4 года назад
Please make videos on bfs and dfs and some of its important use , in python it is hard to find on utube
@LucidProgramming
@LucidProgramming 4 года назад
It's on my list of videos to make! Subscribe and stay tuned!
@debashishchakraborty7924
@debashishchakraborty7924 4 года назад
@@LucidProgramming ..you are not making new videos, no one can explain python data structures better than you. please do something....
@LucidProgramming
@LucidProgramming 4 года назад
@@debashishchakraborty7924 Lots of balls up in the air at the moment. Right now, I'm putting together a book that I hope to have video content for. Stay tuned!
@vnaveenkumar982
@vnaveenkumar982 4 года назад
@@LucidProgramming Thanks for the tutorial... please make such videos in python about data structures and you explain it like a pro please continue..
@LucidProgramming
@LucidProgramming 4 года назад
@@vnaveenkumar982 Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@VarunKumar-pz5si
@VarunKumar-pz5si 4 года назад
Can you explain the recursion in pre-order traversal?
@LucidProgramming
@LucidProgramming 4 года назад
Got a whole playlist on recursion you can check out!
@wm4437
@wm4437 3 года назад
In the last posorder he just copy from inorder you need change in self.inorder to posorder If you get result 4-2-5 not 4-5-2
@LucidProgramming
@LucidProgramming 3 года назад
Yep, I believe my pinned comment addresses this point. Thanks again for mentioning!
@Iamnoone56
@Iamnoone56 4 года назад
Please make videos on graph and please add more questions on trees 😭😭
@LucidProgramming
@LucidProgramming 4 года назад
You can feel free to make suggestions on my Patreon page. This would streamline what you want to see and also help to support my channel. www.patreon.com/lucidprogramming
@bronik7
@bronik7 2 года назад
(17:57) Why in preorder_print (line 4) you passing tree.root? why not self.root? to me it's not clear how Class knows about it's instance? Can you please explain? Thank you
@gokusaiyan1128
@gokusaiyan1128 2 года назад
What are your vim settings/plugins? I like it
@LucidProgramming
@LucidProgramming 2 года назад
Good question! Much of my configuration is covered here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-vlb3qUiS2ZY.html
@prakhargurha1427
@prakhargurha1427 4 года назад
Why is it necessary to define class Node(object) and not class Node() simply as we did in linked list.What's the significance of object
@LucidProgramming
@LucidProgramming 4 года назад
They are equivalent. The former is how things were done in Python 2.7, and the latter is more modern.
@alessiopellegrini523
@alessiopellegrini523 3 месяца назад
Shouldn't it be self.preorder_print(self.root, " ") in the helper function of the BinaryTree? There is no tree variable in the class and the only way the code is still running correctly is because "tree" happens to be defined outside of class, no?
@jingfenghong2312
@jingfenghong2312 4 года назад
These are awesome videos I have ever seen. I have a question, why don't you use self.root in print_tree() function, but use tree.root?
@LucidProgramming
@LucidProgramming 4 года назад
Thanks! And either convention is fine there. Using self.root would work just as well. Cheers!
@jingfenghong2312
@jingfenghong2312 4 года назад
@@LucidProgramming Thank you a lot, these videos would definitely help me in my future career interview! I will recommend it to other friends.
@LucidProgramming
@LucidProgramming 4 года назад
@@jingfenghong2312 Thank you, I sincerely appreciate that!
@armans4306
@armans4306 7 месяцев назад
thanks good tutorial; tho you have a bug which is python's fault to be honest. It has allowed you to do this: return self.preorder_print(tree.root, "") ; it had to be self.root
@kl-je3up
@kl-je3up 2 года назад
explains it way better than my ds&a textbook lol
@LucidProgramming
@LucidProgramming 2 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@enkaibi2756
@enkaibi2756 5 лет назад
Too excited to sleep now! I finally understand it! Best video on Traversal Algorithms explanation! Consider watching all your python video!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@enkaibi2756
@enkaibi2756 5 лет назад
@@LucidProgramming Just a tiny recommendation, on 17:06, it would be better to use self.root instead of tree .root. Keep going! !!
@LucidProgramming
@LucidProgramming 5 лет назад
@@enkaibi2756 Point well taken. Thanks for the comment! :)
@bhuwansharmaa
@bhuwansharmaa 4 года назад
Best Explanation recursion is bit confusing but following each step through example made it easy... Thanks
@LucidProgramming
@LucidProgramming 4 года назад
Awesome, that's great to hear. Thanks for watching!
@MrAgj200
@MrAgj200 2 года назад
you say to look at your series of linked lists videos, but then dont link them. and if you do find the linked lists playlist, the first video in the series says its a continuation, so which is the first video, but who know what that is????
@Rei-m3g
@Rei-m3g 4 года назад
I don't know python but still I understand ..... Weird 😛
@LucidProgramming
@LucidProgramming 4 года назад
Well, I'm glad you got something from the video :). Hopefully, these videos serve to continue to help you understand these concepts!
@yashpandey350
@yashpandey350 4 года назад
Sir in each order_print functions how node gets back to head position when its left child or right child becomes None.
@LucidProgramming
@LucidProgramming 4 года назад
Through the recursive call of the function (if I understand the question correctly).
@ajrvasu
@ajrvasu 4 года назад
@@LucidProgramming Thanks for the great set of videos. My go to playlists. On this one - a bit confused as to how the recursion is getting back to the right child. In the example, after reaching 4, the left child is none. So the recursive function should not enter the loop at all, so how is reading the right child (5)? I get the code intuitively, but am stuck when trying to create the stack line by line to understand the recursion well.
@LucidProgramming
@LucidProgramming 4 года назад
@@ajrvasu I think what might be insightful is to print out the elements as you make the recursive calls. That might make it a bit clearer as to what is happening. Hope that helps!
@ajrvasu
@ajrvasu 4 года назад
@@LucidProgramming Thanks for the suggestion.
@LucidProgramming
@LucidProgramming 4 года назад
@@ajrvasu No problem, cheers!
@rhythmsaparia8788
@rhythmsaparia8788 5 лет назад
I have a doubt, after a while adding nodes by writing tree.root.left.right.left bla bla becomes a cumbersome process, if you could suggest a better and easier way to add nodes than it would be a great help, thanks.
@software-sage
@software-sage 5 лет назад
There must always be a way!
@zewdiherring9528
@zewdiherring9528 2 года назад
Thanks! Helpful :D
@LucidProgramming
@LucidProgramming 2 года назад
Thank you for watching, and glad to hear that it was helpful!
@neildutoit5177
@neildutoit5177 2 года назад
Your diagram makes it appear as though full trees can only have leaf nodes with 0 children which is confusing
@LucidProgramming
@LucidProgramming 2 года назад
All great points! Thank you, Neil!
@neildutoit5177
@neildutoit5177 2 года назад
checking for None using a bool cast is also an anti-pattern. Use "if start is not None" instead.
@karinah6762
@karinah6762 4 года назад
Hi, why when you define the node class or binary class it inherits from object class?
@LucidProgramming
@LucidProgramming 4 года назад
This is the way in which you define a class in Python.
@natnaelberhane3141
@natnaelberhane3141 2 года назад
If I'm not mistaken, depth of root node is 0. Root node is at level 0, not 1 :)
@reccartoon
@reccartoon 6 лет назад
i really love the way you are explaining all these concepts in very effective manner thanks for this :)
@LucidProgramming
@LucidProgramming 6 лет назад
Hi Sarfaraz. Really appreciate that comment, that's very much appreciated! Thank you for watching, and I'm happy to hear this video was effective. Cheers!
@conquerworld_in
@conquerworld_in 4 года назад
Hello sir, I am not able to understand that how everything is happening here as in if how are we writing start.value with inheritance and those things!
@LucidProgramming
@LucidProgramming 4 года назад
You might want to look into Python classes to clarify this.
@conquerworld_in
@conquerworld_in 4 года назад
@@LucidProgramming I saw that but then also I wasn't able to understand
@LucidProgramming
@LucidProgramming 4 года назад
@@conquerworld_in You might need to be more specific. I offer tutoring services if you feel like you're stuck on a subject.
@FahmiEshaq
@FahmiEshaq 9 месяцев назад
Perfect
@kionlingg
@kionlingg 4 года назад
For the output on 19:38 I received an output "Traversal type preorder is not supported." Is that the correct output? Am I missing something?
@LucidProgramming
@LucidProgramming 4 года назад
You should check your code against mine on GitHub.
@felipepardosuarez2364
@felipepardosuarez2364 5 лет назад
Great video. Thank you!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@redpred3502
@redpred3502 3 года назад
For the functions being returned in the print_tree method, what difference would it make if self.root was used as arguments instead of tree.root? Doesn't tree.root limit the class to just that object?
@LucidProgramming
@LucidProgramming 3 года назад
Have you tried doing that?
@redpred3502
@redpred3502 3 года назад
@@LucidProgramming I did and now it works with different named trees.
@LucidProgramming
@LucidProgramming 3 года назад
@@redpred3502 Right, because "self" and "tree" both refer to an instance of the Tree class.
@ZhuYiting612
@ZhuYiting612 3 года назад
@@LucidProgramming and by using "self.root" can make the function works for an instance with any name other than the name "tree", right? thanks
@LucidProgramming
@LucidProgramming 3 года назад
@@ZhuYiting612 So long as you're referring to the object created in the class.
@ayushisingh6638
@ayushisingh6638 4 года назад
I didn't get that in Inorder traversal like how from node A it's Going back to Node B?
@LucidProgramming
@LucidProgramming 4 года назад
You might want to check out my playlist on recursion if this part is confusing to you.
@wyllerdesousa1710
@wyllerdesousa1710 Год назад
Nice introduction! Thanks to support the TI community.
@LucidProgramming
@LucidProgramming Год назад
Cheers!
@ahmedsarker3555
@ahmedsarker3555 3 года назад
how can I understand programming please help i am on the verge of failing i still do not understand why do you use def_init_self
@gunabalang7034
@gunabalang7034 4 года назад
crystal clear
@LucidProgramming
@LucidProgramming 4 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@khavishbhundoo3792
@khavishbhundoo3792 6 лет назад
DFS is often used to solve common graph problems such as Connected cells.I am having trouble mapping the knowledge from trees to graph.What is root,left , right when you do a DFS on a grid.Have a look @ ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-R4Nh-EgWjyQ.html . What type of dfs is used in that tutorial.Thanks a lot for taking the time to clear my doubts
@LucidProgramming
@LucidProgramming 6 лет назад
Hi Khavish. That's a good question, and one I hope to clarify a bit when I cover the graph data structure on this channel. For one, the left and right children of a node make sense in the context of a binary tree, as you only have at most two children for any node, which is implied by the name binary in this case. However, in a graph, a node may have any number of direct child nodes. The DFS idea is still applicable to a graph, only now, you must tweak a few things. One of them is, as you observed, the fact that a node may have more than two children must be accounted for. The changes are minor, and if you understand DFS for how it is applied to a tree, it should be a relatively straightforward switch to graphs. Hope that helps. Looking forward to making videos on this in the future. Thanks for your comment!
@-sallybae5692
@-sallybae5692 4 года назад
thankssssssss
@LucidProgramming
@LucidProgramming 4 года назад
No problem, hope it was helpful!
@rangasridharg2902
@rangasridharg2902 2 года назад
what does tree.root.left represent?
@KashMan523
@KashMan523 5 лет назад
Is "class Node(object):" same as "class Node:"?
@LucidProgramming
@LucidProgramming 5 лет назад
Yes.
@HanisaMohamed
@HanisaMohamed 4 года назад
Thank you! Explained it very well.
@LucidProgramming
@LucidProgramming 4 года назад
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@vinayakaraju2774
@vinayakaraju2774 5 лет назад
which language is the best to learn data structures and algorithms?
@LucidProgramming
@LucidProgramming 5 лет назад
There is no answer to this question. Data structures and algorithms are concepts and topics that are abstracted from any specific language. You can use whatever language you like.
@zarioiubogdan1164
@zarioiubogdan1164 4 года назад
Hi there! Thank you so much for this! I just discovered your videos and they are so helpful! I was struggling a lot to understand how I could implement and traverse a binary tree. There are countless videos about this but yours really made me understand and gave me hope that with time and practice I could learn these concepts. I saw you have videos on many data structures and I plan to go through all of them and try to understand. Could you please also cover graph implementation and traversal in Python? Thank you again for your help! Wish you the best!
@LucidProgramming
@LucidProgramming 4 года назад
You can feel free to make suggestions on my Patreon page. This would streamline what you want to see and also help to support my channel. www.patreon.com/lucidprogramming
@hassanfarah3501
@hassanfarah3501 5 лет назад
God bless you Sir. I have been following your tutorials for a while and you are a LEGEND
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link www.paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@benderbendingrofriguez3300
@benderbendingrofriguez3300 4 года назад
so by coding a Binary tree helps understand the logic of programming?
@LucidProgramming
@LucidProgramming 4 года назад
Is Bender asking what the use of a binary tree is!? It's more than just a tool to understand, binary trees are one of the most widely used data structures. They have millions of uses, something a RU-vid comment cannot do justice. I suggest you Google it!
@gwaka2131
@gwaka2131 2 года назад
how can postorder traversal result be "4-2-5-6-3-7-1-" when it is supposed to be "4-5-2-6-7-3-1-"?
@LucidProgramming
@LucidProgramming 2 года назад
The top comment I pinned here addresses this. My mistake!
@gwaka2131
@gwaka2131 2 года назад
@@LucidProgramming Thank you
@asiacaster3663
@asiacaster3663 4 года назад
I thought a BNT's nodes left child was smaller than the right child..so the 7 should be on right side and 5 should be on left side
@LucidProgramming
@LucidProgramming 4 года назад
No. You're describing a BST, not a BT.
@Rich65501
@Rich65501 5 лет назад
Beautiful presentation.
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@raheemwilliams7998
@raheemwilliams7998 4 года назад
how are you able to access attributes from another class without creating an object for it or even using inheritance? plz explain
@LucidProgramming
@LucidProgramming 4 года назад
I think you might need to look into object oriented design on your own. I'm not going to give you a lecture on OOP principles in a RU-vid comment.
@simranray6281
@simranray6281 3 года назад
I wanted to know why the parameters passed for these order traversals are tree.root, shouldn’t it be self.root? Because inside the class there’s no tree defined.
@ZhuYiting612
@ZhuYiting612 3 года назад
I believe it's a better practice to use "self.root" instead of "tree.root". Appreciate if @Vincent can confirm.
@LucidProgramming
@LucidProgramming 3 года назад
​@@ZhuYiting612 Yep, confirming that "self.root" is definitely clearer and preferable.
@simranray6281
@simranray6281 3 года назад
@@ZhuYiting612 thank you
@simranray6281
@simranray6281 3 года назад
@@LucidProgramming thank you
@LucidProgramming
@LucidProgramming 3 года назад
@@simranray6281 Cheers!
@nx8221
@nx8221 5 лет назад
Dude thank you for this!
@LucidProgramming
@LucidProgramming 5 лет назад
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my RU-vid page. bit.ly/lp_email
@debashishchakraborty7924
@debashishchakraborty7924 4 года назад
Where is your Patreon , we will donate to grow your channel. please make videos on BFS DFS, HEAPS, HASHMAPS AND TRIE
@arkster00
@arkster00 6 лет назад
In the postorder_print function, I think you are calling the inorder_print function for the left and right nodes erroneously (copy/paste error).
@LucidProgramming
@LucidProgramming 6 лет назад
Yep, you are indeed correct. Looks like I too hastily copied and pasted from the previous traversal. I'll make sure to update my code on Github to reflect the correct traversal algorithm. Nice catch, and thanks for watching!
@arkster00
@arkster00 6 лет назад
Not a problem. Thank you for posting. All of this is pretty helpful and makes things more clear for the rest of us.
@LucidProgramming
@LucidProgramming 6 лет назад
Any time Ahmer, happy to hear that these videos are helpful to others. Cheers and have a nice day!
@theguildedcage
@theguildedcage 6 лет назад
Hello, I looked for traversals on your Github. Couldnt find it. Could you post a link or code correction? Thanks for taking the time to share you knowledge with the masses!
@chirayujain5539
@chirayujain5539 6 лет назад
Instead of calling tree.root in print_tree function can we call self.root?...Nice video!!!
@LucidProgramming
@LucidProgramming 6 лет назад
Hi Chirayu. I'm not sure what you mean when you say "instead of calling". We're not calling tree.root in print_tree, so the question doesn't make sense to me. You can only use self.root in the class, if you try to use self.root where we use tree.root, you'll get an error since this is not inside of the tree class. Hope that makes sense, and thanks for your comment. Cheers!
@chirayujain5539
@chirayujain5539 6 лет назад
LucidProgramming I meant that we are creating an object of class Binarytree as tree and then at printree function we are using tree.root .. if we write self.root it is giving the same results..
@LucidProgramming
@LucidProgramming 6 лет назад
Oh, of course, I see what you're asking now. Sorry, I must have got some wires crossed or not completely understood what you were initially asking. Yes, in fact replacing "tree.root" in the "print_tree" function with "self.root" is perfectly acceptable. Sorry for the confusion, and thanks for the clarification.
@Dev-dk3ez
@Dev-dk3ez 5 лет назад
@@LucidProgramming Calling tree.root inside print_tree is not right. If you don't instantiate BST then you will see unresolved reference error.
@LucidProgramming
@LucidProgramming 5 лет назад
@@Dev-dk3ez Hi Dev. You're absolutely right. Without the proper context the unresolved error will occur and problems will be caused. Thanks for pointing that out!
@theguildedcage
@theguildedcage 6 лет назад
Awesome tutorial! Thanks.
@LucidProgramming
@LucidProgramming 6 лет назад
Thank you, Philip! I'm glad you found the tutorial useful! Cheers, and thanks again for watching.
@sarvarjuraev1376
@sarvarjuraev1376 3 месяца назад
Thank you very much
Далее
Binary Trees in Python: Level-order Traversal
15:50
Просмотров 35 тыс.
Обменялись песнями с POLI
00:18
Просмотров 333 тыс.
Binary Search Tree in Python
22:59
Просмотров 51 тыс.
Binary Trees in Python: Calculating Height of Tree
15:37