Lecture 5: Binary Search Trees, BST Sort

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 297

  • @freedomchinaify
    @freedomchinaify 5 років тому +175

    binary search tree structure: 26:06 - 27:33
    insert 42 (k=3) to BST: 27:43 - 30:16
    find.min(): 35:18 - 36:07
    Augment BST: 37:59 - 48:35

  • @cachegrk
    @cachegrk 11 років тому +158

    Wow! Never seen someone explaining why we need BST this clearly. The approach was very nice discussing all data structures for runway problem and filtering out one by one.

    • @supastar25
      @supastar25 4 роки тому +5

      Explaining it using a real world problem example made it easy to follow..great lecture.

  • @sergeykholkhunov1888
    @sergeykholkhunov1888 3 роки тому +15

    01:50 motivation behind BST
    08:30 shoot down known data structures
    21:35 BST introduction
    26:00 example BST insert
    35:00 other BST operations
    36:45 augmented BST example
    45:30 example compute rank t (How many planes are scheduled to plane in time less than or equal t)

  • @johnchen9038
    @johnchen9038 8 років тому +24

    For peeps that may be initially confused by why insertion was constant for the unsorted array, and linear for sorted array, it's because in an unsorted array of [4, 2, 1, 6], if you want to insert 3, you simply add it to the end, so that's constant time. Then, you have to iterate through the array to see which number is next to go on the runway (array.min) which costs linear time.
    In the sorted array, using the binary search method, you can find where to insert your new number in log time, but the act of inserting it costs linear time because the worst case scenario is that you have to add it in the very beginning, which will shift every element over one space. For example, [2, 3, 4]. Inserting 1 to the very front will require the shifting of all 3 elements.

    • @suyashmuley9096
      @suyashmuley9096 8 років тому +1

      Are you the same as the CEO of Blackberry- John Chen?

    • @manikanth2166
      @manikanth2166 7 років тому

      Why to shift all the elements? can't we add the element at start and do a block copy since it is a contiguous block of memory

    • @alexandrepereira2358
      @alexandrepereira2358 7 років тому +2

      Block copy is still linear. Imagine a block copy of a billion elements.

    • @crittercel
      @crittercel 5 років тому

      @@manikanth2166 because adding the element at the start forces you to move all the other elements in the array, thus adding more time to the time complexity.

  • @lukewright7265
    @lukewright7265 10 років тому +97

    This guy is an incredible teacher. Was having trouble understanding heaps and BST until I watched these lectures.

    • @nick18303
      @nick18303 4 роки тому

      Luke Wright same haha

    • @alexandrugheorghe5610
      @alexandrugheorghe5610 4 роки тому +2

      yep, he's doing a good job at keeping it simple at the level of the datastructure and simply walk you through it by using notation and help you visualize how the operations affect the datastructure and it's mental model representation :)

    • @marsille0986
      @marsille0986 Рік тому

      u are a smart guy for even understanding a litlle bit im so lost how do u guys even sit and listen to this type of stuff my brain would be fried

    • @I_am_nooh
      @I_am_nooh 11 місяців тому

      @@marsille0986 The lecture is extremely easy as a whole, just carry on and finish the video and you'll be able to put the pieces together. In other words, everything makes sense as a whole. While doing these MIT lectures, I often found myself blank for 10-15 minutes of a given portion of a lecture. But everytime I bit the bullet and hung on, I was able to understand everything. If not, you can search for particular keywords to understand bits and pieces.
      Hope that helps!

    • @marsille0986
      @marsille0986 11 місяців тому

      @@I_am_nooh thank you for this reply but i dropped out 6 month ago im now a successful drug dealer

  • @jeromesmith5382
    @jeromesmith5382 3 роки тому +5

    This is so unbelievably good, what a great teacher. Perfect for preparing for my oral exam in algorithms and data structures

  • @Jason_Lucero
    @Jason_Lucero 3 роки тому +11

    This course is good for sitting on the couch and listening to I love it

  • @dskinnerify
    @dskinnerify 7 років тому +6

    Thank you for actually showing and applying the math taught in other courses to solve CS problems. It REALLY helps.

  • @Nestorghh
    @Nestorghh 9 років тому +58

    Thank you for this lecture. This Professor is so easy to follow and understand.

    • @redhotbits
      @redhotbits 9 років тому +3

      ive seen better but ok

    • @kebman
      @kebman 8 років тому +9

      +Lazar Otasevic ive got a million bucks but ok

    • @freddyace1993
      @freddyace1993 8 років тому +1

      +kebman this donut is pretty good.

    • @kebman
      @kebman 8 років тому +2

      Freddy Acevedo I like pizza

    • @freddyace1993
      @freddyace1993 8 років тому

      That's certainly not my intent.

  • @rptechplex
    @rptechplex 10 років тому +15

    Liked his way of filtering out other options. Thanks.

  • @netoskin
    @netoskin Рік тому

    I love Srini lectures he is a funny guy but also explains everything to give you an oppottunity to figure things out yourself and I find that amazing

  • @folkloren1574
    @folkloren1574 4 роки тому +1

    This professor is one of my favorite lecturers. They cover the material in an engaging, concise way.

  • @aadishjain6838
    @aadishjain6838 5 років тому +128

    2019 -> still jamming on this

    • @jeury3012
      @jeury3012 4 роки тому +9

      2020 -> still jamming on this

    • @w1d3r75
      @w1d3r75 4 роки тому +1

      Data structures will last for ever

    • @peasant12345
      @peasant12345 3 роки тому +3

      2021 -> still jamming on this

    • @Jason_Lucero
      @Jason_Lucero 3 роки тому +2

      Ik, I just rewatch these instead of netflix

    • @hughe29
      @hughe29 5 місяців тому

      2024 here!

  • @李愚-f7j
    @李愚-f7j 6 років тому +5

    43:00 good strategy!
    first do the regular insert if fails done
    else: continue to do tree augmentation

  • @aouldah
    @aouldah 7 років тому +4

    He's the true God of algorithms and data structures.

  • @sandipanmajhi2770
    @sandipanmajhi2770 5 років тому +168

    does anyone feel that the dusters in MIT are way too good :D

    • @pubgplayer1720
      @pubgplayer1720 4 роки тому +8

      And Hagoromo chalk too

    • @ndeoligence8
      @ndeoligence8 3 роки тому +5

      I hear their supplier did a Duster Design & Manufacturing PhD at MIT. So no wonder

    • @tanvishinde805
      @tanvishinde805 3 роки тому

      @@ndeoligence8 are you serious?

    • @ndeoligence8
      @ndeoligence8 3 роки тому +1

      @@tanvishinde805 Of course not - I doubt such a PhD exists!

    • @tanvishinde805
      @tanvishinde805 3 роки тому +1

      @@ndeoligence8 hahaaaa

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому +2

    This series and Sedgewick's are so good.

  • @tinaareddy
    @tinaareddy 4 роки тому +20

    2020 and I feel like I have finally found gold!

  • @dhruv_aditya
    @dhruv_aditya 3 роки тому

    the way of teaching is really amazing...

  • @JohnTosun
    @JohnTosun 3 роки тому

    He is a beast. Bst cannot explain better than this. Im suprised people asked super easy questions around min 32 that there were harder questions to ask

  • @MrJackyieman
    @MrJackyieman 6 років тому +2

    i really like hims teaching. great inspiration and explanation

  • @mushroomepic6727
    @mushroomepic6727 7 років тому +39

    BST starts at 21:46

    • @somebody4679
      @somebody4679 6 років тому +2

      The most underrated comment on this video.

    • @TheLakers987654321
      @TheLakers987654321 6 років тому +2

      THANK YOU I WAS LOOKING FOR THIS COMMENT

    • @TrabelsiMarwen
      @TrabelsiMarwen 6 років тому +2

      indeed this is a bad teacher, you get bored easily, he not talking about the improtant things... Get fired please!

    • @christinehill4491
      @christinehill4491 5 років тому +8

      @@TrabelsiMarwen You have got to be kidding. He is explaining why you use BSTs vs. other data structures. It is brilliant in that it seems so basic because he explains it so well, but then all of these concepts become very, very clear.

    • @arunavaghatak8614
      @arunavaghatak8614 5 років тому +8

      @@TrabelsiMarwen Knowing why we should use BST is as important as being able to use BST. He is a good teacher an is really talking about important things.

  • @MasterChief.42
    @MasterChief.42 10 років тому +147

    That guy on the left is eating something in every lecture! :P

  • @kianreddy1295
    @kianreddy1295 4 роки тому +2

    MIT Please HD Lectures... that's the only thing missing from these...😭😭😭😭😭😭❤❤❤❤

  • @websoftwaredeveloperijtiha3093
    @websoftwaredeveloperijtiha3093 2 роки тому +1

    It's so cool that these top schools release courses like this one online free of charge. I may not get a chance to go to MIT

  • @shubhamgawali8030
    @shubhamgawali8030 5 років тому

    one of them asks at the end of the lecture what is the value of k in a problem. but the professor does not panic at all again explain the problem what is the meaning of 'k' in the problem very nice professor.

  • @projectdocx4661
    @projectdocx4661 5 років тому +1

    How about using a Set? Insertion/LookUp/Deletion all are O(1). Yes, that's an "expected case". But still, it needs to be considered and discussed.

  • @noypi613
    @noypi613 10 років тому +96

    that subliminal Nintendo ds ad placement tho

  • @qiguosun129
    @qiguosun129 2 роки тому

    He is a Fabulous teacher!

  • @AbhishekSrivastava_ab
    @AbhishekSrivastava_ab 5 років тому

    I knew what BST in general were. I just came here to revise. But it is today I understood why BST exist in the first place and how they evolved and what problems do they solve which is not possble through other data structures in best time..

  • @tabularasa0606
    @tabularasa0606 11 років тому +1

    There's a problem with the invariant, nodes with key(x) equal can be in both left and right subtrees. You don't want that, you want to choose either.

    • @nipasy
      @nipasy Рік тому

      33:18 mentions duplicate values with a multiset. However, two 46 values would have to be differentiated, say, as 46a and 46b. But the nodes themselves would be unique.

  • @KUSUMAKARSHUKLA
    @KUSUMAKARSHUKLA 4 роки тому

    I love this professor! He is so clear and deep!

  • @WayneWBishop
    @WayneWBishop 10 років тому

    Fantastic teacher! It's so great to have access to this content. At 31:17 he mentions there's no constraints to a BST. Other than the "left / right" rules one should also ensure all values are unique.

    • @zeronothinghere9334
      @zeronothinghere9334 4 роки тому

      It's not strictly necessary, but it's a common augmentation to add.

  • @chaitanaya677
    @chaitanaya677 8 років тому +45

    came here from iit Bombay data structures class. God, what a relief

    • @harshilpatel2115
      @harshilpatel2115 5 років тому +3

      Haha good joke

    • @ujjalm007
      @ujjalm007 3 роки тому

      I am not sure why IIT free lectures are bearing

  • @the.rajkumar.sawant
    @the.rajkumar.sawant 3 роки тому

    Still this is best course on UA-cam in Algorithms 🙃🙃🙃

  • @ALEEMKHAWAR1
    @ALEEMKHAWAR1 2 роки тому

    wow ,how much amazing teacher you are

  • @vinaysingh-nc1jk
    @vinaysingh-nc1jk 11 років тому

    mr srini devadas thnk u for coming to my cllg ..(AIT PUNE).india is proud of u :)

  • @mrinal2100
    @mrinal2100 4 роки тому

    check out 50:10 why he is adding extra weight 2 to subtree 46, even when we are navigating to the right side of the tree.

    • @asero82.
      @asero82. 4 роки тому

      That's because 46 and all of his left subtree are before 79, as well 79's left subtree is also before itself.

  • @rajjain7628
    @rajjain7628 4 роки тому +1

    So far enjoying dsa, it's cool. Implementation part and code trivialities are little rough though. Lecture 5..bam

  • @DrRobrez
    @DrRobrez 8 років тому +1

    nice lecture but if there was just integer precision, I'd implement it as a fixed size array or 2d array runways by minutes for a size complexity of just n x 1400 and a constant time complexity

  • @sairajk19
    @sairajk19 4 роки тому +1

    2020, still beneficial!

  • @seblewongelashenafi3417
    @seblewongelashenafi3417 6 років тому +1

    To get Binary search tree searching run time complexity logn .the binary tree should be balanced search tree

  • @nikhithareddy8539
    @nikhithareddy8539 4 роки тому +2

    Indebited for your lecture sir!!

  • @yannyt4909
    @yannyt4909 11 років тому +3

    I like this lecturer a lot :)

  • @universal4334
    @universal4334 4 роки тому

    Brilliant intro to BST ....

  • @ngorngorcalvin9705
    @ngorngorcalvin9705 10 років тому

    Good work of technology in the positive way, keep cool

  • @DanielPage
    @DanielPage 11 років тому

    Correct. The right subtree should be key(x)

  • @rohitbhat1985
    @rohitbhat1985 4 роки тому +1

    Thank you. This is such a good explanation! And makes it seem so intuitive.

  • @fuzzychang1676
    @fuzzychang1676 4 роки тому +9

    "I did not lie" hahahaha this instructor is so cute

  • @purveshthakre8298
    @purveshthakre8298 6 років тому +11

    It's 2018, don't worry.

  • @princehodonou5595
    @princehodonou5595 5 років тому +1

    Bro this teacher is amazing!

  • @ajaygunalan1995
    @ajaygunalan1995 2 роки тому

    BST -> Binary Search (Divide & Conquer) .

  • @jovanny253
    @jovanny253 3 роки тому +2

    So that’s what a classroom looks like. I was starting to forget.

  • @NOCRealEstate
    @NOCRealEstate 11 років тому

    This video answered a lot of my questions.

  • @Mythul
    @Mythul 10 років тому

    Best course ever.

  • @lockersrandom6161
    @lockersrandom6161 4 роки тому

    Thank you MIT.

  • @olorunsogojohn1049
    @olorunsogojohn1049 4 роки тому

    Still helpful in 2020

  • @MathStatsWonders
    @MathStatsWonders 4 роки тому

    Easy way to understand what BST is good for: its good to find the closest existing point to a given new point

  • @TheQuancy
    @TheQuancy 4 роки тому +2

    Gotta watch these. My algorithms class has, on average, cancelled one class a week. We only show up 2x a week, and we r 2 weeks before midterms

    • @alexandrugheorghe5610
      @alexandrugheorghe5610 4 роки тому

      auch, hope you're making progress...
      there's also programiz website - it's very good as well if you want to take a look at it
      i usually combine programiz with MIT 6.006 and Rivest book

  • @mujaheedisahabdullahi4206
    @mujaheedisahabdullahi4206 8 років тому +1

    Thanks alot for this tutorial, can we get for questions and answers

  • @ShubhamSinghYoutube
    @ShubhamSinghYoutube 4 роки тому +1

    Is this Sophomore year content ?

  • @lionkor98
    @lionkor98 4 роки тому

    What a brilliant lecture!

  • @PamirTea
    @PamirTea 7 років тому +1

    Great lecture.

  • @pankajwillis
    @pankajwillis 7 років тому

    Great lecture! Lots of fun watching

  • @happy_labs
    @happy_labs 6 років тому +1

    Fantastic teaching, thanks from Australia to MIT!

  • @DominicVictoria
    @DominicVictoria 3 роки тому

    Wouldn't changing pointers around be slower than just creating an optimized dynamic array?

  • @kapil_ag__
    @kapil_ag__ 3 роки тому

    on 15:36 he said "So the list does one thing right,
    but doesn't do the other thing right.
    The array does a couple things right,
    but doesn't do the shifting right."
    so what is the difference between array and a list here. does he mean a sorted list by array..???

  • @waqarbinwaqas9537
    @waqarbinwaqas9537 4 роки тому

    Going through the questions to find out if you could get a cushion

  • @Gukslaven
    @Gukslaven 7 років тому +1

    Amazing lecture; great example problem to teach BST with. Loved it.

  • @anujkhare3815
    @anujkhare3815 4 роки тому

    i do not have much data strucures knowledge like queue stack and everythinhg. so should i first learn them from somewhere and then come here or im okay to learn these first????

  • @wonjaehwang7670
    @wonjaehwang7670 5 років тому

    At 24:50, why does the Professor say use >= for the sub trees? I was read that each key should be unique. So shouldn't it be just > || < not >= ||

  • @zhegemingzigouchang
    @zhegemingzigouchang 7 років тому

    question about BST invariant at 24:45, shouldn't it be y x on the right?

  • @kiranbhatiya1747
    @kiranbhatiya1747 7 років тому +1

    Very good teacher he explain clearly
    And my college i don't know when what happen thank you sir

  • @arunteltia7888
    @arunteltia7888 5 років тому +2

    i have a question for getting the nodes of a subtree we need to go to each and every node atleast one time then whats the point if we solve the question after wards in logn

    • @arunteltia7888
      @arunteltia7888 5 років тому

      @@devgumdrop3700 i need a copy and pen to write the info for better understanding but ya this will help thank you 🤗 for a detailed answer

    • @divyanshusaxena148
      @divyanshusaxena148 4 роки тому

      @@devgumdrop3700 Thank you man! really helped me.

  • @Rahul-lg1nw
    @Rahul-lg1nw 4 роки тому

    I don't get.. what happened with 45? 31:22

  • @weizhixie9678
    @weizhixie9678 5 років тому

    Great courses! I just couldn't understand why there are people give it a thumb down. By accidentally, I guess.

  • @georgetannous5162
    @georgetannous5162 4 роки тому +2

    2020 -> still jamming on this

  • @hakanahlstrom8310
    @hakanahlstrom8310 6 років тому

    I dont quite understand: at 20:57 the professor expresses that the algorithm is good, but not good enough. and that the problem with the alg is that the insertion is now fast enough. he says that we must find a solution for faster insertion.
    I dont see him providing the solution. the rest of the lecture from that point is a description on how to find place to be inserted (which we already know how to do?) ????

  • @mananhora3655
    @mananhora3655 9 років тому +1

    Best Professor ever.

  • @cusatankur296
    @cusatankur296 2 роки тому

    Where to find the code for implementation ?

  • @nesan787
    @nesan787 4 роки тому

    I don't understand why they don't replace the dusters with modern white board.

  • @markhaus
    @markhaus 8 років тому +4

    Where are the lecture notes that keep getting referenced?

    • @mitocw
      @mitocw  8 років тому +15

      The lecture notes and other materials are available on MIT OpenCourseWare at ocw.mit.edu/6-006F11. They are with each video in a tab labelled Lecture Notes.

  • @youtwothirtyfive
    @youtwothirtyfive 8 років тому +2

    At around 20:00 the subs say "min/max heap of i" several times, but it should be "min/max heapify"

  • @DanielPage
    @DanielPage 11 років тому +1

    Jeez louise! You shouldn't be teaching this kind of stuff with a power point slide presentation.

  • @BlairDavidson1981
    @BlairDavidson1981 11 років тому

    Really good video

  • @nicholaskong1673
    @nicholaskong1673 3 роки тому

    taking data structures in the fall. Getting a 2 month head start woots

  • @jingjinw9068
    @jingjinw9068 4 роки тому

    In note page 2 'can we do better', it said for sorted list "appending and sorting takes theta(n lgn) time. Why is that?

    • @alexandrugheorghe5610
      @alexandrugheorghe5610 4 роки тому

      lists have pointers - for theta (not big O), your average case would be that you'll always find a mid point somewhere (where mid point here means no extremes: at either ends depending if it's a doubly linked list or not)
      this means, that there'll always be an element k that is s

  • @陈江涛-r6z
    @陈江涛-r6z 5 років тому

    Can someone tell me why the BST method is more efficient? I know the BST insert have h complexity but before that, shouldn't we build this BST model first? Adding to this, that insertion costs a lot of time.

  • @DaxXx988
    @DaxXx988 10 років тому +1

    nice augmenting technique

  • @kress89
    @kress89 6 років тому

    my question is if i want too add one data to sorted binary tree, the only rule is that left side is for minimum range data,and right one is for maximum data,and i follow tree carefully,so in real code i will just adding plus 1 until i am finsihed?

  • @unabshakir9647
    @unabshakir9647 3 роки тому

    21:39 BSTs

  • @casamir1
    @casamir1 7 років тому

    This is super helpful

  • @samyakjain2084
    @samyakjain2084 4 роки тому +1

    Why can't we use binary search in the list?

    • @keithzhu6288
      @keithzhu6288 4 роки тому

      Short ans: You can, but it is just inefficient and defeats the purpose of a binary search and also your list must be sorted.
      Long ans: Assuming your question is regarding to a LinkedList. (whether singly or doubly) Due to the fact that memory allocation for a LinkedList is dynamic and non-contiguous, a search operation is unlike arrays where its elements can be accessed in constant time O(1) complexity with random access. Performing a single binary search in a linkedlist requires you to traverse each node from the head to the mid node. Now you can imagine doing multiple searches with a binary search algorithm.

    • @samyakjain2084
      @samyakjain2084 4 роки тому

      @@keithzhu6288 Thanks a lot, i got it. But I have one more doubt. In the python list, if we want to go to the middle element, will it take O(1) time or O(n) time, i mean do Python list work as double linked list?

    • @keithzhu6288
      @keithzhu6288 4 роки тому +1

      ​@@samyakjain2084 I don't expertise in Python, but according to my research (stackoverflow.com/questions/3917574/how-is-pythons-list-implemented) Python lists are actually just dynamic arrays, equivalent to Java ArrayLists. So other than dynamically expanding the size to store more elements, indexing would be the same as an array. Official Python 3 documentation reference: docs.python.org/3/faq/design.html#how-are-lists-implemented-in-cpython

  • @Shebu
    @Shebu 6 років тому

    What if two nodes have same values?Will it goto right or left?

  • @JCArtuso
    @JCArtuso 3 роки тому

    Thanks a lot for sharing!

  • @fartzy
    @fartzy 6 років тому

    Why didnt she get a cushion?

  • @serioussam2071
    @serioussam2071 5 років тому

    wheres part 2 of this video that the lecturer is talking about?

  • @RussTeeTrombone
    @RussTeeTrombone 5 років тому

    Is deletion covered here? Did i miss it?

  • @jhonyiigp
    @jhonyiigp 6 років тому

    Awesome class! Thank you!

  • @Chirag-mb2yd
    @Chirag-mb2yd 4 роки тому

    The guy sounds like a genius Michael Scott