Тёмный

Binary Search Trees in Python: Introduction - Insertion and Search 

Подписаться
Просмотров 45 тыс.
% 807

In this video, we will go over the binary search tree data structure. We will first cover the general idea of what a binary search tree is and how one may go about inserting data into this structure as well as how one searches for data. Once we cover the general idea, we will move over into the terminal and implement the binary search tree data structure in Python. We will construct two class methods that will implement the search and insertion algorithms.
If you are unfamiliar with tree-like data structures, I would encourage you to watch first the series on binary trees. A binary search tree is a type of binary tree. It is important to understand the various terminology used in the context of a tree data structure (root, node, leaves, parent, child, etc.). If any of those terms are unfamiliar to you, or you would like to brush up on them, the binary tree playlist may be found here:
bit.ly/lp_bt
This video is part of a playlist on binary search trees:
bit.ly/lp_bst
Slides:
docs.google.com/presentation/d/1tffjb_9GjBpZ9RG-RCaO71F-L6pwllph-Dq4_j6ajaI/edit?usp=sharing
The software written in this video is available at:
github.com/vprusso/youtube_tutorials/blob/master/data_structures/trees/binary_search_trees/insertion_search.py
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_subscribe

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

 

31 июл 2018

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 162   
@raisamaria6538
@raisamaria6538 4 года назад
I'm not the last or the first to say that you're a great teacher. Thanks
@LucidProgramming
@LucidProgramming 4 года назад
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 RU-vid page. bit.ly/lp_email
@rumanaislam4758
@rumanaislam4758 7 месяцев назад
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 7 месяцев назад
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 7 месяцев назад
@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!
@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!
@milkiasyeheyis5407
@milkiasyeheyis5407 3 года назад
I can't believe this channel has only 30k subs. Really amazing content. Thank you for 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!
@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!
@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!
@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 :)
@davidrowlands8548
@davidrowlands8548 2 года назад
Yet another excellent video. Thank you
@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!
@JoseHernandez-ed5lz
@JoseHernandez-ed5lz 3 года назад
Incredible! Absolutely incredible! Thank you so much for your content! This is golden content!
@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!
@annidamf
@annidamf 4 года назад
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 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
@harshavardhanachary3863
@harshavardhanachary3863 3 года назад
you taught the code in an easy manner....I like it.......thank you so much sir.
@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 RU-vid page. bit.ly/lp_email I hope to continue covering others topics like AVL trees and heaps in future videos!
@neurochannels
@neurochannels 4 года назад
Remove method would be nice that is a lot harder than add!
@bijayamanandhar3890
@bijayamanandhar3890 2 года назад
Thank you for such a nice and clear presentation,
@LucidProgramming
@LucidProgramming 2 года назад
Of course, thank you for watching!
@marinboras5001
@marinboras5001 3 года назад
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!
@piratevv
@piratevv 4 года назад
excellent teaching vincent!!
@LucidProgramming
@LucidProgramming 4 года назад
Thank you, very much appreciated!
@NikhilParekh7
@NikhilParekh7 3 года назад
It would be really helpful if you can continue this series.
@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!
@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!
@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 RU-vid page. bit.ly/lp_email
@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!
@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!
@kamaboko1
@kamaboko1 4 года назад
Exceptional tutorial.
@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 (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
@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 !!!
@kruthikhm6379
@kruthikhm6379 3 года назад
You are a different and 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!
@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!
@JollyBeJolly
@JollyBeJolly 3 года назад
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!
@prakashranjanpatra3539
@prakashranjanpatra3539 4 года назад
Thank you very much... 😊👍👍
@LucidProgramming
@LucidProgramming 4 года назад
Cheers, and thanks for watching!
@anirvansen2941
@anirvansen2941 4 года назад
Awesome as always :)
@LucidProgramming
@LucidProgramming 4 года назад
Thanks! :)
@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!
@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!
@namanvohra8262
@namanvohra8262 2 года назад
You just got a new subscriber
@LucidProgramming
@LucidProgramming 2 года назад
Much appreciated, thank you!
@debashishchakraborty7924
@debashishchakraborty7924 5 лет назад
Just WOW.!... Please post videos on graphs. :)
@LucidProgramming
@LucidProgramming 5 лет назад
It's on my to-do list! :)
@prasanjithpatel9490
@prasanjithpatel9490 3 года назад
great code !!!!
@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!
@amalmathew2030
@amalmathew2030 3 года назад
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!
@weichengzhu6605
@weichengzhu6605 5 лет назад
Hi Lucid, Thank you for your very nice tutorials! And for the slides of this series, could you share? Thanks
@LucidProgramming
@LucidProgramming 5 лет назад
I've updated the description with a link to the slides. Thanks for the suggestion, and thanks for your kind comment! Cheers!
@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 3 года назад
@@LucidProgramming Any update sir?
@LucidProgramming
@LucidProgramming 3 года назад
@@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
@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!
@mastermind5421
@mastermind5421 3 года назад
god tier tutorial
@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!
@estudosapenas7717
@estudosapenas7717 Год назад
a function calling itself inside its own structure is still something that my brain can not comprehend
@LucidProgramming
@LucidProgramming Год назад
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! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-dlCGc92tAqo.html
@jagdishwarbiradar1763
@jagdishwarbiradar1763 4 года назад
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 4 года назад
I've got you covered. I have a playlist on recursion you might find useful here: bitly.com/lp_recursion Cheers!
@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!
@mateuszsmendowski2677
@mateuszsmendowski2677 4 года назад
Can I have a question? Is there any vital difference between: 1. class Node(object): 2. class Node:
@LucidProgramming
@LucidProgramming 4 года назад
No, they are equivalent.
@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!
@heidik1757
@heidik1757 3 года назад
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 RU-vid. Hope that provides a reasonable start for ya, and don't hesitate to keep asking questions!
@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
@Mohit-nn9bt
@Mohit-nn9bt 4 года назад
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 4 года назад
Those are on my to-do list. Stay tuned!
@Mohit-nn9bt
@Mohit-nn9bt 4 года назад
@@LucidProgramming Sir People are asking for advance data structures tutorial from months.please try to update asap.Thanks
@LucidProgramming
@LucidProgramming 4 года назад
@@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 4 года назад
@MOHIT KUMAR You can make a donation of 10$ to suggest for a video, he will definitely appreciate it www.patreon.com/join/lucidprogramming
@theguildedcage
@theguildedcage 5 лет назад
Noob question: Is 'object' passed in by default when creating these classes or is it omitted?
@LucidProgramming
@LucidProgramming 5 лет назад
Hi Philip. I'm not sure I know what you mean. What do you mean when you say "object" in this case?
@theguildedcage
@theguildedcage 5 лет назад
LucidProgramming for example, what is the difference between these two classes. class Node(object): class Node:
@LucidProgramming
@LucidProgramming 5 лет назад
@@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!
@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 :)
@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!
@sutingyang9439
@sutingyang9439 4 года назад
Could you please make some video on Machine Learning?
@LucidProgramming
@LucidProgramming 4 года назад
Absolutely, I actually have a series on machine learning that you can find here: bit.ly/lp_mlearn Cheers!
@anshumangupta2842
@anshumangupta2842 3 года назад
Please make a series on graph
@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!
@Sagar_RS
@Sagar_RS 5 лет назад
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 5 лет назад
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.
@rishikeshpuri6101
@rishikeshpuri6101 4 года назад
Sir, pls make video on graph algorithm, dynamic programming, greedy algorithm
@LucidProgramming
@LucidProgramming 4 года назад
It's on my to-do list!
@KKinHD10
@KKinHD10 3 года назад
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
@dhananjaywadhavane4106
@dhananjaywadhavane4106 3 года назад
what if two values are same in array for binary search tree?
@LucidProgramming
@LucidProgramming 3 года назад
That violates the definition of a binary search tree.
@vamsik3186
@vamsik3186 4 года назад
wow.....
@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 (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
@khavishbhundoo3792
@khavishbhundoo3792 5 лет назад
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 5 лет назад
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.
@Samin7575
@Samin7575 4 года назад
that saved me....
@LucidProgramming
@LucidProgramming 4 года назад
Glad to hear it! If you benefited, please drop a like and subscribe. Cheers!
@junaidiqbal2321
@junaidiqbal2321 3 года назад
Sir what is self variable
@LucidProgramming
@LucidProgramming 3 года назад
I'm not going to be able to answer that in a RU-vid comment. You should use Google.
@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
@vishnurj6207
@vishnurj6207 2 года назад
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 2 года назад
When I get more time, I'll come back!
@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!
@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!
@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.
@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!
Далее
Кто понял тот понял
00:24
Просмотров 442 тыс.
Me: Don't cross there's cars coming
00:16
Просмотров 10 млн
Yeni Özbək Mahnisi Yoxsa Vefali Reqsi? 😍
00:36
Просмотров 1,2 млн
Кто понял тот понял
00:24
Просмотров 442 тыс.