Binary Search Trees in Python: Introduction - Insertion and Search

  Рет қаралды 45,600

LucidProgramming

LucidProgramming

Күн бұрын

Пікірлер: 164
@raisamaria6538
@raisamaria6538 5 жыл бұрын
I'm not the last or the first to say that you're a great teacher. Thanks
@LucidProgramming
@LucidProgramming 5 жыл бұрын
I really appreciate that, Raisa. That means a lot! 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 KZbin page. bit.ly/lp_email
@rumanaislam4758
@rumanaislam4758 11 ай бұрын
Your explanation was really amazing, you should come back make more of this awesome videos. I was confused all day about how to define the bst functions and magically youtube suggested your channel.
@LucidProgramming
@LucidProgramming 11 ай бұрын
That's wonderful to hear. I would love to make a comeback, but time as of now is the limiting factor. Thank you in any case for the kind words!
@rumanaislam4758
@rumanaislam4758 11 ай бұрын
@LucidProgramming Please do, teachers like you are very rare these days!
@ahmedkidwai-
@ahmedkidwai- 4 жыл бұрын
Hi! I've taken data structure classes before (in java) and needed a refresher for Trees and in python. Your video series has been fantastic. Theory has been excellent and the code has been clean. Most tutorials I've seen have grouped the Node and BST classes together and I really didn't like that. I'm glad you split them up! Thank you for your amazing contributions.
@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 жыл бұрын
My takeaway on BST based on your awesome explanation: 1.BST is very good for searching , deletion and insertion provided the tree is balanced(log n).The selection of the root node will determine how balanced the tree will be.AVL or Splay tree will ensure the tree remain balanced. 2.If tree isn't balanced we essentially have a long list , making the time complexity O(n) 3.I noticed that if you apply Inorder traversal to a BST you get the nodes in ascending order.So if we want to sort with a tree it will O(nlogn) because building the tree is O(n)
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Khavish. That's an excellent summary of the video. I hope to find the time to cover AVL and Splay trees in upcoming videos :). Thanks for noting those key points, and of course, thank you again for watching and commenting as well. Cheers! :)
@khavishbhundoo3792
@khavishbhundoo3792 6 жыл бұрын
In this video BST is ordered in a way where left child < root < right child but i suppose that just a variant of BST. A variant where right child < root < left child could exist , an inverse of the ordering in other words
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Khavish. Absolutely. As long as the ordering that you impose on the tree is consistent, the overarching structure of a BST should be applicable to that. I'm struggling to think of any specific case in which this ordering would be beneficial to a problem, but perhaps I just haven't thought about it enough. Thanks again for your comment!
@khavishbhundoo3792
@khavishbhundoo3792 6 жыл бұрын
Same here ...although i did found a question on leetcode.com/problems/invert-binary-tree/description/
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Ah, I see. Yes, once you have a regularly sorted binary search tree and want to invert that's a bit trickier than just constructing an inverse binary search tree from scratch. That Twitter quote is interesting. I recall hearing about that scenario where Google decided to not hire a candidate based on their inability to invert a BST, despite the fact that he had written software that was so widely used by the company. Thanks again for sharing the link!
@milkiasyeheyis5407
@milkiasyeheyis5407 4 жыл бұрын
I can't believe this channel has only 30k subs. Really amazing content. Thank you for this.
@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!
@rohanchakraborty4284
@rohanchakraborty4284 6 жыл бұрын
The way u teach in the video is truly impeccable..For me, ur videos are one of the best..,The concepts get clear..
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Thank you kindly, Rohan that's very flattering. I appreciate your feedback, and thanks again for your comment! Cheers :)
@annidamf
@annidamf 5 жыл бұрын
OMMMGGGG MY REAL MVP❤️❤️❤️❤️❤️❤️ THANKS A LOT SIR PLS KEEP MAKING VIDEOS LIKE THESE THEY HELP ME LEARN AND SURVIVE IN COLLEGE😭😭😭😭😭😭😭❤️❤️❤️❤️❤️ MUCH LOVE
@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 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 KZbin page. bit.ly/lp_email
@shrikantpande9474
@shrikantpande9474 4 жыл бұрын
Thanks man.. you have no idea how much your videos have helped me.
@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. I hope to be putting out more similar videos soon!
@muggie_guava
@muggie_guava 2 жыл бұрын
Oh my god I finally understood how to implement the bst in python, thanks alot! Great video!
@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!
@dhashdev
@dhashdev 3 жыл бұрын
Your explanation is amazing! Especially for the part which requires a lot of focus, I was able to understand in one go. Thank you, Please keep making content like this.
@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!
@rahls7
@rahls7 5 жыл бұрын
This awesome playlist deserves a video on remove method for BST and finally avl trees and heaps :D
@LucidProgramming
@LucidProgramming 5 жыл бұрын
Thank you, Rahul! 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 KZbin page. bit.ly/lp_email I hope to continue covering others topics like AVL trees and heaps in future videos!
@neurochannels
@neurochannels 5 жыл бұрын
Remove method would be nice that is a lot harder than add!
@NikhilParekh7
@NikhilParekh7 4 жыл бұрын
It would be really helpful if you can continue this series.
@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!
@harshavardhanachary3863
@harshavardhanachary3863 4 жыл бұрын
you taught the code in an easy manner....I like it.......thank you so much sir.
@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!
@peregudovoleg
@peregudovoleg 4 жыл бұрын
I was stuck with trees at some other course, but your code and explanations are very intuitive and make a lot of sense. Subscribed and thanks!
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Cool, thanks for the support! I sincerely appreciate it!
@marinboras5001
@marinboras5001 4 жыл бұрын
Thanks a lot for making these videos. Python will be even easier to learn with such a great teacher!
@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!
@marinboras5001
@marinboras5001 3 жыл бұрын
Already did that, keep up the great work! CS students are very lucky to have you!
@LucidProgramming
@LucidProgramming 3 жыл бұрын
@@marinboras5001 Cheers, I really appreciate the kind words!
@mrinmayigavali2049
@mrinmayigavali2049 5 жыл бұрын
I am so glad I found your videos. I watched all the videos in the Data Structures playlist of yours. I referred many books and videos but none of them have such a clear explanation of concepts as yours. Could you please make videos on Graphs as well? :)
@LucidProgramming
@LucidProgramming 5 жыл бұрын
That's really fantastic to hear, thank you so much! Graphs are most definitely on my shortlist. Thanks again for your comment and suggestion!
@gokusaiyan1128
@gokusaiyan1128 2 жыл бұрын
@@LucidProgramming Graphs please !!!
@bijayamanandhar3890
@bijayamanandhar3890 2 жыл бұрын
Thank you for such a nice and clear presentation,
@LucidProgramming
@LucidProgramming 2 жыл бұрын
Of course, thank you for watching!
@JoseHernandez-ed5lz
@JoseHernandez-ed5lz 4 жыл бұрын
Incredible! Absolutely incredible! Thank you so much for your content! This is golden content!
@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!
@kruthikhm6379
@kruthikhm6379 4 жыл бұрын
You are a different and great teacher
@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!
@George-1297
@George-1297 26 күн бұрын
More than amazing explanation
@misatran1107
@misatran1107 3 ай бұрын
Thank you very much. Very clear lecture and explaination
@davidrowlands8548
@davidrowlands8548 2 жыл бұрын
Yet another excellent video. Thank you
@carolynbose6802
@carolynbose6802 4 жыл бұрын
thank you soo much Sir. All your videos have helped me a lot.
@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 KZbin page. bit.ly/lp_email
@Yogi-hz2rd
@Yogi-hz2rd 3 жыл бұрын
Very useful and informative Thanks alot!!!!
@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!
@namanvohra8262
@namanvohra8262 2 жыл бұрын
You just got a new subscriber
@LucidProgramming
@LucidProgramming 2 жыл бұрын
Much appreciated, thank you!
@rohanchakraborty4284
@rohanchakraborty4284 6 жыл бұрын
Please make a video on hashing and hash table stuffs...
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Rohan. That is most definitely on my "to-do list". I will hopefully get to hash tables sooner rather than later. Thanks for the suggestions! :)
@albertulysses
@albertulysses 4 жыл бұрын
Any update on hash tables?
@iashishhere
@iashishhere 4 жыл бұрын
@@LucidProgramming Any update sir?
@LucidProgramming
@LucidProgramming 4 жыл бұрын
@@iashishhere 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
@Mickeyfsc2601
@Mickeyfsc2601 3 жыл бұрын
thanks so much your videos are really awesome and helpful
@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!
@piratevv
@piratevv 4 жыл бұрын
excellent teaching vincent!!
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Thank you, very much appreciated!
@IshuGoelIshIshIsh9203
@IshuGoelIshIshIsh9203 4 жыл бұрын
This is one of the best explained videos on Trees! Good job and thanks for the lucid explanation :) If I were to print the tree output as an image, how could I do that?
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Thanks! As per your question, there are a number of ways you could do that. It really depends on how you want to display the tree!
@balamurugans363
@balamurugans363 3 жыл бұрын
You are the best Boss ,Thanks
@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!
@kamaboko1
@kamaboko1 5 жыл бұрын
Exceptional tutorial.
@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 KZbin page. bit.ly/lp_email
@siddhantbhardwaj4268
@siddhantbhardwaj4268 3 жыл бұрын
Can you do a video on AVL Trees, Red-Black Trees and N-Ary Trees ? Your lectures are golden.
@LucidProgramming
@LucidProgramming 3 жыл бұрын
Thanks! My time has been pretty sparse lately, but those are on my list. Cheers!
@estudosapenas7717
@estudosapenas7717 2 жыл бұрын
a function calling itself inside its own structure is still something that my brain can not comprehend
@LucidProgramming
@LucidProgramming 2 жыл бұрын
It is indeed a bit mind-boggling at first. I do have a playlist on recursion that you might want to check out to fill in some of those gaps. Cheers! kzbin.info/www/bejne/mp2meJZvZ9l0p9E
@leohangrai7298
@leohangrai7298 4 жыл бұрын
Thank you so much! This is really brilliant and helpful. :')
@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!
@Mohit-nn9bt
@Mohit-nn9bt 5 жыл бұрын
Sir,it would be really helpful if u can go for advance topics like graph,avl tree,red-black tree,hash tables and more questions on tree
@LucidProgramming
@LucidProgramming 5 жыл бұрын
Those are on my to-do list. Stay tuned!
@Mohit-nn9bt
@Mohit-nn9bt 5 жыл бұрын
@@LucidProgramming Sir People are asking for advance data structures tutorial from months.please try to update asap.Thanks
@LucidProgramming
@LucidProgramming 5 жыл бұрын
@@Mohit-nn9bt I understand. My recording setup was compromised due to a fire that occurred. I'm still trying to get back up and running. I appreciate your understanding and patience.
@jasoncole3253
@jasoncole3253 5 жыл бұрын
@MOHIT KUMAR You can make a donation of 10$ to suggest for a video, he will definitely appreciate it www.patreon.com/join/lucidprogramming
@KKinHD10
@KKinHD10 4 жыл бұрын
Adding (' / ') or (' \ ') in the _find function would print path like structure with the direction of slash representing left child or right child : ) Pretty good to visualize the path to the node you searched for. if data < cur_node.data and cur_node.left: print(str(cur_node.data)) print(' / ') return self._find(data,cur_node.left) elif data > cur_node.data and cur_node.right: print(str(cur_node.data)) print(' \ ') return self._find(data,cur_node.right) ###### EXAMPLE OUTPUT ##### > bt.find(200) 1 \ 100 \ 250 / True
@mastermind5421
@mastermind5421 4 жыл бұрын
god tier tutorial
@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!
@debashishchakraborty7924
@debashishchakraborty7924 5 жыл бұрын
Just WOW.!... Please post videos on graphs. :)
@LucidProgramming
@LucidProgramming 5 жыл бұрын
It's on my to-do list! :)
@prakashranjanpatra3539
@prakashranjanpatra3539 4 жыл бұрын
Thank you very much... 😊👍👍
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Cheers, and thanks for watching!
@JollyAZ
@JollyAZ 4 жыл бұрын
Great video 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!
@weichengzhu6605
@weichengzhu6605 6 жыл бұрын
Hi Lucid, Thank you for your very nice tutorials! And for the slides of this series, could you share? Thanks
@LucidProgramming
@LucidProgramming 6 жыл бұрын
I've updated the description with a link to the slides. Thanks for the suggestion, and thanks for your kind comment! Cheers!
@anirvansen2941
@anirvansen2941 4 жыл бұрын
Awesome as always :)
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Thanks! :)
@khavishbhundoo3792
@khavishbhundoo3792 6 жыл бұрын
Just a quick update , i have coded BST operations iteratively including deletion + tree traversals @ repl.it/repls/InterestingHumiliatingWordprocessing . @LucidProgramming Let me know what you think and any potential bug / optimization that i may have missed. Regards
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Khavish. I don't currently have the bandwidth to look at the code, but I'm happy to hear you've got it working. I recommend you look at how to test your code and run it on a number of edge cases to give you more confidence that your code is correct. Cheers.
@mateuszsmendowski2677
@mateuszsmendowski2677 5 жыл бұрын
Can I have a question? Is there any vital difference between: 1. class Node(object): 2. class Node:
@LucidProgramming
@LucidProgramming 5 жыл бұрын
No, they are equivalent.
@aditya4974
@aditya4974 4 жыл бұрын
Thanks again! Could you please cover AVL trees in your upcoming videos?
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Thanks! No plans at the moment, but I would like to if I have the time!
@sutingyang9439
@sutingyang9439 5 жыл бұрын
Could you please make some video on Machine Learning?
@LucidProgramming
@LucidProgramming 5 жыл бұрын
Absolutely, I actually have a series on machine learning that you can find here: bit.ly/lp_mlearn Cheers!
@jagdishwarbiradar1763
@jagdishwarbiradar1763 5 жыл бұрын
way you teaches is auesome , can you make any recursion video that covers the all concept of recursion , be-cause that confuses me a lots of time .
@LucidProgramming
@LucidProgramming 5 жыл бұрын
I've got you covered. I have a playlist on recursion you might find useful here: bitly.com/lp_recursion Cheers!
@anshumangupta2842
@anshumangupta2842 4 жыл бұрын
Please make a series on graph
@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!
@heidik1757
@heidik1757 4 жыл бұрын
Hello again :) Just wondering... to learn all of these algorithms frontwards, backwards and sideways. How long do you think it should take? (All of these data structures shown in all 40 videos). Really curious, thank you!
@LucidProgramming
@LucidProgramming 3 жыл бұрын
It really depends on your goals and scope. If you plan on using this information to say, pursue a PhD in data structures, my answer is going to be different than say, getting enough information to perform well at a technical interview. I offer tutoring and consulting, so if you have a specific goal in mind, you can reach out to the email in the "about" section to schedule in some time to set something up. Hope that makes sense. Cheers!
@heidik1757
@heidik1757 3 жыл бұрын
thanks for the info! and I was wondering more for a more PhD level of understanding of data structures.
@LucidProgramming
@LucidProgramming 3 жыл бұрын
@@heidik1757 Gotcha. In that case, I would check out the CLRS textbook along with the "red" "Algorithm Design Manual". Those are two great books I would recommend, mostly as a reference, but also to read through. There are great companion courses for each of those books as well that you can find on KZbin. Hope that provides a reasonable start for ya, and don't hesitate to keep asking questions!
@amalmathew2030
@amalmathew2030 4 жыл бұрын
thanks
@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!
@prasanjithpatel9490
@prasanjithpatel9490 4 жыл бұрын
great code !!!!
@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 жыл бұрын
What about duplicates in a BST ? Ofcourse we could just add an instance variable count in the node and be done with it.
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Khavish. From most of the definitions I've found, a BST typically will not allow the storing of duplicates. Your solution is probably one valid one, where if you want to insert a node with a data value that is already present, an auxiliary property of each node could be a count parameter that would increase if a duplicate value is inserted. Great point, Khavish. I really appreciate your commentary!
@rishikeshpuri6101
@rishikeshpuri6101 4 жыл бұрын
Sir, pls make video on graph algorithm, dynamic programming, greedy algorithm
@LucidProgramming
@LucidProgramming 4 жыл бұрын
It's on my to-do list!
@teutasalihu9364
@teutasalihu9364 3 жыл бұрын
How would you revise the find method to instead of returning T/F it returns the number of nodes that are examined
@LucidProgramming
@LucidProgramming 3 жыл бұрын
Have you tried doing this on your own?
@teutasalihu9364
@teutasalihu9364 3 жыл бұрын
@@LucidProgramming hi! yes, I’ve added a counter after every search to count the nodes but I don’t think I’m doing it correctly. Just wanted more insight on it :)
@gokusaiyan1128
@gokusaiyan1128 2 жыл бұрын
I didn't wanted to use helper function so I did it this way. Though I am not sure if my code is pythonic or not. I still think in terms of C++ but below is my code. have a look class Node: def __init__(self, data=None): self.data = data self.left = None self.right = None class BinarySearchTree: def __init__(self): self.root = None def insert(self, root, data): if root is None: root = Node(data) elif data < root.data: root.left = self.insert(root.left, data) elif data > root.data: root.right = self.insert(root.right, data) else: print("value already present in the tree") return root def search(self, root, data): if root is None: return False elif root.data == data: return True elif data < root.data: return self.search(root.left, data) elif data > root.data: return self.search(root.right, data) def inorder(self, iter): """left->data->right""" if iter: self.inorder(iter.left) print(iter.data) self.inorder(iter.right) bst = BinarySearchTree() bst.root = bst.insert(bst.root, 10) bst.root = bst.insert(bst.root, 5) bst.root = bst.insert(bst.root, 20) bst.root = bst.insert(bst.root, 2) bst.root = bst.insert(bst.root, 2) bst.inorder(bst.root) print("1 in Tree : ", bst.search(bst.root, 1)) print("2 in Tree : ", bst.search(bst.root, 2))
@LucidProgramming
@LucidProgramming 2 жыл бұрын
Nice. Thanks for sharing!
@Samin7575
@Samin7575 4 жыл бұрын
that saved me....
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Glad to hear it! If you benefited, please drop a like and subscribe. Cheers!
@vishnurj6207
@vishnurj6207 3 жыл бұрын
Please come back to youtube. And next time while making videos, please use the call stack to move through a recursive call function
@LucidProgramming
@LucidProgramming 3 жыл бұрын
When I get more time, I'll come back!
@davidrosen2705
@davidrosen2705 3 жыл бұрын
hey great video, can you or anybody who knews explain at 17:25 when you cur_node.left = Node(data), i understnd that you want to assiagn value to the left node but why not cur_node.left = data, and why when i try to print(cur_node.left) after assignment it gives back thank you.
@LucidProgramming
@LucidProgramming 3 жыл бұрын
Because you need to print out the data at the left node: cur_node.left.data
@theguildedcage
@theguildedcage 6 жыл бұрын
Noob question: Is 'object' passed in by default when creating these classes or is it omitted?
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Philip. I'm not sure I know what you mean. What do you mean when you say "object" in this case?
@theguildedcage
@theguildedcage 6 жыл бұрын
LucidProgramming for example, what is the difference between these two classes. class Node(object): class Node:
@LucidProgramming
@LucidProgramming 6 жыл бұрын
@@theguildedcage Ah okay, that question is clearer to me. In Python 3, it makes no difference. Python 2 has a bit more a nuanced answer, but for 3, it doesn't make a difference. StackOverflow has some good information on this if you Google for it. Hope that helps. Cheers!
@enkaibi2756
@enkaibi2756 5 жыл бұрын
Awesome video! A question on 22:14, why do you have to use Return instead of not using it. What is the difference? Without it, no syntax error, I just got a wrong result. It's killing me!
@LucidProgramming
@LucidProgramming 5 жыл бұрын
If you do not specify any return the default return is the "None" type. Hope that helps, and thanks again for watching!
@enkaibi2756
@enkaibi2756 5 жыл бұрын
@@LucidProgramming Yeah! Gotta you! So glad that you replied! Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@LucidProgramming
@LucidProgramming 5 жыл бұрын
@@enkaibi2756 No problem!
@evanzhao3887
@evanzhao3887 4 жыл бұрын
@@LucidProgramming if data > cur_node.value and cur_node.right: return self._find(data, cur_node.right) elif data < cur_node.value and cur_node.left: return self._find(data, cur_node.left) elif data == cur_node.value: return True else: return False I think if you change it into this way, that part will become a lot more easier to understand!
@LucidProgramming
@LucidProgramming 4 жыл бұрын
@@evanzhao3887 Cool, thanks for the suggestion!
@dhananjaywadhavane4106
@dhananjaywadhavane4106 4 жыл бұрын
what if two values are same in array for binary search tree?
@LucidProgramming
@LucidProgramming 4 жыл бұрын
That violates the definition of a binary search tree.
@Sagar_RS
@Sagar_RS 6 жыл бұрын
Hey I follow your videos for daily practicing , you are doing a great job. can you do other Data structures too in python ?. Thanks.
@LucidProgramming
@LucidProgramming 6 жыл бұрын
Hi Sagar. That's outstanding, I'm thrilled to hear that. Indeed, doing other data structure videos is on my list. I do intend to focus on that soon, and thanks again for your suggestion! Cheers, and thanks for watching.
@junaidiqbal2321
@junaidiqbal2321 3 жыл бұрын
Sir what is self variable
@LucidProgramming
@LucidProgramming 3 жыл бұрын
I'm not going to be able to answer that in a KZbin comment. You should use Google.
@rukiliyanage8464
@rukiliyanage8464 4 жыл бұрын
I was wondering if you can just do this: def insert(self, value) : if self.isEmpty() : self._root = self._Node(value) return parent = None probe = self._root while (probe != None) : if value
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Have you tried this? The two insert functions are there because one is just a helper function.
@rukiliyanage8464
@rukiliyanage8464 4 жыл бұрын
@@LucidProgramming yes i was wondering if using a helper function was more efficient than doing it all under one function?
@rukiliyanage8464
@rukiliyanage8464 4 жыл бұрын
I was also wondering if you can just insert a whole list instead of just one integer at a time?
@LucidProgramming
@LucidProgramming 4 жыл бұрын
@@rukiliyanage8464 Efficiency has nothing to do with it, it's only for clarity.
@jaideepmore1299
@jaideepmore1299 5 жыл бұрын
def insertTree(self, item): if self.root is None: self.root = Node(item) else: self.insertHelper(self.root, item) def insertHelper(self, start, item): if start.data is None: start.data = Node(item) else: if start.data > item: self.insertHelper(start.data.left, item) else: self.insertHelper(start.data.right, item) getting error : TypeError: '>' not supported between instances of 'Node' and 'int' But, as i am using start.data then it shouldn't be giving this error. start is a Node object please help..
@LucidProgramming
@LucidProgramming 5 жыл бұрын
I would suggest you copy my code on the Github page. It's hard to diagnose as I don't see the rest of the code to know the type of what you're passing around here.
@jaideepmore1299
@jaideepmore1299 5 жыл бұрын
Umm is there any way in which I could share my code to you and you can take a look I ma curious to know what's wrong in my code. I can share my GitHub link if possible, Thanks for the reply .😀
@LucidProgramming
@LucidProgramming 5 жыл бұрын
@@jaideepmore1299 I don't really have the bandwidth to take that on at the moment. My suggestion would be to ask your question on StackOverflow and see if you can get some help there. Taking the time to phrase the question in a concise and simple way is helpful in finding a solution oftentimes.
@jaideepmore1299
@jaideepmore1299 5 жыл бұрын
No worries. Thanks
@khbye2411
@khbye2411 4 жыл бұрын
23:14 I just learned that if none of the 3 branches in the _find function can be entered, then the function will return 'None'
@LucidProgramming
@LucidProgramming 4 жыл бұрын
Good to learn something new each day!
@vamsik3186
@vamsik3186 5 жыл бұрын
wow.....
@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 KZbin page. bit.ly/lp_email
@ahmedmohamed-yo2hb
@ahmedmohamed-yo2hb 5 жыл бұрын
in search method i wanna return the node in which i found my value not only desplay the value and for that i wrote this but it returns None even if the node was found def search(self,val): if val==self.root.value: print('found') return self.root curr=self._search(val,self.root) if curr is not None: return curr def _search(self, node, current): if current.value < node: if current.right is None: print("not found") return elif current.right.value == node: print('found') return current.right elif current.right.value != node: self.root = self.root.right current = self.root self._search(node, current) elif current.value > node: if current.left is None: print("not found") return elif current.left.value == node: print('found') return current.left elif current.left.value != node: self.root = self.root.left current = self.root self._search(node, current)
@LucidProgramming
@LucidProgramming 5 жыл бұрын
Cool, thanks for sharing the code!
Binary Search Trees in Python: Checking the BST Property
19:01
LucidProgramming
Рет қаралды 13 М.
Binary Trees in Python: Introduction and Traversal Algorithms
28:40
LucidProgramming
Рет қаралды 213 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 35 МЛН
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49
Binary Trees in Python: Calculating Height of Tree
15:37
LucidProgramming
Рет қаралды 26 М.
Python Data Structures #5: Binary Search Tree (BST)
31:54
Brian Faure
Рет қаралды 169 М.
Binary Search Tree in Python
22:59
NeuralNine
Рет қаралды 54 М.
Binary Trees in Python: Level-order Traversal
15:50
LucidProgramming
Рет қаралды 35 М.
10.1 AVL Tree - Insertion and Rotations
43:08
Abdul Bari
Рет қаралды 1,2 МЛН
Binary Tree Algorithms for Technical Interviews - Full Course
1:48:53
freeCodeCamp.org
Рет қаралды 734 М.
AVL Trees & Rotations (Self-Balancing Binary Search Trees)
20:38
Back To Back SWE
Рет қаралды 352 М.
Linked List - Data Structures in Python #1
48:54
NeuralNine
Рет қаралды 9 М.
Binary Search Tree Tutorial - Traversal, Creation and More
32:30
Tech With Tim
Рет қаралды 33 М.