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.
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)
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.
@@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.
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 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!
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
@@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.
@@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.
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.
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..
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.
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.
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
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
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..???
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????
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
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?) ????
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.
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
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.
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?
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.
@@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?
@@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
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
These are the best youtube comments. Thank you.
Thank you!
H==level
Thanks
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.
Explaining it using a real world problem example made it easy to follow..great lecture.
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)
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.
Are you the same as the CEO of Blackberry- John Chen?
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
Block copy is still linear. Imagine a block copy of a billion elements.
@@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.
This guy is an incredible teacher. Was having trouble understanding heaps and BST until I watched these lectures.
Luke Wright same haha
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 :)
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
@@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!
@@I_am_nooh thank you for this reply but i dropped out 6 month ago im now a successful drug dealer
This is so unbelievably good, what a great teacher. Perfect for preparing for my oral exam in algorithms and data structures
This course is good for sitting on the couch and listening to I love it
Thank you for actually showing and applying the math taught in other courses to solve CS problems. It REALLY helps.
Thank you for this lecture. This Professor is so easy to follow and understand.
ive seen better but ok
+Lazar Otasevic ive got a million bucks but ok
+kebman this donut is pretty good.
Freddy Acevedo I like pizza
That's certainly not my intent.
Liked his way of filtering out other options. Thanks.
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
This professor is one of my favorite lecturers. They cover the material in an engaging, concise way.
2019 -> still jamming on this
2020 -> still jamming on this
Data structures will last for ever
2021 -> still jamming on this
Ik, I just rewatch these instead of netflix
2024 here!
43:00 good strategy!
first do the regular insert if fails done
else: continue to do tree augmentation
He's the true God of algorithms and data structures.
does anyone feel that the dusters in MIT are way too good :D
And Hagoromo chalk too
I hear their supplier did a Duster Design & Manufacturing PhD at MIT. So no wonder
@@ndeoligence8 are you serious?
@@tanvishinde805 Of course not - I doubt such a PhD exists!
@@ndeoligence8 hahaaaa
This series and Sedgewick's are so good.
2020 and I feel like I have finally found gold!
so true
@@thienngan2534 +1
the way of teaching is really amazing...
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
they are learning for the first time !!
i really like hims teaching. great inspiration and explanation
BST starts at 21:46
The most underrated comment on this video.
THANK YOU I WAS LOOKING FOR THIS COMMENT
indeed this is a bad teacher, you get bored easily, he not talking about the improtant things... Get fired please!
@@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.
@@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.
That guy on the left is eating something in every lecture! :P
Gaurav Goyal who care, mind your own business, poop
GOOD Observation
And you are watching him instead of listening to him 😂
american culture !!
he specifically chose to eat at the lecture lol.
MIT Please HD Lectures... that's the only thing missing from these...😭😭😭😭😭😭❤❤❤❤
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
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.
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.
that subliminal Nintendo ds ad placement tho
haha, you mean the cloth?
yep
that too in the first minute :3
He is a Fabulous teacher!
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..
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.
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.
I love this professor! He is so clear and deep!
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.
It's not strictly necessary, but it's a common augmentation to add.
came here from iit Bombay data structures class. God, what a relief
Haha good joke
I am not sure why IIT free lectures are bearing
Still this is best course on UA-cam in Algorithms 🙃🙃🙃
wow ,how much amazing teacher you are
mr srini devadas thnk u for coming to my cllg ..(AIT PUNE).india is proud of u :)
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.
That's because 46 and all of his left subtree are before 79, as well 79's left subtree is also before itself.
So far enjoying dsa, it's cool. Implementation part and code trivialities are little rough though. Lecture 5..bam
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
2020, still beneficial!
To get Binary search tree searching run time complexity logn .the binary tree should be balanced search tree
Indebited for your lecture sir!!
I like this lecturer a lot :)
Brilliant intro to BST ....
Good work of technology in the positive way, keep cool
Correct. The right subtree should be key(x)
Thank you. This is such a good explanation! And makes it seem so intuitive.
"I did not lie" hahahaha this instructor is so cute
It's 2018, don't worry.
Bro this teacher is amazing!
BST -> Binary Search (Divide & Conquer) .
So that’s what a classroom looks like. I was starting to forget.
rittttttttttt
This video answered a lot of my questions.
Best course ever.
Thank you MIT.
Still helpful in 2020
Easy way to understand what BST is good for: its good to find the closest existing point to a given new point
find and insert*
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
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
Thanks alot for this tutorial, can we get for questions and answers
Is this Sophomore year content ?
What a brilliant lecture!
Great lecture.
Great lecture! Lots of fun watching
Fantastic teaching, thanks from Australia to MIT!
Wouldn't changing pointers around be slower than just creating an optimized dynamic array?
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..???
Going through the questions to find out if you could get a cushion
Amazing lecture; great example problem to teach BST with. Loved it.
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????
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 >= ||
question about BST invariant at 24:45, shouldn't it be y x on the right?
Very good teacher he explain clearly
And my college i don't know when what happen thank you sir
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
@@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
@@devgumdrop3700 Thank you man! really helped me.
I don't get.. what happened with 45? 31:22
Great courses! I just couldn't understand why there are people give it a thumb down. By accidentally, I guess.
2020 -> still jamming on this
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?) ????
Best Professor ever.
Where to find the code for implementation ?
I don't understand why they don't replace the dusters with modern white board.
Where are the lecture notes that keep getting referenced?
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.
At around 20:00 the subs say "min/max heap of i" several times, but it should be "min/max heapify"
Jeez louise! You shouldn't be teaching this kind of stuff with a power point slide presentation.
Really good video
taking data structures in the fall. Getting a 2 month head start woots
In note page 2 'can we do better', it said for sorted list "appending and sorting takes theta(n lgn) time. Why is that?
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
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.
nice augmenting technique
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?
21:39 BSTs
This is super helpful
Why can't we use binary search in the list?
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.
@@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?
@@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
What if two nodes have same values?Will it goto right or left?
Thanks a lot for sharing!
Why didnt she get a cushion?
wheres part 2 of this video that the lecturer is talking about?
Is deletion covered here? Did i miss it?
Awesome class! Thank you!
The guy sounds like a genius Michael Scott