Тёмный

Lecture 5: Binary Search Trees, BST Sort 

MIT OpenCourseWare
Подписаться 5 млн
Просмотров 611 тыс.
50% 1

MIT 6.006 Introduction to Algorithms, Fall 2011
View the complete course: ocw.mit.edu/6-006F11
Instructor: Srini Devadas
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu

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

 

27 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 297   
@freedomchinaify
@freedomchinaify 5 лет назад
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
@AnanyaDasAvi
@AnanyaDasAvi 4 года назад
These are the best youtube comments. Thank you.
@hortsss
@hortsss 4 года назад
Thank you!
@hamzariaz9700
@hamzariaz9700 3 года назад
H==level
@data-dynamo-guy
@data-dynamo-guy Год назад
Thanks
@cachegrk
@cachegrk 10 лет назад
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 года назад
Explaining it using a real world problem example made it easy to follow..great lecture.
@sergeykholkhunov1888
@sergeykholkhunov1888 3 года назад
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)
@lukewright7265
@lukewright7265 10 лет назад
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 3 года назад
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 8 месяцев назад
@@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 8 месяцев назад
@@I_am_nooh thank you for this reply but i dropped out 6 month ago im now a successful drug dealer
@johnchen9038
@johnchen9038 8 лет назад
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 7 лет назад
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 лет назад
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.
@dskinnerify
@dskinnerify 6 лет назад
Thank you for actually showing and applying the math taught in other courses to solve CS problems. It REALLY helps.
@folkloren1574
@folkloren1574 3 года назад
This professor is one of my favorite lecturers. They cover the material in an engaging, concise way.
@jeromesmith5382
@jeromesmith5382 3 года назад
This is so unbelievably good, what a great teacher. Perfect for preparing for my oral exam in algorithms and data structures
@aadishjain6838
@aadishjain6838 5 лет назад
2019 -> still jamming on this
@jeury3012
@jeury3012 3 года назад
2020 -> still jamming on this
@w1d3r75
@w1d3r75 3 года назад
Data structures will last for ever
@peasant12345
@peasant12345 3 года назад
2021 -> still jamming on this
@Jason_Lucero
@Jason_Lucero 3 года назад
Ik, I just rewatch these instead of netflix
@hughe29
@hughe29 2 месяца назад
2024 here!
@rptechplex
@rptechplex 10 лет назад
Liked his way of filtering out other options. Thanks.
@Jason_Lucero
@Jason_Lucero 3 года назад
This course is good for sitting on the couch and listening to I love it
@user-hs7qg5tt8t
@user-hs7qg5tt8t 6 лет назад
43:00 good strategy! first do the regular insert if fails done else: continue to do tree augmentation
@Nestorghh
@Nestorghh 9 лет назад
Thank you for this lecture. This Professor is so easy to follow and understand.
@redhotbits
@redhotbits 8 лет назад
ive seen better but ok
@kebman
@kebman 8 лет назад
+Lazar Otasevic ive got a million bucks but ok
@freddyace1993
@freddyace1993 8 лет назад
+kebman this donut is pretty good.
@kebman
@kebman 8 лет назад
Freddy Acevedo I like pizza
@freddyace1993
@freddyace1993 8 лет назад
That's certainly not my intent.
@sandipanmajhi2770
@sandipanmajhi2770 4 года назад
does anyone feel that the dusters in MIT are way too good :D
@pubgplayer1720
@pubgplayer1720 4 года назад
And Hagoromo chalk too
@ndeoligence8
@ndeoligence8 3 года назад
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 года назад
@@tanvishinde805 Of course not - I doubt such a PhD exists!
@tanvishinde805
@tanvishinde805 3 года назад
@@ndeoligence8 hahaaaa
@rohitbhat1985
@rohitbhat1985 4 года назад
Thank you. This is such a good explanation! And makes it seem so intuitive.
@netoskin
@netoskin 11 месяцев назад
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
@tinaareddy
@tinaareddy 4 года назад
2020 and I feel like I have finally found gold!
@thienngan2534
@thienngan2534 4 года назад
so true
@dragon_warrior_
@dragon_warrior_ 4 года назад
@@thienngan2534 +1
@mattgraves3709
@mattgraves3709 3 года назад
This series and Sedgewick's are so good.
@MrJackyieman
@MrJackyieman 6 лет назад
i really like hims teaching. great inspiration and explanation
@KUSUMAKARSHUKLA
@KUSUMAKARSHUKLA 3 года назад
I love this professor! He is so clear and deep!
@noypi613
@noypi613 9 лет назад
that subliminal Nintendo ds ad placement tho
@yifuliu547
@yifuliu547 7 лет назад
haha, you mean the cloth?
@KaranSingh-ty5xr
@KaranSingh-ty5xr 7 лет назад
yep
@KaranSingh-ty5xr
@KaranSingh-ty5xr 7 лет назад
that too in the first minute :3
@websoftwaredeveloperijtiha3093
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
@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.
@aouldah
@aouldah 6 лет назад
He's the true God of algorithms and data structures.
@pankajwillis
@pankajwillis 7 лет назад
Great lecture! Lots of fun watching
@MasterChief.42
@MasterChief.42 10 лет назад
That guy on the left is eating something in every lecture! :P
@henrykashyap8913
@henrykashyap8913 6 лет назад
Gaurav Goyal who care, mind your own business, poop
@ypww748
@ypww748 5 лет назад
GOOD Observation
@studyonline3236
@studyonline3236 5 лет назад
And you are watching him instead of listening to him 😂
@SoI_JEE_NEET_Physics_Math_IITB
@SoI_JEE_NEET_Physics_Math_IITB 4 года назад
american culture !!
@UltimatePiccolo
@UltimatePiccolo 4 года назад
he specifically chose to eat at the lecture lol.
@kianreddy1295
@kianreddy1295 3 года назад
MIT Please HD Lectures... that's the only thing missing from these...😭😭😭😭😭😭❤❤❤❤
@mujaheedisahabdullahi4206
@mujaheedisahabdullahi4206 8 лет назад
Thanks alot for this tutorial, can we get for questions and answers
@dhruv_aditya
@dhruv_aditya 2 года назад
the way of teaching is really amazing...
@NOCRealEstate
@NOCRealEstate 11 лет назад
This video answered a lot of my questions.
@kress89
@kress89 5 лет назад
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?
@mushroomepic6727
@mushroomepic6727 6 лет назад
BST starts at 21:46
@olzhaszhumabek2034
@olzhaszhumabek2034 6 лет назад
The most underrated comment on this video.
@TheLakers987654321
@TheLakers987654321 5 лет назад
THANK YOU I WAS LOOKING FOR THIS COMMENT
@TrabelsiMarwen
@TrabelsiMarwen 5 лет назад
indeed this is a bad teacher, you get bored easily, he not talking about the improtant things... Get fired please!
@christinehill4491
@christinehill4491 5 лет назад
@@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 лет назад
@@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.
@debarunmukherjee9069
@debarunmukherjee9069 5 лет назад
What if I want to insert same element more than once? Can it be done in bst's or multisets are required for that?
@vinaysingh-nc1jk
@vinaysingh-nc1jk 11 лет назад
mr srini devadas thnk u for coming to my cllg ..(AIT PUNE).india is proud of u :)
@ankurkhurana91
@ankurkhurana91 10 лет назад
Well, how will you check that if there is any element which lies in range t-k or t+k ? As heap have a property by which we can only say with surety that top element is min or max ( minheap/maxheap) but it does not say any other things. We will have to iterate through heap to check for the elements in range.
@yannyt4909
@yannyt4909 10 лет назад
I like this lecturer a lot :)
@zhegemingzigouchang
@zhegemingzigouchang 7 лет назад
question about BST invariant at 24:45, shouldn't it be y x on the right?
@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
@SoI_JEE_NEET_Physics_Math_IITB
@SoI_JEE_NEET_Physics_Math_IITB 3 года назад
they are learning for the first time !!
@princehodonou5595
@princehodonou5595 5 лет назад
Bro this teacher is amazing!
@rajjain7628
@rajjain7628 4 года назад
So far enjoying dsa, it's cool. Implementation part and code trivialities are little rough though. Lecture 5..bam
@Shebu
@Shebu 6 лет назад
What if two nodes have same values?Will it goto right or left?
@projectdocx4661
@projectdocx4661 5 лет назад
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.
@fuzzychang1676
@fuzzychang1676 3 года назад
"I did not lie" hahahaha this instructor is so cute
@user-ot8xv2mj3z
@user-ot8xv2mj3z 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.
@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.
@amritrai3336
@amritrai3336 10 лет назад
cos searching any node takes O(n) times in heap be it max or min
@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 >= ||
@DrRobrez
@DrRobrez 8 лет назад
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
@DominicVictoria
@DominicVictoria 2 года назад
Wouldn't changing pointers around be slower than just creating an optimized dynamic array?
@serioussam2071
@serioussam2071 4 года назад
wheres part 2 of this video that the lecturer is talking about?
@seblewongelashenafi3417
@seblewongelashenafi3417 6 лет назад
To get Binary search tree searching run time complexity logn .the binary tree should be balanced search tree
@tabularasa0606
@tabularasa0606 11 лет назад
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.
@ngorngorcalvin9705
@ngorngorcalvin9705 10 лет назад
Good work of technology in the positive way, keep cool
@Mythul
@Mythul 9 лет назад
Best course ever.
@ALEEMKHAWAR1
@ALEEMKHAWAR1 2 года назад
wow ,how much amazing teacher you are
@waqarbinwaqas9537
@waqarbinwaqas9537 4 года назад
Going through the questions to find out if you could get a cushion
@chaitanaya677
@chaitanaya677 7 лет назад
came here from iit Bombay data structures class. God, what a relief
@harshilpatel2115
@harshilpatel2115 5 лет назад
Haha good joke
@ujjalm007
@ujjalm007 3 года назад
I am not sure why IIT free lectures are bearing
@jhonyiigp
@jhonyiigp 5 лет назад
Awesome class! Thank you!
@PamirTea
@PamirTea 6 лет назад
Great lecture.
@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?) ????
@DanielPage
@DanielPage 11 лет назад
Correct. The right subtree should be key(x)
@lionkor98
@lionkor98 4 года назад
What a brilliant lecture!
@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..
@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.
@markhaus
@markhaus 8 лет назад
Where are the lecture notes that keep getting referenced?
@mitocw
@mitocw 8 лет назад
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.
@anujkhare3815
@anujkhare3815 3 года назад
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????
@the.rajkumar.sawant
@the.rajkumar.sawant 3 года назад
Still this is best course on RU-vid in Algorithms 🙃🙃🙃
@salmonstrikes
@salmonstrikes 7 лет назад
Seems like the terminology in this lecture is '(element or index, key)' while I am used to '(key or index, value)'. What's the standard terminology?
@AMoore-qx6vv
@AMoore-qx6vv 4 года назад
salmonstrikes index key
@weizhixie9678
@weizhixie9678 5 лет назад
Great courses! I just couldn't understand why there are people give it a thumb down. By accidentally, I guess.
@KhantVyas
@KhantVyas 8 лет назад
Can I get its code in java or python
@Gukslaven
@Gukslaven 7 лет назад
Amazing lecture; great example problem to teach BST with. Loved it.
@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..???
@youtwothirtyfive
@youtwothirtyfive 8 лет назад
At around 20:00 the subs say "min/max heap of i" several times, but it should be "min/max heapify"
@RussTeeTrombone
@RussTeeTrombone 4 года назад
Is deletion covered here? Did i miss it?
@qiguosun129
@qiguosun129 2 года назад
He is a Fabulous teacher!
@calvingodfrey7340
@calvingodfrey7340 8 лет назад
Where are the notes for these lectures? On the complete course link in the description I can only find video notes.
@BFdes93
@BFdes93 8 лет назад
If you go to the video lectures page and click on a video link you will find notes for the respective lecture at the bottom of the page. If this is what you mean by video notes then I'm afraid theirs nothing else apart from recitation stuff. The subsequent course on Algorithms (Design and Analysis of Algorithms, 2015) has better notes.
@sushantchoudhary6393
@sushantchoudhary6393 11 лет назад
Could someone explain to me how (at 17:00) we know that the k-minute test takes O(n) time in the case of a min-heap or max-heap ?
@zeronothinghere9334
@zeronothinghere9334 4 года назад
Might be a bit late but I'll comment anyways for other readers. Although the elements in a min-heap / max-heap are ordered, you can't look up specific key values without going through the entire tree. E.g. Min tree: 4 / \ 9 89 / \ / \ 10 90 92 100 Find(90), starting from the root, could be anywhere. You only know that if you go down the values will increase, but there is no difference between going to the left and going to the right. Because of that, you will need to go through almost the entire tree to find a specific element in said tree. In the worst case scenario, that is O(n)
@TheQuancy
@TheQuancy 4 года назад
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 3 года назад
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
@fartzy
@fartzy 5 лет назад
Why didnt she get a cushion?
@sairajk19
@sairajk19 3 года назад
2020, still beneficial!
@jingjinw9068
@jingjinw9068 3 года назад
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 3 года назад
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
@happy_labs
@happy_labs 6 лет назад
Fantastic teaching, thanks from Australia to MIT!
@jovanny253
@jovanny253 3 года назад
So that’s what a classroom looks like. I was starting to forget.
@--ShivaS
@--ShivaS 3 года назад
rittttttttttt
@arunteltia7888
@arunteltia7888 4 года назад
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 4 года назад
@@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 3 года назад
@@devgumdrop3700 Thank you man! really helped me.
@universal4334
@universal4334 3 года назад
Brilliant intro to BST ....
@purveshthakre8298
@purveshthakre8298 6 лет назад
It's 2018, don't worry.
@casamir1
@casamir1 6 лет назад
This is super helpful
@lockersrandom6161
@lockersrandom6161 4 года назад
Thank you MIT.
@doaaal-otoom1450
@doaaal-otoom1450 8 лет назад
why O for search in dictionaries and hashtables are O(n) ? itsO(1) ?
@Qladstone
@Qladstone 7 лет назад
You can search for a particular key in O(1) with high probability, but you cannot search for the existence of keys that meet some criteria in O(1). So let's say you want to search for any key within distance 3 of 50. You can find 50 in O(1) time with high probability. But then you'd miss all the keys between 47 and 53, and if fractions are allowed there are infinitely many such keys to check. The only way then would be to iterate through all the existing keys and match them one by one to the criteria of being distance 3 from 50, which would be O(n).
@nesan787
@nesan787 4 года назад
I don't understand why they don't replace the dusters with modern white board.
@nikhithareddy8539
@nikhithareddy8539 4 года назад
Indebited for your lecture sir!!
@DaxXx988
@DaxXx988 10 лет назад
nice augmenting technique
@cusatankur296
@cusatankur296 2 года назад
Where to find the code for implementation ?
@BlairDavidson1981
@BlairDavidson1981 11 лет назад
Really good video
@kiranbhatiya1747
@kiranbhatiya1747 6 лет назад
Very good teacher he explain clearly And my college i don't know when what happen thank you sir
@bvashisht9283
@bvashisht9283 3 года назад
Great lecture
@Rahul-lg1nw
@Rahul-lg1nw 4 года назад
I don't get.. what happened with 45? 31:22
@200415670
@200415670 7 лет назад
Thank you!
@ayeshaqureshi3319
@ayeshaqureshi3319 7 лет назад
can you plz upload the memory view or dry run of binary searching which read characters not integer
@konstantia33
@konstantia33 7 лет назад
When he says "invariant", what is he talking about? What does that mean?
@lakshaygarg4383
@lakshaygarg4383 7 лет назад
The condition in the algorithm that won't change. For example in max heap, the loop invariant would be: element y is always larger than either of its children
@konstantia33
@konstantia33 7 лет назад
Lakshay Garg Thank you so much for your explanation! Very helpful to me.