CS50 2021 in HDR - Lecture 3 - Algorithms

preview_player
Показать описание

TABLE OF CONTENTS

00:00:00 - Introduction
00:01:17 - Algorithms
00:05:34 - Searching
00:08:17 - Big O Notation
00:12:51 - Common Running Times
00:13:18 - Asymptotic Notation
00:16:50 - Searching Lockers
00:20:46 - Linear Search
00:29:45 - Binary Search
00:37:11 - Sorting and Searching vs. Just Searching
00:41:23 - Implementing Linear Search
00:45:34 - String Comparison
00:54:28 - Storing Data in Arrays
00:59:36 - Structs
01:12:26 - Sorting
01:13:39 - Visualizing Sorts
01:26:22 - Selection Sort
01:34:28 - Bubble Sort
01:43:03 - Comparing Sorts
01:45:23 - Recursion
02:00:54 - Merge Sort
02:15:16 - Sort Race

***

This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.

***

HOW TO SUBSCRIBE

HOW TO TAKE CS50

HOW TO JOIN CS50 COMMUNITIES

HOW TO FOLLOW DAVID J. MALAN

***

CS50 SHOP

***

LICENSE

CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License

David J. Malan
Рекомендации по теме
Комментарии
Автор

I will never forget this man in my whole lifetime.

xavier
Автор

Pro tip: I had some difficulty grasping the concept of recursion until I ran it via debug50 and saw how it works step by step.
If you too are having trouble understanding how the "n - 1" part works (how "n" decreases without updating the variable) and also how the program prints backwards (starts from 4 to 1, but prints 1 to 4) like I did, I'll try to explain:

void draw(int n)
{
if (n <= 0)
{
return;
}
draw(n - 1);

for (int i = 0; i < n; i++)
{
printf("#");
}
printf("\n");
}

If the user sets the height to 4, the first function is called with 4 as n. The function now checks if n <= 0(in our case 4 <= 0). As this is not the case, the function is called again on the next line within itself, resulting in two functions having been called at the same time however the first function is now parked/halted until the second is completed, as the computer can only solve one problem at a time. 
The second function was called with "n - 1" as the argument or in our case 3 (4 - 1 = 3). again the new function checks if n <= 0 (3 <= 0). Again this is not the case and the function is called yet again on the following line within the second function, this time with the parameter 3 - 1(n - 1) or 2, because the previous function's n was 3.  
This now means that three functions are being called at the same time, with the first two being halted until the third function is completed. However, since the functions keep calling another function within themselves, the functions will continue to be halted and piled up until one of the functions no longer calls another function. In our example this only occurs once n <= 0. When this condition is fulfilled, that function will return/finish before a new function is called, and the previous paused function will resume where it left off, running its For Loop for the first time. The previous paused function's n was 1, therefore the function now prints a single Mario cube ("#"). The next halted function in memory proceeds and prints two Mario cubes ("##"), and so on, until the stack's final halted function resumes and completes our Mario staircase.

And there you have it; I hope this helps, and I strongly suggest you to try the code out for yourself using a debugger and stepping into the functions to fully comprehend how the computer executes the code.
Best of luck, guys & gals!

agentfifteen
Автор

I loved the concept of lockers to make students understand the concept of searching.

Totor
Автор

" I'm Rave.. Rave like a party." Wish my name was Rave so I could say that all the time

rolandcucicea
Автор

TURN OFF THE GOD DAMN HEATING MY MAN IS TOAST

mxgifyj
Автор

Someone please cool this man down, he is crucial to my future career.

frosty_teacup
Автор

its only the 4th lecture and i am learn much, thanks david

hatsukegero
Автор

This lecturer is the best. Concept delivery at its best. Respect to him and the entire crew that made this video available to the general public.

danielnyakundi
Автор

god bless this man, he explains things so clearly that i struggled to understand for a long, long time

ying
Автор

The lecture worked really well for me, especially since I do better with visualisation. However, though, I kinda wish Dr. Malan talked about the concept of stacks while going over the recursive function. It would’ve been much much easier

advaithsahasranamam
Автор

If you don’t get how the pyramid was built with just one for loop pls watch, recursion in C by Jenny lectures

pearlr.
Автор

the final scene just like a movie, the concept is organized so well through this lecture

alanlu
Автор

you are indeed a great professor!! I have been learning c, and until now, I did not understand what the struct is. I now fully understand what a struct is and how to use it. Thank you for taking your time and making the effor to making this lecture interactive and innovative.

rugmaable
Автор

i have never seen such kinda explanation on sorting algorithm like this tnxx alot
from Alx_africa student

FactFinders-ofmu
Автор

You know, these binary lights are very entertaining, but this one was so far my favorite.

JesseLeeHumphry
Автор

loving this year's into theme, as always the lecture is meticulous,

thawzinhtun
Автор

Thank you, Harvard. I've followed along now through week 4 and will surely be taking other free classes through your programs. You have helped me move into a new career at 35. I've finally gotten the drive to learn more and move up in my career and abilities. Classes like this are a treasure. Cheers.

Akerfeldt
Автор

This course is absolute joy! Thank you so SO much <3

AriaHarmony
Автор

Texting him (from Europe) to thank David for all of his work.. checking to see how much it'll cost me. Turns out I, for the first time, paid to get rickrolled.
Thanks David!

timmundt
Автор

29:50 "Rave, like a party" 😂😂😂
shes so cool lmao

LeelaSankharM