Python Data Structures #5: Binary Search Tree (BST)

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 207

  • @chloeliu9207
    @chloeliu9207 4 หลายเดือนก่อน +1

    After searching thousand of videos at ytb, this tutorial is the most helpful and insightful! thanks!

    • @BrianFaure1
      @BrianFaure1  4 หลายเดือนก่อน +2

      @@chloeliu9207 Awesome news! Happy the video helped you ✌️

  • @BinaryAdventure
    @BinaryAdventure 2 ปีที่แล้ว +10

    Yeah I've watched a lot of these. This video really helped me to re-grasp the concept well; it's hard to put into words but you are well-spoken and direct, which I learn best from. You do not ramble and wander in your presentations which is helpful for technical subjects.

  • @nackyding
    @nackyding 4 ปีที่แล้ว +10

    Best walk through implementation of BST on TH-cam by far! Thank you so much.

  • @Abhi-qi6wm
    @Abhi-qi6wm 3 ปีที่แล้ว +1

    def insert(self,data):
    if self.root:
    self._insert(data,self.root)
    else:
    self.root=node(data)
    def _insert(self,data,curr_node):
    if curr_node is None:
    curr_node=node(data)
    return curr_node

    if datacurr_node.data:
    curr_node.right=self._insert(data,curr_node.right)
    else:
    print( 'Value already exists')
    return None
    return curr_node
    Implemented a shorter version of the insert method :)

  • @nancycarlson548
    @nancycarlson548 4 ปีที่แล้ว +1

    So yes, please make a delete node video. What is great about your approach is your commentary as you are writing the code. This is sooo helpful to those of us who are still learning how to write the code as it connects to the logic of the data structure. This teaching technique is hard to find! Please keep this up and thank you.

  • @333robel
    @333robel 5 ปีที่แล้ว +2

    The sound at 7:39 super motivating... and the energy level from 7:25-7:40 is just threw threw the roof.

  • @Samuel-lm1wb
    @Samuel-lm1wb ปีที่แล้ว

    Thank you! very helpful, watched like idk 6 or so videos on youtube but they were mad confusing especially on the recursion part. You were clear thank you

  • @fredesch3158
    @fredesch3158 3 ปีที่แล้ว

    Really nice, I was really stuck at how to start implementing, when I saw the use of 2 classes one for the node and one for the tree itself everything just clicked, I coded and it worked, THANK YOU SO MUCH, I always need a jumpstart to make my brain work and your video was just perfect.

    • @shreehari2589
      @shreehari2589 2 ปีที่แล้ว

      I agree, Two classes is the way best way to implement any non linear data structure!

  • @HarveyXE
    @HarveyXE 3 ปีที่แล้ว

    Thank you for being clear about the values on the left and right side of the tree. Very helpful detail.

  • @jennaalden3658
    @jennaalden3658 3 ปีที่แล้ว +3

    awesome video! in the function ` fill_tree`, you don't need to return tree, it does it "inplace"

  • @autismo1969
    @autismo1969 2 ปีที่แล้ว

    very good explanation of binary search trees. straight to the point. explained each of the parts very well. thanks a lot!

  • @BrianFaure1
    @BrianFaure1  7 ปีที่แล้ว +3

    Part 2 (deletion) of the Binary Search Tree lesson can be found here: th-cam.com/video/Zaf8EOVa72I/w-d-xo.html

  • @carlavirhuez4785
    @carlavirhuez4785 2 ปีที่แล้ว

    Finally! I undertand BST! Thanks a lot for yoru help

  • @MCNeko6554
    @MCNeko6554 ปีที่แล้ว

    Thank you, helped me finish my homework without losing my mind x'D

  • @vishesh_soni
    @vishesh_soni 4 ปีที่แล้ว

    Very Nice and clean Code. You know I was thinking of making DS&A with python videos on youtube coz I couldn't find any. But now I have seen way better than I expected.

  • @wojohn6441
    @wojohn6441 2 ปีที่แล้ว

    best binary tree tutorial ever!

  • @chaoticpringle2578
    @chaoticpringle2578 6 ปีที่แล้ว +5

    Thanks for this! I was having trouble understanding my professor when we learned this today.

  • @davidarthurpaul
    @davidarthurpaul 6 ปีที่แล้ว +14

    Fantastic video and great explanations. Rarely comment but please keep this up

  • @boohoo334
    @boohoo334 5 ปีที่แล้ว +1

    Such an underrated channel

  • @zakiahmedqureshi4358
    @zakiahmedqureshi4358 6 ปีที่แล้ว +1

    easy to understand and pretty well summed up the BST. thanks :)

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      Thanks for watching!

  • @AnilYadav-ut5zj
    @AnilYadav-ut5zj 3 ปีที่แล้ว +1

    For the _height() function, shouldn't you return cur_height -1 because even if its None, you have already incremented current height by 1 via the recursive functions.

    • @TheSSB007
      @TheSSB007 3 ปีที่แล้ว

      I observed this too, or you can start with -1 instead of zero

  • @RaniLink
    @RaniLink 3 ปีที่แล้ว

    You find the tree's height much simpler with:
    _height(self, current_node):
    return -1 if current_node is None else 1+max (self_height(current_node.left), self_height(current_node.right))

  • @yaseen1478
    @yaseen1478 6 ปีที่แล้ว +87

    7:39

  • @karthikudupa5475
    @karthikudupa5475 4 ปีที่แล้ว +1

    Thanks a lot Brian, I was actually looking for this. Well explained.

  • @bright1402
    @bright1402 4 ปีที่แล้ว

    Very concise and informative! Thanks man

  • @akizzlebrand4657
    @akizzlebrand4657 5 ปีที่แล้ว

    Best video and code I've seen on this and I've been looking for weeks! Thank you!

  • @azizas9366
    @azizas9366 6 ปีที่แล้ว

    Very clear since I am coming from Java.

  • @arturfil
    @arturfil 4 ปีที่แล้ว

    Excellent explanation! Great work!

  • @alexsugarman9511
    @alexsugarman9511 5 ปีที่แล้ว

    For your insert method, I would change the parameter to *args. That way you can input one, or multiple values with one insert command from your main. You just have to iterate through the args first

  • @darkseeven
    @darkseeven 5 ปีที่แล้ว +1

    32 minutes of yt video (this) = Better_than(My_asd_classes) + Understanding

  • @sifagayev7793
    @sifagayev7793 2 ปีที่แล้ว

    Great tutorial

  • @burakhanaksoy
    @burakhanaksoy 3 ปีที่แล้ว +1

    Brian, another amazing video!! I want to ask a question though. What is the main reason you portion a function to private and public? Just want to understand the logic behind. Thanks for the tutorial~

    • @fredesch3158
      @fredesch3158 3 ปีที่แล้ว

      I'm not the creator, but as far as I understood the private function takes as an additional parameter the node to analyze, the public one assumes the beginning of the tree (or the root of the tree).

    • @tibettenballs4962
      @tibettenballs4962 2 ปีที่แล้ว

      No. It’s a snake to mouth paradigm. You’ll get it after much practise suqqing on knobs and snake heads.

  • @jasonzhang6534
    @jasonzhang6534 4 ปีที่แล้ว

    thanks for the video! well explained, good pace

  • @ashwinimandani2829
    @ashwinimandani2829 5 ปีที่แล้ว

    Great explanation sir..

  • @wenchehsu8915
    @wenchehsu8915 7 ปีที่แล้ว +2

    Nice video! Expecting to see the deletion part of BST :D

    • @BrianFaure1
      @BrianFaure1  7 ปีที่แล้ว +1

      Haha sorry about that, I'll be coming out with a video on it soon! I'll reply again to your comment again once it's released.

    • @wenchehsu8915
      @wenchehsu8915 7 ปีที่แล้ว

      Brian Faure I'm so appreciate :D Thank you for your effort on these nice videos

    • @BrianFaure1
      @BrianFaure1  7 ปีที่แล้ว +2

      Just finished the video covering the deletion function: th-cam.com/video/Zaf8EOVa72I/w-d-xo.html , thanks again for the kind comments!

    • @wenchehsu8915
      @wenchehsu8915 7 ปีที่แล้ว

      Thank you! I have watched it immediately :D Looking forward to your following videos!

  • @shrikantkarki4966
    @shrikantkarki4966 6 ปีที่แล้ว

    Superb explanation and coding.Helped a lot.Thanks Brain

  • @rahadulislamrahat328
    @rahadulislamrahat328 10 หลายเดือนก่อน

    Do you have video in Graph a nd algorithm

  • @ankittank2098
    @ankittank2098 5 ปีที่แล้ว

    Amazingly explained!! Hats Off

  • @joshiravishankar
    @joshiravishankar 4 ปีที่แล้ว

    Fantastic video, can be understood quickly :)

  • @subashchandrapakhrin3537
    @subashchandrapakhrin3537 3 ปีที่แล้ว

    Thank You Brian

  • @johndu9255
    @johndu9255 4 ปีที่แล้ว

    Hi Brain, I met a problem with this code, the "search" function does not return "True" when the number was generated by the "Random function", but inserted number is fine. do you have any idea about this? Thank you !

  • @VibhaDhar
    @VibhaDhar 6 ปีที่แล้ว +1

    Great video! I have followed your linkedList video also. The code is clean and easily understandable. Can you please plan on adding DFS and BFS also.

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +1

      Thanks! Sure thing, I'll do a vid on the different traversal methods and build off the BST code from this video.

    • @lenaerbs8359
      @lenaerbs8359 9 หลายเดือนก่อน

      ​@@BrianFaure1 I want to see these videos. Where are they?

  • @mrhobojim6098
    @mrhobojim6098 2 ปีที่แล้ว

    Really helpful thankyou

  • @djuka8121
    @djuka8121 4 ปีที่แล้ว +1

    could you please explain me a little bit more about _print_tree(self, cur_node) function?

  • @utkarshpol123
    @utkarshpol123 4 ปีที่แล้ว

    when in search I search for a number which is not in the list instead of false it shows an error saying non-type attribute value

  • @wahtsfgsgwwwsxq
    @wahtsfgsgwwwsxq 5 ปีที่แล้ว

    Excellent explanation! Thank you!

  • @brianwahome5789
    @brianwahome5789 7 ปีที่แล้ว +2

    You are a God!! Mind doing a BST validator too? Also it would be great having access to the repo you post this Code in. Thank you so much!

    • @BrianFaure1
      @BrianFaure1  7 ปีที่แล้ว +3

      Thanks Brian! I've just posted the code here: github.com/bfaure/Python_Data_Structures/blob/master/Binary_Search_Tree/main.py , it also contains the logic for the deletion function which isn't covered in this video. Thanks also for the recommendation, I'll definitely do a BST validator ASAP.
      Edit: BST Validator lesson can be found here: th-cam.com/video/azupT01iC78/w-d-xo.html

  • @EnglishRain
    @EnglishRain 3 ปีที่แล้ว

    Great tutorial, thanks a ton!

  • @ardsnijders7777
    @ardsnijders7777 5 ปีที่แล้ว

    one small thing I ran into; at one point you define the fill_tree function, pass in the Tree object and re-assign the output to variable tree. However, (In my implementation) doing so reset the type of tree from to which rendered me unable to perform the tree.print_tree() method.

  • @daliacruz759
    @daliacruz759 6 ปีที่แล้ว

    This is a great video! Did you ever make a video on the different traversals? If not, it would be cool to see one.

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +2

      Hi Vanessa, unfortunately I haven't yet gotten around to making that but it is on the queue. Thanks for watching!

  • @rizkifitrarrijal9138
    @rizkifitrarrijal9138 4 ปีที่แล้ว

    thank you so much for the explanation

  • @siddharthadas86
    @siddharthadas86 7 ปีที่แล้ว +1

    fantastic explanation! Thanks again.

  • @adeolaogunleye7965
    @adeolaogunleye7965 2 ปีที่แล้ว

    Can i add the new root value at the binary_search_tree __init__

  • @marco.nascimento
    @marco.nascimento 5 ปีที่แล้ว

    Amazing explanation, very nice!!

  • @rwothoromoelijah
    @rwothoromoelijah 5 ปีที่แล้ว

    Very good explanations. Much appreciated!

  • @indominus9184
    @indominus9184 2 ปีที่แล้ว

    please make a video on Hashtable with linear probing

  • @isha6510
    @isha6510 5 ปีที่แล้ว

    If we only want to write the left view of the tree then how can we do it . I mean with print function when i tried to print only the right part of the tree it worked properly but for the left it's not working. Can you please help me?

  • @kritiohri2950
    @kritiohri2950 7 ปีที่แล้ว

    Hi Brian..just as we are printing the value of current node or the root (print(str(cur_node.value))) , where are we printing the values of left and right child?? Only call is being made to the fucntion (self._print_tree(cur_node.left_child)) and self._print_tree(cur_node.right_child)

    • @BrianFaure1
      @BrianFaure1  7 ปีที่แล้ว

      Hi Kriti, the left child will be printed before the cur_node and the right child will be printed after...
      > self._print_tree(cur_node.left_child) # this will print the left_child (if not None)
      > print str(cur_node.value) # this will print the cur_node
      > self._print_tree(cur_node.right_child) # this will print the right_child (if not None)
      ...and because it's handled by recursion, we don't need to specifically call 'print str(cur_node.left_child.value)' or 'print str(cur_node.right_child.value)', just passing both as parameters to the _print_tree function is enough. I hope that clears it up.

    • @kritiohri558
      @kritiohri558 7 ปีที่แล้ว +1

      Thanks Brian for the wonderful explanation

  • @tomporkka5273
    @tomporkka5273 4 ปีที่แล้ว

    Thanks for this! Quick question, are the BST's at 00:44 and 01:28 valid or is that a typo? I'm confused by the left side where the child nodes of 7 are 2 and 6?

  • @RomanMamedov333
    @RomanMamedov333 5 ปีที่แล้ว

    Thanks for this video.

  • @davidgutierrezarias3309
    @davidgutierrezarias3309 6 ปีที่แล้ว

    @Brian Faure ,in an interview do you recommend to follow your approach , I mean break in two functions. Thanks

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +2

      Hey David, for interviews I think the best approach is whatever is easiest for you to code and, more importantly, to be able to explain. I doubt you would be asked to code an entire BST for an interview but it's certainly possible, more likely would be just a single function (insert for example). When it comes to coding during interviews it's hard to know how much the interviewer is expecting of you so while you're writing if you come to a point where it would make sense to call a function to perform some action (for example if you were moving an object across a screen and would call a function to perform the x,y coordinate transform) I would say certainly call the extra function, if you have time you can fill in the logic for that later on. It's definitely better to have the higher-level program correct vs getting stuck in the weeds trying to figure out some logic in the beginning, then never actually even finishing the high level logic. For the recursive functions we use in the BST here, you could either break it into two functions (as seen in the video) or use a single function that performs all the stuff of the non-recursive function only on the first iteration (so you would need some sort of variable to check to see if you're on the first iteration or not), in this case I think breaking it into two functions makes sense but I'm sure many programmers would disagree. Good luck with the job hunt!

  • @mohammad-bunyanish
    @mohammad-bunyanish 6 หลายเดือนก่อน

    Why are you creating 2 classes

  • @mykinvincible
    @mykinvincible 5 ปีที่แล้ว

    nice video, i am not able to understand how does the display method work. can you please explain that ?

  • @mahyarsedigh6203
    @mahyarsedigh6203 4 ปีที่แล้ว

    when _search called recursively, doesn't it check the value first and if it is equal to what we are looking for it should return True; I am confused in your first run you got False False; why you had to add return statement before each of those calls?

    • @BrianFaure1
      @BrianFaure1  4 ปีที่แล้ว +1

      Hi Mahyar! Yes it does return True if the current value is equal to what we're searching for but if its not it needs to recurse lower into the tree (in the recursive function calls). The issue with the first approach was that when we recursed into the tree we weren't propagating the return values back up the function stack i.e. if one of the lower search calls found True we wouldn't return that, we would continue to the bottom of the function and just return False. Please let me know if this makes sense.

    • @mahyarsedigh6203
      @mahyarsedigh6203 4 ปีที่แล้ว

      @@BrianFaure1 Thanks Brian

  • @AbhishekSingh-cx5dr
    @AbhishekSingh-cx5dr 6 ปีที่แล้ว +1

    this is just awesome..sir thanks

  • @animeknowledge8381
    @animeknowledge8381 4 ปีที่แล้ว

    Using Python 3.8 so may be the reason but it is just calling the place in memory and not the value at the pointer so im getting a typeError when calling value

    • @animeknowledge8381
      @animeknowledge8381 4 ปีที่แล้ว

      had to set in class node that self.value = value and not None it was overwriting my values in the node constructor

  • @ayeinsayali1340
    @ayeinsayali1340 3 ปีที่แล้ว

    great video man .. thumbs up from me

  • @ManaNoodles
    @ManaNoodles 4 ปีที่แล้ว +13

    The way this guy doesn't put spaces around commas and equality operators drives me nuts

  • @natalieweishuhn521
    @natalieweishuhn521 5 ปีที่แล้ว

    Fantastic video~ You're the first person that has explained this in a way that makes sense!! THANK YOU

  • @nikitaizmaylov4888
    @nikitaizmaylov4888 4 ปีที่แล้ว

    THANKS my guy) Definitely deserve the recognition)

  • @lilysu2529
    @lilysu2529 4 ปีที่แล้ว +5

    the fast forward sounds now reminds me of animal crossing XD

  • @JoaoCfgc
    @JoaoCfgc 5 ปีที่แล้ว

    Great video man very useful!

  • @kajalmondal9745
    @kajalmondal9745 2 ปีที่แล้ว

    Thank you so much sir

  • @jojoesekyisagoe
    @jojoesekyisagoe 4 ปีที่แล้ว

    I guess you dont need to check if self.root == None in the height function since the recursive call takes care of a None condition. you can just have "return self._height(self.root, 0)" as the only line in the height function.

  • @rakheekulkarni2708
    @rakheekulkarni2708 7 ปีที่แล้ว +1

    excellent video, very informative

  • @neuralnets6656
    @neuralnets6656 5 ปีที่แล้ว

    Can you demonstrate the code for the case where value == cur_node?
    Currently, you are printing "Value already in tree" - can you demonstrate the code to handle duplicate values by replacing the cur_node with value? Thanks.

  • @nicknaik
    @nicknaik 6 ปีที่แล้ว +1

    Excellent, thanks!

  • @rohitkumarj632
    @rohitkumarj632 4 ปีที่แล้ว

    How to store the tree created permanently even after closing the file. And also on fetching the tree and updating, the updates must also be saved.

  • @jingyuchang1885
    @jingyuchang1885 6 ปีที่แล้ว

    Thank you very much Brian!! Really good video! I noticed in your code which you posted in github is actually not the same as the code in the video. You added parent pointer in github. You used the parent pointer in insert function and deletion function. I wonder is there any advantage to have the parent point? Or it's just easy for the deletion function?

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      Hi Jingyu, the parent pointer is mostly just to simplify the deletion function. When we delete a node we need to alter the parent (so it no longer points to the node we wish to delete) and if we didn't include a parent pointer we would need to traverse through the tree to find the parent before we could actually perform the deletion, which could take a while if our tree was fairly large. The parent pointer is also involved in the insertion function but all we do there is set it correctly when we insert a new node.
      I explain it a bit more in the deletion video but when we call delete_value (which is a passed a value in the tree) we still _do_ have to traverse through the tree to find the node with that value, so the parent pointer only really increases the efficiency of the 'delete_node' function.

    • @jingyuchang1885
      @jingyuchang1885 6 ปีที่แล้ว

      Thank you very much Brian! You explained very clear! I literally wrote down every single word you said in the videos as notes cause my native language is not English. Sometimes I need to read the notes again after the video to make myself really understand! You videos really helped me a lot! I will watch all your videos and hope you will make more videos!! Thanks again!

  • @avhishekbiswas4251
    @avhishekbiswas4251 5 ปีที่แล้ว

    in the insert function , in else block why is there a '_' before insert ?? are we just calling the insert recursively?

  • @arthurzhang7868
    @arthurzhang7868 5 ปีที่แล้ว

    great explanation!

  • @pjcamiam
    @pjcamiam 4 ปีที่แล้ว

    Don't know how people are saying the style is clean when it could use quite a bit of help (please use more space out operators and operands), but otherwise nice implementation

    • @rockstarjazzcat
      @rockstarjazzcat 4 ปีที่แล้ว

      Adherence to PEP 8 would definitely make it clearer!

    • @pjcamiam
      @pjcamiam 4 ปีที่แล้ว +1

      @@rockstarjazzcat Absolutely

  • @jimmyshenmusic
    @jimmyshenmusic 6 ปีที่แล้ว

    Super nice video. I love your code of the BST. It will be good if the code is posted online. Also, for the private method, name is under the double underscore will also work, right? I found the lib of python is using double underscore for all the private functions.

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +2

      Hi Jimmy, thanks for the nice comment! The code for this video can be found here: github.com/bfaure/Python_Data_Structures/blob/master/Binary_Search_Tree/main.py . Using a single underscore is more of a Python style convention than anything, it basically tells anyone using the code that they should refrain from calling the function directly (essentially making it a private function of the class, as you say) but doesn't enforce this in any way. A double underscore function or variable is actually treated slightly differently by the Python interpreter. I found a good answer on stack overflow talking about this exact thing ( stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-name ).

    • @jimmyshenmusic
      @jimmyshenmusic 6 ปีที่แล้ว

      Thanks for the sharing of the code. Also thanks a lot for the link provided on the explanation of the difference of the double underscore and single underscore. It is very clear. Thanks.

  • @rahularvindshinde
    @rahularvindshinde 6 ปีที่แล้ว

    this is really helpful...

  • @shibajichatterjee3190
    @shibajichatterjee3190 6 ปีที่แล้ว

    Thanks a lot for the tutorial. Can you please make a video on creating a Huffman tree., as that is a binary three we create from the leaf to the root ( from below), I am having a hard time figuring out implementing the algorithm.

  • @vincentluong6238
    @vincentluong6238 6 ปีที่แล้ว +1

    Needs more views

  • @rockstarjazzcat
    @rockstarjazzcat 4 ปีที่แล้ว

    Historically BST right node uses ">=," allowing for duplicate keys.

  • @irisx6619
    @irisx6619 6 ปีที่แล้ว

    Hi, Any chance that you can explain how to take words from a paragraph in a text file and store them in the BST?
    Thanks.

    • @ilkinaliyev1044
      @ilkinaliyev1044 5 ปีที่แล้ว

      No need to BST, you don't sort elements. Hashing does fit here actually

  • @oishikachaudhury3718
    @oishikachaudhury3718 5 ปีที่แล้ว

    Not related to data structures but can you please do a Github tutorial video? Thanks!

  • @nernaykumar8334
    @nernaykumar8334 5 ปีที่แล้ว

    i am getting an error AttributeError: 'binary_search_tree' object has no attribute '_print_tree' please help me in this one

    • @nernaykumar8334
      @nernaykumar8334 5 ปีที่แล้ว

      it is at line no - 38 please help me out

  • @wonjaehwang7670
    @wonjaehwang7670 6 ปีที่แล้ว

    What kind of keyboard do you use?

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      corsair k65 rgb with Cherry red keycaps :)

    • @wonjaehwang7670
      @wonjaehwang7670 6 ปีที่แล้ว

      @@BrianFaure1 They sound great :)

  • @yuanyuan23191212
    @yuanyuan23191212 4 ปีที่แล้ว

    Thanks for your video! I have a question. This tree at first is empty. Then how come it will return 'Value already in tree!' in the first line when printing the tree?

    • @yuanyuan23191212
      @yuanyuan23191212 4 ปีที่แล้ว +1

      ah, just realize 'Value already in tree' comes from insertion, not printing

  • @MattUKepcc816
    @MattUKepcc816 6 ปีที่แล้ว

    Hello Brian I wanted to ask what does line 68 do? “ tree = binary_search_tree() “ I typed the code exactly how you typed it for practice and shows it’s an undefined name. I’m coding on Python 3.6
    Thanks!

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      Hey Matt, "tree=binary_search_tree()" will set the 'tree' variable equal to a newly created instance of the binary_search_tree class, if this isn't working for you make sure that you named the class 'binary_search_tree'. If you did, feel free to share your code on repl.it and I can take a look for you.

    • @MattUKepcc816
      @MattUKepcc816 6 ปีที่แล้ว

      Yes its still not working for me, even after changing variables and class names. Heres my code: repl.it/@miglesias4/ProductiveRawQuadrant
      Thank you for taking the time to assist me much appreciated!

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      That link seems to be broken, getting a 404 when trying to go to it.

    • @MattUKepcc816
      @MattUKepcc816 6 ปีที่แล้ว

      This one should work: repl.it/@miglesias4/BinarySearchTree

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว

      Okay, I think I fixed the issue you were having repl.it/repls/ShockingClientsideTutorial , the problem was that in your 'init' functions you only had a single underscore '_' on each side of 'init' whereas, to declare a Python class constructor you need double underscores '__'. I also removed the first 'self' parameter from your recursive calls to _insert because you don't need to specify 'self' when calling a class member function, only when defining it. There were some other minor naming issues I fixed up so it should be working now.

  • @gokulraviteja5209
    @gokulraviteja5209 6 ปีที่แล้ว +1

    Video on segment trees,Fenwick trees...

  • @-mwolf
    @-mwolf 3 ปีที่แล้ว

    thx really helpfull

  • @BL-om2hn
    @BL-om2hn 6 ปีที่แล้ว +1

    22:46 Hi Brian, could you give a more detailed explanation for the recursive part of the _height function. Like what will the left.height and right.height return if the cur.height of the left.height or right.height are not None yet.

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +7

      Hi Bowen, I'll explain using the following line identifiers (A,B,C,D)...
      (A) > if cur_node==None: return cur_height
      (B) > left_height=self._height(cur_node.left_child,cur_height+1)
      (C) > right_height=self._height(cur_node.right_child,cur_height+1)
      (D) > return max(left_height,right_height)
      Line A is essentially the base case of this recursive function, once we hit the child of a leaf node (which will equal 'None') we return the total height we've accumulated across the recursive calls, 'cur_height'. In line B we are starting a new recursive branch that will retrieve for us the height of the left sub-tree of 'cur_node', and similarly, in line C we start a new recursive branch to return the height of the right sub-tree of 'cur_node'. In line D we return the greater of the two heights, because the height of a node is defined as the longest distance from that node to a leaf node. It may be easier to understand if you realize this function will be called exactly once for each node in the tree (plus the 'None' children of leaf nodes), and the recursive calls would basically trace out a depth-first search of the tree, though we don't search for values rather we simply add to our found height.
      In lines B and C, the reason we pass cur_height+1 as the second parameter to the _height function is that we must increment our height value by one because we are traversing down to the next level in the tree. Let me know if this cleared it up at all or if you have any further questions. If you're interested, a resource that helped me understand this function in more depth was this great tutorial by mycodeschool th-cam.com/video/_pnqMz5nrRs/w-d-xo.html

    • @BL-om2hn
      @BL-om2hn 6 ปีที่แล้ว

      Thank you so much!

  • @saideepspeaks
    @saideepspeaks 3 ปีที่แล้ว

    💥💥

  • @vihaandhruthi
    @vihaandhruthi 6 ปีที่แล้ว

    Firstly, Thanks for the beautiful videos. You are the best!!. I have a question, In _insert method, why can't we handle duplicates. Doesn't binary search tree insert the values equal to the current node to the left. In that case, can't we just have the first "if" condition as

    • @BrianFaure1
      @BrianFaure1  6 ปีที่แล้ว +1

      It just depends on the specific implementation, some BSTs might put equal values to the right and some to the left, in this case I decided to omit equal values for simplicity. Without actually running it myself, I don't think there would be any issues if you used

    • @vihaandhruthi
      @vihaandhruthi 6 ปีที่แล้ว

      Thanks!!

  • @pedrocastro882
    @pedrocastro882 3 ปีที่แล้ว

    THANK YOU!!!!!!!!!!!!!!

  • @kirimi782
    @kirimi782 5 ปีที่แล้ว

    thanks @BrianFaure.