3. Sets and Sorting

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • MIT 6.006 Introduction to Algorithms, Spring 2020
    Instructor: Justin Solomon
    View the complete course: ocw.mit.edu/6-...
    TH-cam Playlist: • MIT 6.006 Introduction...
    Stored sets sorted by key allows for faster searching. This lecture covers how to construct a sorted array efficiently and the types of sorts.
    License: Creative Commons BY-NC-SA
    More information at ocw.mit.edu/terms
    More courses at ocw.mit.edu
    Support OCW at ow.ly/a1If50zVRlQ
    We encourage constructive comments and discussion on OCW’s TH-cam and other social media channels. Personal attacks, hate speech, trolling, and inappropriate comments are not allowed and may be removed. More details at ocw.mit.edu/co....

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

  • @adamhaney9447
    @adamhaney9447 3 ปีที่แล้ว +113

    This dude is simultaneously the most excited and patient professor in the world. It's awesome.

  • @ParthPatel-vj2zv
    @ParthPatel-vj2zv 3 ปีที่แล้ว +140

    0:00 intro
    3:13 set interface
    8:55 unsorted array
    14:05 sorted array
    18:48 sorting vocab
    21:28 purmutation sort
    26:04 selection sort
    40:52 insertion sort (skipped)
    41:25 merge sort

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

      deserved a like.

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

      PACHEL -- Sioux / Rushan - SWDEN... Hence; never India. Sw i.e. Sioux.

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

    All hail MIT for their selfless determination to contribute to our society.. for free!

  • @natura-g5i
    @natura-g5i 3 ปีที่แล้ว +109

    He didn’t stop smilling the whole lecture 😳

    • @sam_s3344
      @sam_s3344 3 ปีที่แล้ว +24

      He seems so happy :) We need more such professors!

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

      That's good. That means he loves what he does.

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

      Yeah... That's why I was so calmed when. I watched this video

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

      哈哈哈哈you’re right

    • @scatteringparameters.4167
      @scatteringparameters.4167 หลายเดือนก่อน

      He depressed.

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

    The 3 instructors are just great. Good class as well.

  • @ram_bam
    @ram_bam 3 ปีที่แล้ว +26

    Justin is a fantastic lecturer.

  • @JeffreyConcerto
    @JeffreyConcerto 3 ปีที่แล้ว +22

    Love that MIT is providing this to us for free. Thank you! The lecturer is passionate and knows his stuff, but the previous lecturer from Day 2 was far superior. The students would probably benefit more if he taught the entire course.

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

      yeah, previous one is much better, and much more comforting

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

      This lecturer's math is better - more rigorous.

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

      I love his enthusiasm but also love the guy from day 2!

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

      That guy is a genius.

    • @wyqtor
      @wyqtor 3 วันที่ผ่านมา

      Erik Demaine is simply the best teacher! And Srini Devadas from the previous version of this course, while slightly below Erik at teaching, is still much better than both of the other lecturers.

  • @textinface1
    @textinface1 ปีที่แล้ว +15

    So far my favorite lecturer. Really engaging and easy to follow

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

    Entire 6.006 course recordings makes me wanna go back to university and study cs again

  • @sweeteshsingh4054
    @sweeteshsingh4054 3 ปีที่แล้ว +28

    At minute 41.07, by mistake professor mentions Insertion sort runs in O(n) time, it should have been O(n^2). I know it was human mistake, can happen with anyone.

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

    Great lecture Justin, you have a great vibe about you. The quiet students in the class makes it all funnier to me. Feels bad Justin haha

  • @daydreamed
    @daydreamed 3 ปีที่แล้ว +5

    Thanks for the update. Really helpful resource

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

    This is really deep, like deep learning deep - Justin Solomon

  • @lucaswolf9445
    @lucaswolf9445 3 ปีที่แล้ว +14

    I was slightly confused at ~ 13:30: Inserting a new element (at the end) should take Theta(1) amortized time (and not O(n) amortized time, as the instructor suggested). However, since we have to search through the entire dyn. array on every insert to check if an element with that key already exists, the insert operation runs in O(n).

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

      Agree with you.

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

      @Lucas keep in mind the professor's response is relative to the argument he gave earlier in the lesson of traversing, one by one, through an array of size n to find(k), and that would take order n time.

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

    Very helpful thanks mit love from india 🔥🔥

  • @ZMan-lx6pg
    @ZMan-lx6pg 8 หลายเดือนก่อน

    Watching it online it feels like why isn't anyone answering what the Professor asks, but even if I would have been sitting in the class, I would not have answered thinking someone else would. But that made it hard for the Professor.

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

    what is meant by the remark at 9:20 about the previous two lectures using 'metaphorical arrays'? is this refering to the 'memory allocation model' described by Demaine in L02?

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

    The way that nobody answers his questions makes me sad, honestly. He's doing his best to give you some knowledge and you can't even say if 72 larger than 8.

    • @photographyraptor
      @photographyraptor 2 หลายเดือนก่อน

      why is he asking 3rd grade questions though, who's going to raise their hand for that in uni

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

    Yes, that’s true that this teacher is not able to share his ideas throughout his lectures and can’t able to connect with them

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

    you are not counting your students here in youtube around the world. Greetings from Argentina. Sorry for my english , i'm not very good with the sintax

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

    Very easy to understand

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

    he really wasn't kidding about the serial killer handwriting

  • @Juan-dc6yf
    @Juan-dc6yf ปีที่แล้ว

    Goat lecturer

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

    thank you ~

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

    5:16 set is a container

  • @nirbhaysingh4360
    @nirbhaysingh4360 3 ปีที่แล้ว +13

    I feel bad when the students are not responding, lol 😅

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

      It's because he wasn't doing a good job engaging the students and having them follow his thought progression, so many had tuned out and/or weren't understanding him. It didn't help that he basically dismissed any questions they had so that he could cram as much material as possible into the time he was allotted.

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

    I like his vibe

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

    MIT should limit the number of instructors taking a course. Like 3 proffs for a DSA course, it does affect the synchronization between the students n the proffs. Btw, loved Erik and Jason, Justin is just trying to cover too many stuffs in too less time.

  • @ScientistShield01
    @ScientistShield01 8 หลายเดือนก่อน

    thanks mit

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

    I didn't know James Murray taught at MIT!

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

      That's a good joke :)

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

    thank you mit

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

    Thank you! Great content!

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

    Very nice ocw!

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

    Hence; itt doesn't collect - because; you load out!

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

    Why do we always seem to go backwards(?); why not just push to the array and when the length reaches the size we stop?
    Is it's because it's easier to make inductions on where we anyway need(?) to be explicit about the index and don't want to make assumptions about the underlying datastructure?

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

    Great!

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

    Thanks MIT

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

    All the teachers are good

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

    can i watch these lectures and try to write code in C++ instead of Python? I mean I can but is it a good idea to learn both C++ and Algorithms, and is it feasible?

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

      You can but we would advise you look for a course that is in C++ and save yourself some extra effort. If you still want to do this course, it is possible. The logic and the algorithms will work for almost any programming language. Things to look out for:
      - C++ is statically typed vs Python which is dynamically typed.
      - Python Functions do not have restrictions on the type of the type of its return value. C++ does have restrictions. C++ can only return a type of value which is already defined.
      - Python variable scope is more flexible than C++. Look out for issues of scope in things like loops.
      Best wishes on your studies!

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

    37:34から

  • @4431freddy
    @4431freddy 4 หลายเดือนก่อน

    I'm confused about the merge sort code. Does it not seem to have added the i term of L/the j term of R into the set A? It only made the A[b-1] = L[j-1] or R[j-1], but there's no statement to assign L[i] or R[j] to the A[b]. This is my confusion, maybe it's fault.

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

    why are we doing comparison/merges in reverse order for selection and merge sort? what's the point?

  • @omarh7l193
    @omarh7l193 4 หลายเดือนก่อน

    sorry but can someone tell me in 25:00 why does the loop starts from 1 not 0 ?

    • @LiamLagan
      @LiamLagan 3 หลายเดือนก่อน +2

      He has chosen to write pseudocode with 1-Based Indexing, in which you access the first element of the array like this: array[1]. If you are used to 0-Based Indexing, the loop would be for i from 0 to length(array) - 2. Note the use of -2 rather than -1, we don't need to visit the last element, as there wouldn't be anything to compare it with.

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

    Awesome

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

    first thanks for amazing course but there something wrong here when prof explained selection sort i reconized it doesn't a selection sort ti's a abubble sort please correct me if am wrong

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

    Nice lecture. I wonder why he doesn't use the number 8 in any of his examples. haha

  • @ganeshanageshappa9341
    @ganeshanageshappa9341 3 ปีที่แล้ว +6

    Start watching at 2x speed.

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

      Obviously

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

      Oh, I thought I have open 2x speed in the beginning!

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

    This guy said hella

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

    question: what does Eric post on Facebook?

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

    could anyone help me with the recitation 2 followed by exercise where Set from Sequence has to be built? I am not getting the part self.S.get_at(i).key inside the insert method. What kinds of items are we feeding to build the sequence seq() and later set from seq? Are we making custom item object with key attribute as intrinsic property? Please help me with this.

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

    Imagine paying to go to MIT and the professors can’t be bothered to write properly/legibly

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

    Done!!

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

    Anyone else get confused by the mathematical part?

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

      Check discrete math, which is essential for learning algorithms.

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

      not like he reaaly needs it@@seyitilkturk

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

    Are Lec pdf is avilable ?

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

      Yes, lecture notes and other course materials are available on MIT OpenCourseWare at: ocw.mit.edu/6-006S20. Best wishes on your studies!

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

    dude wastes so much time with rhetorical 3rd grade questions and decent jokes, but doesn't have time for student questions. he seems like a really sweet guy, but the time economy is terrible.

    • @mitocw
      @mitocw  2 หลายเดือนก่อน

      Keep in mind, courses like this have recitation sessions where students can ask questions for clarification.

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

    24:53 Omega question
    To answer it you gave to stop listening to wanna bes and go bVk to source math
    Omega is a probability space
    a set of all possible outcomes
    Set of all possible moves which he chose from his algorithm
    From comments I'd say this is only mediocre
    Stop whatever you're doing only when you're ready study probability theory for phds
    God wish Caltech picks me up for a professor Substitute for once
    Sorry MIT but my heart is in California

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

      Nope same symbol but different meaning. They're talking about algorithm complexity / big-O notation so it's not the same as the probability one

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

      You clearly don't understand what the Omega notation is in Algorithms.

  • @skidipap8750
    @skidipap8750 11 หลายเดือนก่อน

    who else is preparing for job interview

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

    this class is so non interactive

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

    Wow, I understood this, I even wrote code that did this three years ago, yet my applications which included samples of the code to Google and Amazon went unanswered and I never got into MIT. It is almost like they circumvented the security of my system.

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

    watching these lectures, the moment you think you're perhaps understanding the class better than the folks sitting there at freaking MIT, actually you're right, you're actually smart if you're doing this. these schools selection process is as useless as Guinness world record, not enough participate at the right time at the right age, it's like first come first serve

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

      First come first serve basis? I wanna research more on this now. Your comment helped me realize all this. Thank you!

    • @davyroger3773
      @davyroger3773 3 ปีที่แล้ว +5

      But how can you know that you understand the content better than the students? Because they dont speak up? Have you considered the other factors involved in that other than ignorance?

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

      Well, you are way over your head there, buddy! We are all smart, I will give you that, however, watch an TH-cam video in the comfort of you home is a whole different experience than actually being present in class along with 200 students.

    • @BohdanIvanov-ru7qg
      @BohdanIvanov-ru7qg 4 หลายเดือนก่อน

      @@davyroger3773 You don't get it bro. This guy is smarter than all these MIT students because he can bark that 9 is a larger number than 7 on command.

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

    I'm not sure if that student really know what he doing, great subject with worst explanation, Thank you for wasting my time.

  • @karthikKarthik-by6ws
    @karthikKarthik-by6ws 2 ปีที่แล้ว

    my comment is the 47th comment

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

    First😂

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

    /mk Xtt' green / black cammoflage 20deg fnt 100pts tempd DllCHaa'(Delta) 4''in x 4''in Att' center 3''in diamsz dbl speres //system.out.ArroW' HeaDD'.prntln("DllCHaa' SDR OrrbTTsz' L'''x system) /