CS50x 2024 - Lecture 3 - Algorithms

Поділитися
Вставка
  • Опубліковано 19 тра 2024
  • ***
    This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
    ***
    TABLE OF CONTENTS
    00:00:00 - Introduction
    00:01:01 - Overview
    00:02:58 - Attendance
    00:09:40 - Linear Search
    00:24:58 - Binary Search
    00:28:25 - Running Time
    00:38:06 - search.c
    00:51:29 - phonebook.c
    00:53:42 - Structs
    01:05:26 - Sorting
    01:12:43 - Selection Sort
    01:24:50 - Bubble Sort
    01:33:10 - Recursion
    01:46:28 - Merge Sort
    02:00:23 - Sort Race
    ***
    HOW TO SUBSCRIBE
    ua-cam.com/users/subscription_c...
    HOW TO TAKE CS50
    edX: cs50.edx.org/
    Harvard Extension School: cs50.harvard.edu/extension
    Harvard Summer School: cs50.harvard.edu/summer
    OpenCourseWare: cs50.harvard.edu/x
    HOW TO JOIN CS50 COMMUNITIES
    Discord: / discord
    Ed: cs50.harvard.edu/x/ed
    Facebook Group: / cs50
    Faceboook Page: / cs50
    GitHub: github.com/cs50
    Gitter: gitter.im/cs50/x
    Instagram: / cs50
    LinkedIn Group: / 7437240
    LinkedIn Page: / cs50
    Medium: / cs50
    Quora: www.quora.com/topic/CS50
    Reddit: / cs50
    Slack: cs50.edx.org/slack
    Snapchat: / cs50
    SoundCloud: / cs50
    Stack Exchange: cs50.stackexchange.com/
    TikTok: / cs50
    Twitter: / cs50
    UA-cam: / cs50
    HOW TO FOLLOW DAVID J. MALAN
    Facebook: / dmalan
    GitHub: github.com/dmalan
    Instagram: / davidjmalan
    LinkedIn: / malan
    Quora: www.quora.com/profile/David-J...
    TikTok: / davidjmalan
    Twitter: / davidjmalan
    ***
    CS50 SHOP
    cs50.harvardshop.com/
    ***
    LICENSE
    CC BY-NC-SA 4.0
    Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
    creativecommons.org/licenses/...
    David J. Malan
    cs.harvard.edu/malan
    malan@harvard.edu

