Binary Search Trees (BSTs) - Insert and Remove Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 พ.ย. 2024
  • Harvey Mudd College
    CS 60
    Prof. Colleen Lewis
    Lecture 06 part 2
    Content: Binary Search Trees (BSTs) - Insert and Remove Explained

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

  • @fuckkg
    @fuckkg 9 ปีที่แล้ว +57

    this is probably the best tutorial on TH-cam

  • @Karim-nq1be
    @Karim-nq1be ปีที่แล้ว +2

    First I thought this explanation was going bad because the quality of the picture you put is low. But that's actually one of best explanations I've seen, thank you.

  • @williamz8330
    @williamz8330 4 ปีที่แล้ว +2

    This is the best explanation of BST methods I've seen

  • @Simoky99
    @Simoky99 5 ปีที่แล้ว +7

    video from 2013 helping me 6 years later.... thanks!

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

      Glad to hear it! :-) - Colleen

    • @Serrchh
      @Serrchh 7 วันที่ผ่านมา

      And here for me 11 years later. I hope you achieved your goal from back then!

  • @Daniellagnaux
    @Daniellagnaux 3 หลายเดือนก่อน +1

    Of all videos on TH-cam, you posted the best tutorial on BST

    • @ColleenMLewis
      @ColleenMLewis  3 หลายเดือนก่อน

      Thank you! I'm glad it was helpful to you!

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

    Awesome! clear and concise explaination! İ came here from the Odin project

  • @JohnSmith-zg2id
    @JohnSmith-zg2id 8 ปีที่แล้ว

    What my professor couldn't make clear lecture after lecture after lecture, nor could my TA, you did in 6 minutes. Thank you so much for sharing this.

  • @aryangoel4320
    @aryangoel4320 10 หลายเดือนก่อน +1

    best explaination , simple language and covering all the cases . THANKS A LOT

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

      Glad it was helpful! Thanks for the note!

  • @vishnuvalleru
    @vishnuvalleru 10 ปีที่แล้ว +1

    This is the best explanation I ever came across. short and up to the point. Thank you.

  • @conradmbugua9098
    @conradmbugua9098 2 ปีที่แล้ว +4

    concise and clear, such a beautiful presentation ma'am

  • @VipinKumar-uy2sw
    @VipinKumar-uy2sw 8 ปีที่แล้ว +5

    Damn ! Tree operations are so easy ! This 6 min video taught me what I couldn't learn in 3 hour class. U r amazing ...thx ...muaahhh :)

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

    This was one of the best explanations I have seen yet, so simple, so concise. Thank you, Colleen

  • @jayjoshi3853
    @jayjoshi3853 9 ปีที่แล้ว

    I have checked many insertion and deletion videos, but yours is best one. Sweet, short ,simple and effective though. Thanks.

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

    Small and concise. To the point. Loved it. Thanks alot.

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

    thank you so much for that simple explanation!. i was so confused about this all the time

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

      I'm glad it is helpful to you!

  • @geeksclub3455
    @geeksclub3455 9 ปีที่แล้ว

    The best video ever.. Made the deletion look so much easier.. I wish you were my teacher

  • @dulanjanaliyanagama3823
    @dulanjanaliyanagama3823 8 ปีที่แล้ว

    The way you explained is brilliant!!! It's marvellous that you manage the whole thing within 6 minutes. Job well done!!!

  • @MrNish27
    @MrNish27 8 ปีที่แล้ว

    amazing explanation. I used to always get stuck in the removal of a node, but now everything is clear.

  • @TheXHypex
    @TheXHypex 9 ปีที่แล้ว +8

    Learning for my exams at the moment so thank you very much for this video!

    • @ColleenMLewis
      @ColleenMLewis  9 ปีที่แล้ว +1

      TheXHypex Thanks! I hope the exams went well!

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

    It took you 6minutes to explain something our teacher failed to do in 2 hours, thx

  • @mrodriguezglobe
    @mrodriguezglobe 4 ปีที่แล้ว +2

    Binary Search Tree Delete: 1:45

  • @shahzamanniazai3832
    @shahzamanniazai3832 9 ปีที่แล้ว +4

    Excellent video ... Best way to learn is to sit patiently, watch and practice the mind along with the video (pausing video at various points to do self analysis).....
    Reply ·

  • @AmbiguousAbhi
    @AmbiguousAbhi 8 ปีที่แล้ว

    i have my exam in 1 hour, and was getting confused in delete and insert. U made it look very easy. thanks a lot . #awesome

    • @ColleenMLewis
      @ColleenMLewis  8 ปีที่แล้ว

      +Abhijeet Joshi Good luck! :) Thanks for the comment!

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

    Algo and Data structures exams in 2 hours. Thanks for saving my life.

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

      Thanks for the note - I'm happy it was helpful! - Colleen

  • @mryup6100
    @mryup6100 4 ปีที่แล้ว +2

    This clears up everything I only 6 minutes!

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

      I'm glad the video is helpful to you! - Colleen

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

    Great! This was a really clear review. Except for case 3 you only talked about finding the min of the right subtree. One can also replace the target node with the max of the left subtree. Either method works in keeping the tree in order.

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

      That's correct. And we only need to replace it with one of those - and we should be consistent about which one we choose.

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

      👍🏿

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

      nice

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

    Using your video to prepare for an interview. Thanks for your help.

  • @towhidskynet
    @towhidskynet 9 ปีที่แล้ว +14

    Finally. English. thank you so much!!!

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

    I can't believe I understand this now better than after a 2 hours class at the uni

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

      Glad to hear it was helpful!

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

    Thank you so much your explanation is very good and easy to understand....hope you will be uploading such types of explanation in next topics

  • @alexitosrv
    @alexitosrv 8 ปีที่แล้ว

    Very succinct and to the point. Good video! I loved also the style for representing the different cases so I can rebuild the algorithm my own head without need to memorize anything else.

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

    This video might be old but it was so useful and effective!
    Thanks a lot! Wish you all the best!

  • @Mmnc-bv3rk
    @Mmnc-bv3rk ปีที่แล้ว

    best explination i could find on the subject, thank you a lot

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

    your video is best than other countries TH-camr video

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

    Best explaination

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

    Useful and clear, thanks. BSTs seem like a very useful invention.

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

    professor dude from my uni took 2 hrs to explain this 6 mins and this female wibba explains a whole lot better, thanks a lot madam.

  • @mrodriguezglobe
    @mrodriguezglobe 4 ปีที่แล้ว +2

    Thank you so much for this video!

  • @Ginzo111
    @Ginzo111 8 หลายเดือนก่อน +1

    Amazing explanation, thank you

  • @PRIYANKA1998
    @PRIYANKA1998 9 ปีที่แล้ว +2

    i never thought it was this easy

  • @squirrelbrains2197
    @squirrelbrains2197 8 ปีที่แล้ว

    thanks, that was a simple, but very clear explanation.

  • @deveren
    @deveren 7 หลายเดือนก่อน +2

    Greetings from odin!

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

    this helps me. I understand BSTs really well, but removing nodes continues to stump me. thank you for the clarification.

  • @FA-ff4dz
    @FA-ff4dz 5 ปีที่แล้ว

    Thank you so much for making such an awesome video that explains the whole idea clearly. It helps me a lot

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

      I'm glad it was helpful! Thanks for the comment!

  • @badis23
    @badis23 9 ปีที่แล้ว

    Very clear tutoriial and nice voice too thanks sweety!

  • @bombambum7955
    @bombambum7955 9 ปีที่แล้ว +19

    short and effective !!

    • @ColleenMLewis
      @ColleenMLewis  9 ปีที่แล้ว +7

      BomBamBum Thanks! And thanks for the ascii art below! :-)

  • @durgeshbg
    @durgeshbg 5 หลายเดือนก่อน

    its 2024 and this's still a great explanation

    • @ColleenMLewis
      @ColleenMLewis  5 หลายเดือนก่อน +1

      Thanks so much! :)

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

    THANKYOU SO MUCH😭💓

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

      Thanks for the comment! I'm glad it was helpful! :-)

  • @Mahdi-hq4te
    @Mahdi-hq4te 7 ปีที่แล้ว

    Very helpful, thank you! I also liked the way you explained it.

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

    Awesome thanks understood it within a time span of 6 mins :D

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

    thank you so freaking much!

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

      I'm glad it is helpful to you!

  • @ThiagoBenazziMaia
    @ThiagoBenazziMaia 8 ปีที่แล้ว

    Fastest and best video -)

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

    This video is really helpful and effective to learn about trees.I am from Bangladesh.Thanks Colleen Lewis ♥

  • @erickvazquez2070
    @erickvazquez2070 9 ปีที่แล้ว

    Thank you so much! This is very clear and easy to follow!

  • @SuperJAIMISH
    @SuperJAIMISH 8 ปีที่แล้ว

    Pretty concise and clear. Thanks!

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

    Extremely useful! Thanks for uploading.

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

      Thanks! :-) I'm glad it is helpful!

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

    what a badass teacher

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

    Clearly explained. Thanks!

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

    But what happens to nodes labeled 34 and 36 when we remove their father( when we replaced 30 by 32) Now 34 and 36 should be placed on the left subtree of 40 and not on its right, how to deal with it algorithmically?

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

      When we replaced 30 with 32 we had to have deleted 32 so it is only in the tree once! To see what happens to 34 and 36 in that case, you can watch the video at 2 minutes and 50 seconds (th-cam.com/video/wcIRPqTR3Kc/w-d-xo.htmlm50s) where I had shown 32 being removed. Node 34 would be the new left child of node 40 (and node 40 would be the parent of node 34). Does that make sense?

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

      Yeah! Now I see it clearly! Thanks

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

    Thank you soooooo muuuuuuch.

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

      I'm glad this was helpful for you!

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

      colleen lewis you have no idea. I passed my course because of your video. I cant even thank you enough.

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

    Thanks Colleen..
    So so much

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

    Awesome simple video!

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

    Super good explanation

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

    What an awesome explanation! Thank you a lot :)

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

    Amazing explanation thank you!

  • @abdallhghanem708
    @abdallhghanem708 9 ปีที่แล้ว

    Very Very Very effective thank you so much

  • @danielgrindrod9526
    @danielgrindrod9526 8 ปีที่แล้ว

    Brilliant video, thanks!

  • @AlivHasan
    @AlivHasan 9 ปีที่แล้ว

    awesome..it helped a lot...lucid explanation

  • @halluciongen3000
    @halluciongen3000 10 ปีที่แล้ว +1

    This was really good, thank you!

  • @shadownirvana5044
    @shadownirvana5044 9 ปีที่แล้ว

    Good explaination. Thanks!

  • @mikek.2703
    @mikek.2703 8 ปีที่แล้ว

    Thanks a lot for your help.

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

    awesome explanation

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

    Amazing video! Thank you

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

    short and accurate thanks alot

  • @AgentSubZero4
    @AgentSubZero4 8 ปีที่แล้ว

    thanks.. the best.. helped me alot..

  • @saddamhossain2171
    @saddamhossain2171 8 ปีที่แล้ว

    Nicely explained!!!.... subscribed... :)

  • @cKEntertainment
    @cKEntertainment 2 หลายเดือนก่อน +1

    Herrroooo from The Odin Project

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

    This helped a lot thank you. I did something wholly different than this.

  • @randyisme
    @randyisme 8 ปีที่แล้ว

    Thanks for the video!

  • @tanmoyt9391
    @tanmoyt9391 9 ปีที่แล้ว

    Thanks...this was very helpful

  • @twinkly666
    @twinkly666 9 ปีที่แล้ว

    very clear. thanks a lot

  • @mohammadusman3828
    @mohammadusman3828 8 ปีที่แล้ว

    ma'am you are just perfect :*

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

    Holy shit that was perfectly explained. Thank you.

  • @DavidKhudaverdyan
    @DavidKhudaverdyan 9 ปีที่แล้ว

    Thank you for your video.

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

    if I implement the remove method recursively, how can I remove a leaf ? Since by the time the recursion gets to the leaf, we lose access to the parent node

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

    Thank you very much.

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

    i just love this

  • @AzatDzhanybekov
    @AzatDzhanybekov 9 ปีที่แล้ว

    Good Explanation! Thanx!

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

    awesome video !

  • @LTM4620
    @LTM4620 9 ปีที่แล้ว

    Nice explanation :) like it ..

  • @praneethaluru2601
    @praneethaluru2601 8 ปีที่แล้ว

    thank you very much mam ...

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

    Tried to plot these numbers into a visualizer, and on deletion it selected 65 instead of 75. OP is this a self-balancing tree? WTF?

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

      To all future students:
      There are two ways to do this. You either select the maximum value from left side, or the minimum value from right side.
      Colleen selects 75 here, but most visualizers will select 65 since it's the maximum from left side.
      Hence my confusion above

  • @somiashobo8359
    @somiashobo8359 8 ปีที่แล้ว

    it helped thanx alot

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

    Thank you!! You're amazing:)

  • @SubarnoPal
    @SubarnoPal 10 ปีที่แล้ว

    Helpfull ... thnks

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

    Thank you professor! You helped me a lot! \o/

  • @TheThunderSpirit
    @TheThunderSpirit 8 ปีที่แล้ว +6

    what happens after deleting 32?
    what happens to 34 and 36?

    • @ColleenMLewis
      @ColleenMLewis  8 ปีที่แล้ว +5

      If we start with the tree at the very beginning of the video and delete 32, then we're deleting a node that has only one child. That's a simpler case (than if it had two children) and we can just make 40's left child be 34, which effectively removes 32. We just keep the same connection between 34 and 36, because in general we try to avoid restructuring binary search trees. Does that help?

    • @TheThunderSpirit
      @TheThunderSpirit 8 ปีที่แล้ว

      colleen lewis yes. so while deleting 30 why do u choose to swap 32 in place of 30?
      we can choose 20. that can work too?
      while deleting 70 we can replace by 65. which is next smaller that too maintain tree property.? does it always have to be next bigger element?

    • @ColleenMLewis
      @ColleenMLewis  8 ปีที่แล้ว +2

      That's just a convention for what you do when you delete a node with two children. I have chosen to use the next biggest rather than the next smallest, but either would work just fine. Does that make sense?

    • @TheThunderSpirit
      @TheThunderSpirit 8 ปีที่แล้ว

      colleen lewis yes. now the main question is how to decide which one choose to swap so that least cost is inccured.
      does it also work for equal keys?

    • @ColleenMLewis
      @ColleenMLewis  8 ปีที่แล้ว

      Two answers:
      Usually we'd just implement either the next biggest or the next smallest. Not both.
      We never have duplicate keys in our BST - so that never comes up. If we try to add a key that is already in the BST, we would just replace the old value associated with that key.

  • @HemanthKumar-sq7mq
    @HemanthKumar-sq7mq 10 ปีที่แล้ว +2

    thanks a lot

  • @GiuseppeMiragliotta95
    @GiuseppeMiragliotta95 9 ปีที่แล้ว

    thank you from italy :)

  • @shashankk197
    @shashankk197 8 ปีที่แล้ว

    Is there a similar explanation on red black trees insertion and deletion.....help much appreciated :)