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
Seriously? 4k? HDR? Not only are the lectures amazing but so is the watching experience!!
This course is just amazing. And how good of a teacher is he is 🥶
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
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.
I vow to complete this program this year. Started in December of 2023.
Wish you the best 👊.
I'm with you, started in Dec too
I am with you. I started last week. Keep going!
started this week let's go
How's your progress?
I love the fact that they dont put ads, full concetration Mode [on]
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
seriously!
I can't believe this that this level content is free!,
Why not?
@@toke7342 because they some course which are shit expensive but are not as good as this
@@toke7342 you have madd comprehension skills
I vow to complete this program this 2024
No more excuses!
And did you?
@@misterguy Sadly not yet, currently stucked on week 5.
It's difficult but i'd still keep going forward
@@reynonquirimit6075 stuck on what, understanding the lecture, or doing the assignment that comes with it?
@@misterguy assignment
@@misterguy yeahh, currently stucked on pset5. Been quite busy
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 :)
Thanks prof David
Can't watch the lessons yesterday, as I was travelling. Finished the lecture 3 today and feeling more excited.
Recursion is wild
Learning all this free is awesome, God bless Internet
intro music GOAT!
Sam is just chaotic adorable
Amazing!!!! 🥇
cant wait to make sense of this through rigorous labs
Talking during 44:00 about return values…. In C, you can also return EXIT_SUCCESS or EXIT_FAILURE to make the code more readable
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?
@@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😁
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
@@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.
I wanted to ask whether it is possible to use EXIT_FAILURE and BUFFER_OVERFLOW_ERROR by #define (constant)@@Nunoflashy
Amazing 👉🏾✨✨✨
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
hows is that relevant ? why you even care about that ?
@@troyyey4353 how is it not relevant? Why should I not care about it?
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
Because diversity is a good thing@@troyyey4353
@@user-nu3kb8pe6gYou are so a girl. You are why there were only 15.
amazing!
Amazing 🎉 Wow😮
Thanks
Understood++
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...
I'm always amazed at how fast he types. Then I remember I'm watching it at 1.5x speed.
(still pretty fast though)
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
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
why didnt he teach this tho. im pretty sure there would be better ways, kinda dissapointed about the later part of the lecture......
@@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.
The CS50 it's perferct
1:05:45
38:06
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?
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
The halfs dont have to be equal. If its an odd number, one half will be 1 higer than the second
1:22:47
finished 17/04/2024, the day before my kcet exam
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??????
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
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.
I was not provided brownies, who can I speak to about rectifying this issue????
*Merge Sort is Overpowered !*
Omg ✨spoiler alert ✨
Bogo sort is best
1:43:00 I'm so glad that didn't work, cause I was real confused lol
now i am actually jealous of Havard students
1:09:00
logic
This intro music reminds me something but i cannot remember what.
westworld
@@abrarkhann71 ye it feels tiny bit similar to westworld also it gives me same vibes
@@p199a I found it similar to that. It's good. Hope we don't get the Westworld's Delororis.
11:02 the struggle for "contiguous"😭😭
what if the number of doors is even, do you just skip to step 3?
You randomly choose one of the two central doors.
Tipe for tideman: watch next lecture to learn how to swap values
Do we always have to use the cs50 library to get same results or there are other resources?
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).
1:07:44 Anyone understand what David Malan said? Did he say we keep looking for you today? Why?
Eli was the name he was searching in his phonebook but was not found :)
Watch the lectures with more concentration bro
@@virendxr Thank you, I was confused without the context
@@SkepticLens your welcome
Who is from GLA UNIVERSITY 0:20
Why does this guy knows everything?
years of practise and learning.
28:26 what if there are even number of doors
You randomly choose one of the two central doors.
1like = 5pushups in 2024
😂
Upload push ups or reported
Lemme join ya
@@encapsule2220 accountability is key to sucess
@@encapsule2220 okay I will make a video and prove before Feb 8 2023
21:42 - Class shit
printf("lol
");
gg
Hi Qian
Kindly make sure urdu caption is available it's hard for me to understand english 😢
Sam l🫶♥♥
Please don't call John
john pork
Does Sam have IG?
Please don’t be creepy
She is annoying AF
I really dont like when the lecturers speak so fast .
not all education can be done at the pace of the slowest members of society.
You can slow down the video.
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.
Then do all the problem sets without watching it and see how you fare..
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.
just a couple of fun 10 minute activities all of a sudden we have no time.. ok lol
Sounds like your mom didnt give you enough hugs as a child. Is she still alive? You can ask her for more hugs
good luck learning with that attitude
I highly recommend that you call John's phone number.
What will happen?
I don’t want to ruin it for you. But it’s fun!
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
1:28:23
51:32