КОМЕНТАРІ • 138

  • @user-ju1sn6xo8g
    @user-ju1sn6xo8g 3 місяці тому +55

    Seriously? 4k? HDR? Not only are the lectures amazing but so is the watching experience!!

  • @hamidrezaparand4909
    @hamidrezaparand4909 2 місяці тому +32

    This course is just amazing. And how good of a teacher is he is 🥶

  • @ViniSouza93
    @ViniSouza93 2 місяці тому +28

    The experience of studying this course is amazing, I feel that I´ve learned more in the last weeks that I´ve learned in a full year of a Technologist Degree

    • @MrArkaneMage
      @MrArkaneMage 25 днів тому +2

      Yes, especially the "training" wheels make things way more clear plus once you try to translate it into "real C" you really learn a lot in the process.
      No degree here but this course is pure gold for everyone interested in PCs, coding, etc.

  • @seeblu
    @seeblu 4 місяці тому +85

    I vow to complete this program this year. Started in December of 2023.

  • @luxxer9591
    @luxxer9591 2 місяці тому +9

    I love the fact that they dont put ads, full concetration Mode [on]

  • @stevenlomon
    @stevenlomon Місяць тому +7

    Having blast going through this and doing the Problem Sets!! David is one of the most enthusiastic teachers I've ever seen and he explains things so wonderfully

  • @user-ow8im4dd5o
    @user-ow8im4dd5o 3 місяці тому +39

    I can't believe this that this level content is free!,

    • @toke7342
      @toke7342 2 місяці тому

      Why not?

    • @saqib7685
      @saqib7685 Місяць тому

      @@toke7342 because they some course which are shit expensive but are not as good as this

    • @valentina7901
      @valentina7901 19 днів тому +3

      @@toke7342 you have madd comprehension skills

  • @reynonquirimit6075
    @reynonquirimit6075 4 місяці тому +39

    I vow to complete this program this 2024
    No more excuses!

    • @misterguy
      @misterguy 2 місяці тому +1

      And did you?

    • @reynonquirimit6075
      @reynonquirimit6075 2 місяці тому +2

      @@misterguy Sadly not yet, currently stucked on week 5.
      It's difficult but i'd still keep going forward

    • @misterguy
      @misterguy 2 місяці тому +1

      @@reynonquirimit6075 stuck on what, understanding the lecture, or doing the assignment that comes with it?

    • @Pranav-ie1ik
      @Pranav-ie1ik 2 місяці тому +1

      @@misterguy assignment

    • @reynonquirimit6075
      @reynonquirimit6075 2 місяці тому

      @@misterguy yeahh, currently stucked on pset5. Been quite busy

  • @Nillipilli
    @Nillipilli 19 годин тому

    Amazing video again. Really love the way how you explained running time, especially as I struggled understanding it during my studies but your explanation was really on point, thanks for that :)

  • @marveII0us
    @marveII0us 4 місяці тому +16

    Thanks prof David

  • @mr_riyajath
    @mr_riyajath 4 місяці тому +4

    Can't watch the lessons yesterday, as I was travelling. Finished the lecture 3 today and feeling more excited.

  • @sk45293
    @sk45293 3 місяці тому +6

    Recursion is wild

  • @FigueMonk
    @FigueMonk 12 днів тому +1

    Learning all this free is awesome, God bless Internet

  • @BaraBarabere.
    @BaraBarabere. 3 місяці тому +6

    intro music GOAT!

  • @xuenf
    @xuenf 25 днів тому +3

    Sam is just chaotic adorable

  • @victorfds
    @victorfds 2 місяці тому

    Amazing!!!! 🥇

  • @bwaco7004
    @bwaco7004 4 місяці тому +1

    cant wait to make sense of this through rigorous labs

  • @MatthewIrizarry-4
    @MatthewIrizarry-4 4 місяці тому +10

    Talking during 44:00 about return values…. In C, you can also return EXIT_SUCCESS or EXIT_FAILURE to make the code more readable

    • @mtarik0
      @mtarik0 4 місяці тому +1

      That's a useful tip! I think it would be nice in small projects like we do in this course but in case of a large project, you may need to see what value the program returns with, like returning 1132 could help a programmer point which code snippet to deal with. Is that capable of doing so?

    • @MatthewIrizarry-4
      @MatthewIrizarry-4 3 місяці тому +2

      @@mtarik0 You could just define a constant value to accomplish this. Say you wanted Error 653 to be an I/O error or BufferOverflow, whatever you wanted.
      #define BUFFER_OVERFLOW_ERROR 653
      And when you used the BUFFER_OVERFLOW_ERROR it will return 653😁

    • @mtarik0
      @mtarik0 3 місяці тому +1

      Is it possible to use both? If so, in the context of returning values as well as being helpful to a programmer, I feel like it becomes a bit redundant with this way. I might have missed your point though.@@MatthewIrizarry-4

    • @Nunoflashy
      @Nunoflashy 3 місяці тому +2

      @@mtarik0 If your question is whether you can use both the number and the #define (constant), then yes, you can use both. The point of using #defines and constants in general is to make the code more readable. If you were to return that "653" code any time you had an I/O error for example, you probably wouldn't know what it meant, whereas with a descriptive name such as BUFFER_OVERFLOW_ERROR, you'd know exactly what it means and where it should be used.

    • @mtarik0
      @mtarik0 3 місяці тому

      I wanted to ask whether it is possible to use EXIT_FAILURE and BUFFER_OVERFLOW_ERROR by #define (constant)@@Nunoflashy

  • @WizeChoice
    @WizeChoice 2 місяці тому

    Amazing 👉🏾✨✨✨

  • @user-nu3kb8pe6g
    @user-nu3kb8pe6g 4 місяці тому +29

    crazy how mixed the attendance is! Last year in my first CS class at University (in germany) we had like 15 girls and 200 dudes, the atmosphere here seems much more open

    • @troyyey4353
      @troyyey4353 4 місяці тому +5

      hows is that relevant ? why you even care about that ?

    • @user-nu3kb8pe6g
      @user-nu3kb8pe6g 4 місяці тому +29

      @@troyyey4353 how is it not relevant? Why should I not care about it?

    • @troyyey4353
      @troyyey4353 4 місяці тому

      im not sure if you are joining the course for the right reasons if one gender is more present than the other can effect your decision , im not sure what are you worried about @@user-nu3kb8pe6g

    • @st.bimbam
      @st.bimbam 3 місяці тому

      Because diversity is a good thing@@troyyey4353

    • @ernie5229
      @ernie5229 3 місяці тому

      @@user-nu3kb8pe6gYou are so a girl. You are why there were only 15.

  • @imcalled_ali
    @imcalled_ali 2 місяці тому

    amazing!

  • @oanhtuan2408
    @oanhtuan2408 Місяць тому

    Amazing 🎉 Wow😮

  • @not_amanullah
    @not_amanullah 3 місяці тому

    Thanks

  • @not_amanullah
    @not_amanullah 3 місяці тому +1

    Understood++

  • @user-dz8me4sp8m
    @user-dz8me4sp8m 11 днів тому

    1:53:28 How to merge: The computer points to the first value in each of Lists (3 6) and Lists (1 4). Compare the two pointers and place the smaller value between 3 and 1 in the new list above. The left pointer still points to 3, and the right cursor now points to 4 . (num 1 went up) Compare the size of the two 3 and 4. Of the two, 3 is smaller, so put 3 in the list above, to the right of 1. Repeat this...

  • @duanepoettcker5544
    @duanepoettcker5544 2 місяці тому +2

    I'm always amazed at how fast he types. Then I remember I'm watching it at 1.5x speed.
    (still pretty fast though)

  • @user-mm8ml1ku4g
    @user-mm8ml1ku4g 4 місяці тому +3

    void bubble_sort(int array[], int size)
    {
    // size = no of elemnts in the array
    for (int i = 0; i < size - 1; i++)
    {
    // compare adjacenies
    int no_swaps = 0;
    for (int j = 0; j < size - 1 - i; j++)
    {
    if (array[j] > array[j+1])
    {
    int temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
    no_swaps++;
    }
    }
    if (no_swaps == 0)
    return;
    }
    return;
    } // code for bubble sort

  • @user-mm8ml1ku4g
    @user-mm8ml1ku4g 4 місяці тому +2

    void selection_sort(int array[], int size)
    {
    // size = no of elemnts in the array
    for (int i = 0; i < size - 1; i++)
    {
    int smallest = array[i];
    int j1 = i;
    for (int j = i+1; j < size; j++)
    {
    if (smallest > array[j])
    {
    smallest = array[j];
    j1 = j;
    }
    }
    if (j1 != i)
    {
    int temp = array[i];
    array[i] = smallest;
    array[j1] = temp;
    }
    }
    return;
    } // code for selection sort

    • @chongxian7608
      @chongxian7608 4 місяці тому

      why didnt he teach this tho. im pretty sure there would be better ways, kinda dissapointed about the later part of the lecture......

    • @loldoctor
      @loldoctor 4 місяці тому +1

      @@chongxian7608Because he's setting up for the next lecture about memory. There are probably bitwise methods that would be blazing fast, but the point of the class is to teach CS concepts not how to optimize code.

  • @angelofinassu4867
    @angelofinassu4867 2 місяці тому +1

    The CS50 it's perferct

  • @cope4854
    @cope4854 4 місяці тому +4

    1:05:45

  • @sci-tech3916
    @sci-tech3916 4 місяці тому +4

    38:06

  • @dglesterhardunkichud4287
    @dglesterhardunkichud4287 2 місяці тому +1

    Is anyone else confused about what the lights in the front of the stage say in binary, or did I just mess something up/miss something?

  • @muhammadzeeshan3911
    @muhammadzeeshan3911 Місяць тому +2

    In merge sort if the length of list is in odd number how can we make 2 equal sections or how can we divide list in two equal lengths please reply

    • @Magicninja01
      @Magicninja01 Місяць тому +1

      The halfs dont have to be equal. If its an odd number, one half will be 1 higer than the second

  • @sathishp3180
    @sathishp3180 4 місяці тому +1

    1:22:47

  • @ombanerjee2623
    @ombanerjee2623 Місяць тому

    finished 17/04/2024, the day before my kcet exam

  • @anukritis1297
    @anukritis1297 Місяць тому +1

    The course is awesome.Have reached lecture 3. But I am unable to understand recursion program. I get the theory but not exactly how we are getting the pyramid. If draw(n-1) is implementing value of n should reduce yet on printing value of n instead of # output is
    1
    22
    333
    How??????

    • @fundef
      @fundef Місяць тому

      It decrements n by 1 until it's 0 (the base case) and then it starts printing the hashes on the for loop, it starts returning from the chain of function calls and at each 'level', n is bigger by 1
      After it returns from base case:
      n = 1 // for loop prints #
      n = 2 // for loop prints ##
      n = 3 // for loop prints ###
      ... and so on, until n equals the original height (which is going to print the last row of the pyramid)
      It only starts printing when it starts returning from the function calls

  • @botify9400
    @botify9400 3 місяці тому +1

    Summary
    CS50x 2024 - Lecture 3 focuses on algorithms and implementation. It explores the concept of thinking algorithmically and how to solve problems using code. The lecture uses examples such as searching for a number in an array to demonstrate different algorithms.
    Highlights
    The lecture emphasizes the importance of thinking algorithmically.
    It discusses the concept of dividing and conquering a problem to find a more efficient solution.
    The lecture introduces the idea of arrays and their characteristics, such as being contiguous and potentially unordered.
    [🔍] The lecture uses the example of searching for a number in an array to explain algorithms.
    [📚] It relates the concept of divide and conquer to various real-world scenarios, such as searching contacts in your address book.
    [🔢] The lecture highlights the importance of understanding how data is stored in memory and how it can be accessed using arrays.

  • @CordovaHGS
    @CordovaHGS 19 днів тому +1

    I was not provided brownies, who can I speak to about rectifying this issue????

  • @OfficialCodeVoyage
    @OfficialCodeVoyage 4 місяці тому +5

    *Merge Sort is Overpowered !*

  • @platoschauvet
    @platoschauvet 2 місяці тому

    1:43:00 I'm so glad that didn't work, cause I was real confused lol

  • @samrinagul7154
    @samrinagul7154 8 днів тому +1

    now i am actually jealous of Havard students

  • @amine63404
    @amine63404 4 місяці тому

    1:09:00

  • @endise1888
    @endise1888 4 місяці тому +1

    logic

  • @p199a
    @p199a 2 місяці тому +2

    This intro music reminds me something but i cannot remember what.

    • @abrarkhann71
      @abrarkhann71 2 місяці тому +2

      westworld

    • @p199a
      @p199a 2 місяці тому +1

      @@abrarkhann71 ye it feels tiny bit similar to westworld also it gives me same vibes

    • @abrarkhann71
      @abrarkhann71 2 місяці тому

      @@p199a I found it similar to that. It's good. Hope we don't get the Westworld's Delororis.

  • @SageExploit
    @SageExploit 3 місяці тому +1

    11:02 the struggle for "contiguous"😭😭

  • @saabiqstudios1281
    @saabiqstudios1281 3 місяці тому

    what if the number of doors is even, do you just skip to step 3?

    • @sergi23
      @sergi23 3 місяці тому

      You randomly choose one of the two central doors.

  • @jamesbrock7908
    @jamesbrock7908 Місяць тому

    Tipe for tideman: watch next lecture to learn how to swap values

  • @gideonokwan1785
    @gideonokwan1785 3 місяці тому

    Do we always have to use the cs50 library to get same results or there are other resources?

    • @sergi23
      @sergi23 3 місяці тому

      You use the cs50 library in order to access the functions it contains (like get_string or get_int). You'll eventually leave the cs50 library. In any case, it's best to check the documentation for every library and every function you use (at least until you know them a bit).

  • @SkepticLens
    @SkepticLens 4 місяці тому +2

    1:07:44 Anyone understand what David Malan said? Did he say we keep looking for you today? Why?

    • @virendxr
      @virendxr 4 місяці тому +20

      Eli was the name he was searching in his phonebook but was not found :)

    • @pratikkale5489
      @pratikkale5489 Місяць тому +1

      Watch the lectures with more concentration bro

    • @SkepticLens
      @SkepticLens Місяць тому

      @@virendxr Thank you, I was confused without the context

    • @virendxr
      @virendxr Місяць тому

      @@SkepticLens your welcome

  • @anmol__og
    @anmol__og 4 місяці тому

    Who is from GLA UNIVERSITY 0:20

  • @taro7145
    @taro7145 3 місяці тому +1

    Why does this guy knows everything?

  • @yugrp2128
    @yugrp2128 24 дні тому

    28:26 what if there are even number of doors

  • @syedzainulabideen4455
    @syedzainulabideen4455 4 місяці тому +121

    1like = 5pushups in 2024

  • @yblue6116
    @yblue6116 4 місяці тому +2

    21:42 - Class shit

  • @pizzzax8
    @pizzzax8 4 місяці тому

    gg

  • @beaverbot551
    @beaverbot551 Місяць тому

    Hi Qian

  • @anekhan.4442
    @anekhan.4442 4 місяці тому +2

    Kindly make sure urdu caption is available it's hard for me to understand english 😢

  • @marwanium10
    @marwanium10 3 місяці тому

    Sam l🫶♥♥

  • @Harsh-uh6pf
    @Harsh-uh6pf 3 місяці тому

    Please don't call John

  • @user-xs2ut1sy7i
    @user-xs2ut1sy7i 4 місяці тому +1

    Does Sam have IG?

  • @T....602
    @T....602 4 місяці тому

    I really dont like when the lecturers speak so fast .

    • @insidiousmaximus
      @insidiousmaximus 3 місяці тому +5

      not all education can be done at the pace of the slowest members of society.

    • @milanszekely9745
      @milanszekely9745 2 місяці тому +6

      You can slow down the video.

  • @Coding-to4zj
    @Coding-to4zj 3 місяці тому

    is this a kinderarden or university? we dont have enough time on planet to learn simple concepts with all these setups. there are much more complicated things that im sure you will skip even explaining let alone simulating and spending thousands of dollars to teach people. what a joke and waste of time. Thats why I never miss school.

    • @a23oj28
      @a23oj28 3 місяці тому +8

      Then do all the problem sets without watching it and see how you fare..

    • @Anna-pz9ry
      @Anna-pz9ry 2 місяці тому +5

      You don't have to be here. You can go to your genius school or wherever you think you belong rather than shitting on people who want to learn and the people who teach them.

    • @annyt4626
      @annyt4626 2 місяці тому +2

      just a couple of fun 10 minute activities all of a sudden we have no time.. ok lol

    • @mariatanya3533
      @mariatanya3533 Місяць тому +1

      Sounds like your mom didnt give you enough hugs as a child. Is she still alive? You can ask her for more hugs

    • @sayanbhaa
      @sayanbhaa 16 днів тому

      good luck learning with that attitude

  • @MrGpButler
    @MrGpButler 2 місяці тому +1

    I highly recommend that you call John's phone number.

    • @Magicninja01
      @Magicninja01 Місяць тому +1

      What will happen?

    • @MrGpButler
      @MrGpButler Місяць тому +2

      I don’t want to ruin it for you. But it’s fun!

  • @user-uq6nk3fx1z
    @user-uq6nk3fx1z 29 днів тому

    The experience of studying this course is amazing, I feel that I´ve learned more in the last weeks that I´ve learned in a full year of a Technologist Degree

  • @aidanthompson5053
    @aidanthompson5053 3 місяці тому

    1:28:23

  • @alexandredias1272
    @alexandredias1272 3 місяці тому

    51:32