MIT 6.006 Introduction to Algorithms, Fall 2011 View the complete course: ocw.mit.edu/6-0... Instructor: Erik Demaine License: Creative Commons BY-NC-SA More information at ocw.mit.edu/terms More courses at ocw.mit.edu
Пікірлер: 319
@sergeykholkhunov18883 жыл бұрын
02:50 height of a tree 06:40 height of a node 10:40 AVL tree 14:40 AVL tree balanced 29:00 AVL insert example 32:45 rotation 40:05 general AVL insert 48:42 AVL sort
@aslon12132 жыл бұрын
@adonis11687 жыл бұрын
all those beautiful mornings ruined for stupid classes whilst i could have listened to this guy at my warm bed with a cup of coffee at my hand. smh
@akntokluoglu28515 жыл бұрын
Mesele dersi dinlemek değil aynı dersi aynı şekilde başka yerde de dinleyebilirsin
@LucasRibeiro-qb8bj3 жыл бұрын
Dude, I'm feeling it right now during the class, my professor is kinda bad
@debasishghoshsays Жыл бұрын
I am thinking the same blud lol
@adityamaheshwari425016 күн бұрын
Literally!!
@DaxXx98810 жыл бұрын
@45:00- it should be LeftRotate(x), not Right
@DeshRaj-sr1hy10 жыл бұрын
Yeah, exactly. I am surprised none of the students pointed that out, even though it's MIT.
@anonymoose_yt10 жыл бұрын
I went back and forth from 45:00 to the part where he did the left-rotate(x) originally and was sure I'd missed something. Thanks for clarifying. MIT's KZbin videos are some of the few with comments that are actually useful :-).
@Qladstone7 жыл бұрын
This needs to be upvoted to the top of the comments section.
@capetaquebratudo6 жыл бұрын
RR means you have to left rotate, its used RR notation because you add a node to the RIGHT twice.
@yawofori-addae38886 жыл бұрын
so is everything else he says after right? with reference to the trees he drew
@rfigueiredo23 күн бұрын
Watching 11 years after the video was released, and still relevant and high quality content, thank you.
@acur6657 жыл бұрын
It blows my mind that people can essentially get a free MIT education from these lectures. Thanks for all the CS lectures & the rest of the online courses! I look forward to absorbing as much knowledge as I can from them!
@Mmspuff5 жыл бұрын
i swear this is the best algorithm lecture you could ever find on internet!! I tried paid courses from other top universities and they are not nearly half as clear as MIT!!!! great MIX of concept and image rather than plain formulas and calculations!!
@shady10809 жыл бұрын
I love this guys, so enthusiastic about what he's teaching!
@keshav8853 жыл бұрын
He’s a child prodigy for no reason
@nomadshubham39073 жыл бұрын
Unlike indian profs 🔥🔥
@莊涵盛-n6u3 жыл бұрын
SO good to see those teachers would take time to encourage students to pause and think what just happened
@qiguosun1292 жыл бұрын
Thank you, Erik Demaine. Your courses are always so clear and intuitive!
@CEngineer20109 жыл бұрын
@44:57 its called a left rotate of x. Not right rotate. He goofed up.
@RC_Cola20209 жыл бұрын
CEngineer2010 This caused me so much confusion! I agree that he reversed them.
@chengweili95169 жыл бұрын
+CEngineer2010 Yes. That's a left rotate of x!
@AmbarMehrotra19 жыл бұрын
+CEngineer2010 Thanks man! I was so confused about that!
@TasdiqueChowdhury9 жыл бұрын
+CEngineer2010 super upvote. this is really important lolol
@user138238 жыл бұрын
+CEngineer2010 when I was a student, I often found mistakes in notes which I made at lectures. And I used to think: "o, the professors are so silly, even me, ordinary student, find stupid mistakes in what they teach". Everything reversed when I started to teach. I cannot explain this exactly, but something like magic happens. When you stand near the board and teach, you sometimes forget trivial things, and do such silly and stupid mistakes that even you cannot understand how that happens. It is not that easy to stand near the board and explain something to other people.
@melvin62285 жыл бұрын
05:42 that jump though #secret_teaching_skills
@codewing10 жыл бұрын
Thanks a lot! Way better then my prof in germany... Amazing how much better motivated ppl. can teach stuff! Keep up the good work!
@bluesystemjackson5 жыл бұрын
Ja, ich glaub die haben da auch ein ganz anderes Verhältnis als in Deutschland. Die Studenten dürfen ihn mit Vornamen anreden (es noch weitere Videos, aus dieser Vorlesungsreihe, wo er mehrfach mit "Erik" angesprochen wird", er redet mit denen Studenten, versucht einen lebendigen Vortrag zu entwickeln etc. Kein blödes Rumgedrücke mit Folien und Laserpointer, wie es in Deutschland gelehrt wird, sondern richtige Herleitungen Schritt für Schritt. Massachusist müsste man sein^^
@kazenohito76418 жыл бұрын
Oh my god I wish my instructor was like this. I swear my csc instructor just pulled rotations out of his mitochondria and did not explain a lick of how they work.
@ninatsvetkova8 жыл бұрын
At least you learn about the avl tree in your university...
@eRaZerrOfficial8 жыл бұрын
same dude...same...At least your teacher speaks
@ra1zoo7 жыл бұрын
at least you went to university...
@ausseriridische9767 жыл бұрын
Haha this is why I believe this video has so many views :[
@bluesystemjackson5 жыл бұрын
@@Wes-Tyler "Bad english is the language of science"
@aliaj.shafira72035 жыл бұрын
Thank you for this video, MIT! It helps me a lot to understand the material. And thank you to Mr. Demaine for the explanation. Your explanation is understandable.
@zhanghewnn10 жыл бұрын
It is a enjoyment to watch Erik's lecture! Greetings from Dalhousie!
@arashjamshidi32495 жыл бұрын
I love how the professor is kinda dancing while cleaning the board @ 26:05
@op1ekun818 жыл бұрын
At 45:00 isn't it LEFT ROTATION of X instead of RIGHT ROTATION of X? UPDATE: Already pointed out by DaxXx988 in the comments below. Thanks!
@mash20687 ай бұрын
Dude I thought I was the only one. The teacher, towards the end, was tired and as confused as the rest of us.
@IgnisArdor8 жыл бұрын
I'm a Maths student from Italy and my exam is tomorrow! thank you so much for sharing these!! they're so useful!!
@tryingtocorrect8 жыл бұрын
But why did you leave it to the last moment? :)
@IgnisArdor8 жыл бұрын
I had been studying for a month, i was revising. Passed it.
@darshanbhatt62938 жыл бұрын
g
@chas76185 жыл бұрын
Thanks MIT and prof. Erik for the fantastic lecture on AVL trees
@angelc47945 жыл бұрын
For some reason the Frisbee cushions bring me such joy. xD
@bachirmasry62339 жыл бұрын
If we could listen to the students remarks and questions, that would make this video in my opinion mush more beneficial.
@Hamza-qk9yq6 жыл бұрын
You can turn on the subtitles, it shows what the students are saying
@w1d3r754 жыл бұрын
There must be some sort of translations in the course's website
@sexy_jindwala10683 жыл бұрын
One of the finest videos on AVL Trees I have ever seen! Those who dont understand should not study, leave everything, Go Fishing!
@yajurphullera93964 жыл бұрын
25:39 "Now if you don't know fibonacci numbers, I pull a 'rabbit' out of a hat and..." I see what you did here Eric.
@sonikaagarwal9316 ай бұрын
I study at UNIMELB and this is so much better...and this is in 2011.
@NikhilKumar-fj2dg8 жыл бұрын
Thanks a lot professor for solving my doubt of AVL Tree and also thanks to MIT
@リンゴ酢-b8g2 жыл бұрын
A balanced binary tree, also referred to as a height-balanced binary tree, is defined as a binary tree in which the height of the left and right subtree of any node differ by not more than 1.
@reydavid73004 жыл бұрын
24:50 a random n appears in the reasoning whereas we were always talking in terms of N_h, h, and phi. He meant phi^h / sqrt(n) < N_h
@Bargains20xx4 жыл бұрын
i got confused for a while, maybe thats what reviews are for
@bsethupathi15 жыл бұрын
31.57 : "This guy is doubly left heavy. Hmm, Bad News." Cracked me up.
@websoftwaredeveloperijtiha30932 жыл бұрын
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
@johnxina749611 ай бұрын
yeah no shit
@WS-lv4kk6 жыл бұрын
At 46:55, and was noted at another point earlier that there may be an imbalance in the higher levels of a tree if an imbalanced node is balanced at a lower level of the tree. Is that really true in a properly coded AVL tree? A properly coded AVL tree is balanced at the moment of insertion. After insertion, node X is imbalanced because of, let's say, right-heavy right subtree Y. After rotation(s), Y is now at the previous location of X, and Y has the same height as X before the insertion. This is because Y's height increased by 1 as a result of insertion, and now has the same height as X before insertion. Moving Y to replace X in the rotation means the height at the NODE OF ROTATION does not change. Therefore, the only way that there could be further imbalance up the tree is if the tree was already imbalanced before insertion.
@anmolsharma95394 жыл бұрын
MIT &Erik you owe me for this!! Don't judge by edit sign on comment i misspelled Erik Lol😁
@scottwells93408 жыл бұрын
@31:30 "now all the heights change... and it's annoying to draw what the heights are... but... I'll do it"
@ethannetz49618 жыл бұрын
Yes I also watched the video
@minksq40267 жыл бұрын
Those tree nodes are so cute
@tc07client56 жыл бұрын
Erik's explanations are great! Thanks to MIT.
@PamirTea7 жыл бұрын
Tree rotation is magic.
@coder-wolf2 жыл бұрын
I really liked his personality. A great attitude to have as a teacher. I wish my university had more teachers like him.
@sagnikbhattacharya67254 жыл бұрын
guy walking in at 1:50 is a treat!
@shrikantsarma278 жыл бұрын
Damn good prof. ... Need more videos from him !
@MarcusLucasOficial4 жыл бұрын
Log (n) = height for balanced trees. On the example on 5:20, there are 15 nodes, height is 4, but Log(15) = 3.90689059. Wouldn't it be height = Log (n+1) ? What am I missing? Or "+1" is considered a constant, so it is not inserted into the equation?
@YiANgO54 жыл бұрын
after 7 years , still excellent
@parthinbaraiya71144 жыл бұрын
AVL FULL CODE C/C++ kzbin.info/www/bejne/mqHGaYqiZZ6bhdk
@yashwanthmendu9939 Жыл бұрын
Yes it is
@vothuong086 жыл бұрын
thanks MIT & professor for this video
@TheTownLord11 жыл бұрын
Very strong lecture! Clearly understandable and Smooth
@bluesystemjackson5 жыл бұрын
Viel besser als unsere Algorithmentheorie-Vorlesungen
@kevinbeteta17377 жыл бұрын
Another reason to give NULLPTR a value of negative one is that you have to move upward once to get to a genuine leaf.
@rudymagasrevy211011 жыл бұрын
this guy is a magician with chalk
@malikalamgirian8 жыл бұрын
At 46.00 is a left rotate, not a right rotate
@capetaquebratudo6 жыл бұрын
RR means you have to left rotate, its used RR notation because you add a node to the RIGHT twice.
@arnobchowdhury96415 жыл бұрын
Personal Timestamp: Rotation 32:44 Rebalance 43:00
@SneakyMrSnake9 жыл бұрын
Great lecture! Really helped to understand AVL trees for my exam
@mikkelrivera11 жыл бұрын
I think he may have made a mistake. He defines N(h) as the minimum number of nodes in an AVL tree of height h. In my opinion N(h) = 2^(h - 1) + 1 (I think a student suggested that but he never really elaborated on why that was wrong). As I see it, you take the perfectly balanced tree of height h - 1, and you add only 1 node to increase the height by 1.
@shivamkendre24335 жыл бұрын
Nice lecture I got clear image in my mind. Thank you so much sir
@ckim3361555 жыл бұрын
Literally a genius.
@suramshivakumarreddy10 жыл бұрын
i'm very impressed by the way u taught :)
@jonsmith12715 жыл бұрын
Thanks for explaining this. I can't believe how those students just wonder in late ,, given the opportunity they have
@TheMasterfulcreator5 жыл бұрын
because it gets filmed and put online.
@jonsmith12715 жыл бұрын
@@TheMasterfulcreator ?
@TheMasterfulcreator5 жыл бұрын
@@jonsmith1271 i'm saying i probably wouldn't worry too much about seeing the entire lecture if it all gets recorded and put online anyway
And the people said that you have to become a nerd to be smart and here we have Eric :P
@dmcmanam7 жыл бұрын
AVL Insert algorithm is incorrectly described as possibly requiring more than 1 or 2 rotations and having to travel up to the root. After 1 or 2 rotations retracing is done. I skimmed the video waiting for delete() and it isn't there, delete rotations can introduce further imbalances up the tree. For an example of the insert see: refactoringlightly.wordpress.com/2017/11/05/rank-balanced-avl-trees-on-github/
@Simon07255 жыл бұрын
Yeah, you're right about the amount of rotations required after inserting a new element. I was confused when he said about needing to traverse the AVL up in order to find any new imbalances so I was looking for a comment like yours to confirm my doubt xD
@seinj90139 жыл бұрын
40:47 - not sure it's correct that "we might have to do more than 2 rotations" after a violation fix, the tree should become re-balanced again
@mlazowik9 жыл бұрын
+korvix He explains that just after what you quoted. By adding a node you make all of the (left or right) subtrees of nodes on path from root to the added node larger. This one violation fix fixes only one of these subtrees. Others might have to be fixed too. Otherwise each operation would have a constant complexity. That'd be lovely, but unfortunately it's not true :(
@danyalette13696 жыл бұрын
yes you are correct: when a node is balanced after an insert, it will have the same height as before the insert, so after doing a post-insertion rebalancing of the first unbalanced node, you can terminate. in contrast, with deletion, you need to rebalance all ancestors.
@armathur2596 жыл бұрын
Earlier i was sad :( now m happy :) thanks Erik
@ShubhamSinghYoutube4 жыл бұрын
Lol, good to see your tree got balanced
@PuneetJainfca10 жыл бұрын
The lecture is AWESOME. but yeah, the LR thing and the heights of that tree in the question.. that isn't (h-3)... else the right child would be left heavy.. (lesser the height, lower it is..).... just my point of view.... I love these lectures :D
@lockersrandom61614 жыл бұрын
Thank you MIT.
@hannahmuthoni19213 сағат бұрын
This was a really fun lecture. Damn
@YasserSinjab2 жыл бұрын
who else here enjoy Erik lectures :)
@apartment_prishtina11 жыл бұрын
cushions, everytime they get a right answer they get a cushion because the seats they sit on are hard seats.
@gutierreznunezdavidisrael25114 жыл бұрын
Amazing! Greetings from Mexico.
@chipbk106 жыл бұрын
The more important thing should be mentioned here is how AVL applied in the real problems, and why we choose AVL to solve? The implementation is just after that. I never learn a thing that I don't know how important it is.
@nbafanboi238 жыл бұрын
I can tell that the students are pretty smart, just comparing it to my class at University of Waterloo. Although I can't tell if its the same students answering the question. I know that I would be clueless for half these questions.
@ziliestarrive5 жыл бұрын
Waterloo is a pretty damn good school.
@Ahmed-zq2vo4 жыл бұрын
I feel like I took a minor in CS because of this guy
@Jorgetime11 жыл бұрын
This teacher is awesome
@jasondads95096 жыл бұрын
Wow MIT lecturers are good
@Movewithkhu Жыл бұрын
keep the height order log n to keep the left n right tree balanced
@ashutoshtiwari43984 жыл бұрын
At 27:30 , how did he get N(h) > 2*N(h-2) to N(h) > theta(2 ^ (h/2) )
@--ShivaS3 жыл бұрын
did you get the answer for it ?
@reik2006 Жыл бұрын
N(h) > 2 * N(h - 2) > 2 * (2 * N(h - 4)) > 2 * (2 * (2 * N(h - 6))) > ... > 2^k * N(h - 2k) for some non-negative integer k and recurrence ends when N(h - 2k) reaches base case N(0) for k = h/2.
@AniRec-e8u2 ай бұрын
@reik2006 thanks bro i had same doubt
@woshikakadong6 жыл бұрын
I love this prof
@ericbelrose198410 жыл бұрын
Why didn't he start with a balanced tree. Is it not true that before he inserted the 23 the tree was already off balance. The tree was left heavy. I am still just starting the study of this structure, but it would seem that the tree would have to left rotate at 20 so 29 becomes it's parent and 26 joins it. Then the left subchild of the left subtree is heavy so it would right rotate so 29 becomes the head. Maybe it is because he knew he was going to add the 55 and didn't care that he didn't start balanced. If he did that rotation first the tree would be a perfect tree after adding the 55. Perhaps I'm confused. It would seem that you could improve the algorithm simply by looking beyond the max{HR,HL}. Could you not calculate optimal tree height for N and if max height after walking down to insert in the BST fashion is worse, then start rotations on the max height side. First step towards that side being heaviest in that side (left heavy where left is the issue/right heavy where right is the issue), then balance the head node by rotating away from the heaviness. Is there another name for that tree balancing algorithm.
@melode2219 жыл бұрын
Eric Belrose The tree at start point is not complete balanced, but is indeed `AVL balanced` which means it obeys the constraint of AVL tree, so it is a possible real world case you'll dealing with.
@EXHellfire5 жыл бұрын
the tree was left heavy but only by a factor of 1 over the right side. The idea is to keep the lack of balance either 0 or 1 to either side, but not larger than that 1. Otherwise if you forced a perfect balance of 0 at all times, you would be entirely unable to modify the tree, since you can't add two nodes at the same time, and if you did, you'd have to then add four nodes at the same time the next time and so on. If you allow it to be left or right heavy by at least a factor of 1 then you can add nodes as you go and then rebalance the tree if it's necessary, because you allow it to have empty spots. If that wasn't the case, say you have only the root node, and you want to add a child to it. You just can't, because that'd already make it either right or left heavy from the start, and so that would break the 0 balance factor.
@yyyyzzzzify11 жыл бұрын
Have a doubt about BST in this lecture, where professor writes >=x and < =x that shows nodes in left subtree are equal or less than its parent...same on another side. Isn't BST supposes to have no duplicate nodes, which means nodes in left subtree must be less than its parent not equal or less, and nodes in right subtree must be greater than its parent not equal or greater?
@Stu495839 жыл бұрын
great teacher
@gosumadman10 жыл бұрын
Can someone explain 26:09?I don't get why he changed N(h-1) to N(h-2) and removed the 1. Also I don't get how 2N(h-2) = (2^(h/2)
@jonsnow92467 жыл бұрын
Yes,but how?
@hangchen61317 жыл бұрын
Thanks! By the way, why h is decreasing by 2? Why the second line should be N(h-4) instead of N(h-3)??
@jilongzhang18516 жыл бұрын
it is more convenient to use log, I guess. If you use N(h-3), then you get N(h) > 2*N(h-3), nothing helpful
@jiaweizhou90846 жыл бұрын
Becase N(h) > 2N(h-2) and h replaced by h-2, the righthand side becomes N(h-4). Actually you can write this process as N(h) > 2N(h-2) > 2*2*N(h-4) until N(0)
@u401655 жыл бұрын
Sagar Theurkar Thanks a lot! I had a same question and little trouble to derive the last from the first. It was not only me who have the same.
@nilspin9 жыл бұрын
"Life is good."
@ShubhamSinghYoutube4 жыл бұрын
There's no feeling more merrier than successfully balancing an AVL tree. 🥺😂Lol
@overwhelmingsarcasm6 жыл бұрын
He sometimes switches between 'depth' and 'height', but the depth or level of a node is it's distance going down from the root, right? Also I've seen different ideas about whether the root of a tree is at level/depth 0 or - 1. Is there a widely accepted consensus on which should be used or is it just a matter of consistency with the formula/algorithm in the same way that null nodes were defined to have height - 1 here? The notation and terminology around this topic is a tad confusing...
@prasanna58366 жыл бұрын
I think level and depth are same but height and depth are different.That -1 theory for null nodes is widely accepted and about that root being at level -1,I've never come across any algorithm which assumes the level/ depth of root of a tree as -1.
@isbestlizard4 жыл бұрын
Erik de MAN!
@isbestlizard4 жыл бұрын
I like people who write individual letters, never trusted cursive
@umarfarooq32834 жыл бұрын
I should have just joined MIT dayummmm
@alawy55512 жыл бұрын
You can see the difference between learning data structures Now and in the past I learend AVL trees in 20 min video with good animation and easy to understand And i don't need to write it all on paper! I just take a screenshot and organize it on Notion Thanks allah for these changing
@Dinesh-ng6pb2 жыл бұрын
bro can you please tell me which channel or website to find the video with animations
@harshsharma032 жыл бұрын
you're clearly at the wrong place if you think 20min animation videos are greater than these gems of lectures. I specifically choose to watch these because they are raw and make my brain work more, which helps me understand them much more deeply than I would otherwise.
@LRP-845 жыл бұрын
Very nice your lecture
@micmicmic711 жыл бұрын
Great lecture, thank you very much!
@ga63r4h11 жыл бұрын
if node height = max height of the left + max height of the right + 1 shouldn't the root of the tree at 9:35 = 4 and not 3?
@jungsuheo58748 жыл бұрын
Is Erik out there? or could someone help me? I have a question. At 45:20, RR(x) should be changed to LR(x) or RR(y)? it violates 35:21 Thanks.
@tannernewton85438 жыл бұрын
It should be LR(x) RR(y) would be something completely different but you are correct
@geekoist11 жыл бұрын
@4:45 when writing the inset operation Erik got the direction wrong. It's a left rotation
@jazzvids6 жыл бұрын
at 42:50 didn't he mean that the left sub tree is -1 and the right one is -1 and that's why it comes out -2? If it was 0 like he says then the node would be balanced
@jazzvids6 жыл бұрын
also at 44:20 it seems like if you're AVL tree is good, it will never happen that node x is unbalanced and at the same time x's right child will be balanced.
@anonymoususer54027 жыл бұрын
Thanks a lot Sir.
@TonyNguyen-mc8bh11 жыл бұрын
BST has not a same Node...X-node can't equal X-Root in this case
@7yep4336dfgvvh2 жыл бұрын
Good stuff, thanks bro
@Cnidaria1411 жыл бұрын
no if you look at the maximum height of the children it is 2(maximum) since the last node has a height of 0. ok?
@windowslogo35776 жыл бұрын
33:00 mind blown inc
@adsk20506 жыл бұрын
40:23 - Watch from this part next time
@Zetzumarshen4 жыл бұрын
avl insert example: 36:03
@amrabdulaziz22538 жыл бұрын
thank you
@duneworker21955 жыл бұрын
Saved my live
@xenobob27734 жыл бұрын
Wow...a full room of people with 750+ SAT Math scores.