[MUSIC PLAYING]
DAVID MALAN: Well, so nice to see so many of you.
In healthier times, we would, of course, all be on campus.
But so glad you could tune in from all over the world this way.
My name is David Malan.
I teach a course called CS50, or Computer Science 50
at Harvard, which is our introduction to the intellectual enterprises
of computer science, and the art of programming.
And by way of today's talk, we thought we would give you
a sense of exactly what CS50 is about, what computer science is about,
but also giving you a sense of some of the campus itself.
Indeed, had these been healthier times, we
were hoping to convene in a space like this.
This is the American Repertory Theater, which is
one of the artistic spaces on campus.
Where, because of COVID this past year, we, CS50,
actually had an opportunity to collaborate
with the artists that run that theater and to teach CS50's lectures
from that particular space.
If you zoom in here, you'll see for instance,
we tucked a green screen off to the side so
that we could display code and other computer sciencey-type things
on the stage.
But what I saw this past fall, of curious,
was a little something like this.
Unfortunately, an empty theater with no students
present, but a whole bunch of TV screens on which we could see tiles of zoom
like we're doing now so as to interact in much the same way.
So I'm not sure just yet what this coming
fall will be like, but happy to say that we've
got models that work both ways indeed.
Just as a heads up as part of today's presentation,
if you have access to a piece of paper and a pen or pencil, do
try to grab that at some point soon in case we might reach for it later.
But welcome to CS50 and in turn, a taste there of.
I thought I'd begin by zooming out as to where we actually are on campus,
and give you a tour of just some of the first few places
that I myself visited back in the day.
Indeed, some 25 years ago, I had decided--
perhaps like you-- to go to Cambridge, Massachusetts and enroll
in Harvard as a first year.
And at the time, I found myself gravitating toward fields
quite different from computer science.
In fact, let me go ahead and zoom in here.
Pictured here, for instance, was one of my first locations
on Earth, and in turn, Cambridge, Massachusetts.
I found myself assigned to Matthew's Hall, which
is one of the dormitories in Harvard Yard there.
So using Google Earth here to give you a bird's eye
view of what that dorm room is.
Can't quite see it, but one of the window
seats here in the front of the building happened
to be my own room with my roommates.
And in fact, our claim to fame was that Matt Damon, the actor,
actually lived in our room three years prior.
So never actually met him, but listed on the list of past residents
when we moved in was indeed, his name.
But at the time, this first year of college,
I found myself gravitating toward more familiar fields.
In high school, for instance, I really liked history class.
I really loved a class on constitutional law.
And so when I got to Harvard and was trying
to choose among all of the available concentrations,
I started gravitating initially toward what I was most comfortable with.
And I did nearly half of the government concentration
it seems in retrospect, until finally about halfway
through college did I discover something a little different.
In fact, sophomore year, my second year on campus,
I ended up in one of the upper class houses called Mather House.
Not nearly as pretty as some of the others,
but amazing views here of both the river and the rest of Cambridge.
And it was indeed my sophomore fall that I finally
got up the nerve to shop, that is to attend briefly, a class called CS50.
It was being taught by a visiting professor at the time.
And I found myself, long story short, finally excited about learning.
And finally excited about a particular field.
In fact, for what?
19 years at that point, if homework was something that I did,
I sort of felt compelled to do well as best I could.
But it wasn't something I was particularly ever
passionate about until CS.
And for the first time ever, literally, did
homework suddenly finally become fun.
At the time, we were actually across campus over here in Harvard Science
Center when the course met in one of the lecture halls
there that you'll perhaps see before long on campus.
Nowadays though, some years later, did I take the helm of that same course
after finding my way, after some trepidation,
to computer science itself.
And so the home of CS50 nowadays during healthy times
is this building here, which you might recognize as Memorial Hall.
Which is one of the largest, most beautiful spaces on campus.
Where Annenberg Hall, is where the first years eat,
as well as Sanders Theater where we, CS50, spend quite a bit of time.
So we'll share out a URL of that little tour
thereafter if you'd like to get a sense.
But for now, I thought we'd go inside as well,
if you're curious to see what Sanders itself looks like.
Indeed, were these healthier times, most all of us
would ideally be sitting in this space here looking up at this stage and all
of the woodwork there.
And if I spin us around here in this 3D view,
you'd see seats for some thousand first years, sophomores, juniors, seniors,
and parents alike.
So hopefully before long, you'll get a chance
to actually visit some of those spaces in person.
But there is where we introduce students nowadays ultimately to computer science
and problem-solving.
Indeed, if we were to distill all of computer science, all of CS50
to just one picture, I would propose we consider something like this.
Computer science at the end of the day is all about problem-solving.
And whereas in high school and prior, perhaps,
if you've done any computer science whatsoever or know people who have,
you might view it really as programming alone.
And programming for many people is a big part of it,
but it really is just a tool in one's toolkit.
At the end of the day, what was so exciting for me about computer
science was the ability to get better at and to solve actual real world
problems.
And what does a problem have?
It has some form of input.
That is the problem you want to solve.
The goal of which then is to have some form of output, the solution there too.
But before we can solve any problems-- and even think about these inputs
and outputs--
we have to consider for a moment how we can represent information.
For instance, there's a whole bunch of people in this room.
And of course, Zoom is doing the attendance for us by counting everyone.
But how is Zoom doing that underneath the hood?
Or if we were in person in Sanders, how could we
go about counting everyone in the room?
A problem to be solved.
How many people are actually here?
Well, we could certainly do it old school
and just sort of count on one hand and 1, 2, 3, 4, 5, and then maybe
use another hand as needed and so forth.
And so that's certainly doesn't scale very well, because let
me ask an obvious question.
How high can you count on a hand?
Feel free to chime in on the chats, not a trick question.
But the most obvious answer here, how high can you count on a hand?
One hand, though.
One hand.
So started high there.
But yeah, all the fives that are coming in and all of the Troys
who are responding five still.
Indeed, you can presumably only count up as high as five.
OK, so now we're getting a little more creative.
But indeed, we're going off track there.
Let me stipulate that it is indeed five.
Why?
On one hand I've got five fingers.
But I bet we could count higher than that, because at the moment--
I went ahead in advance here and wrote on my fingers--
we're sort of treating each of my fingers
here as representing a single person, or just the number one.
And so by putting up one finger and the number 1 or 2
I'm keeping track of 1, 2, 3, 4, 5 people.
But what if instead, we got a little more creative as humans
and maybe assigned different weights to our fingers?
And so here too, I drew lefty on my other hand.
And what if instead, my thumb represented still the number 1.
But maybe my index finger here could represent the number 2.
My middle finger could represent the number 4.
Ring finger number 8, and pinky could represent 16.
And there's indeed a pattern to those numbers,
but if I do weight my fingers more differently,
how high now might I be able to count?
And I saw a couple of you actually chimed with this answer already.
But if you haven't, consider how high could I now count on this human hand.
The only difference being that you and I might
agree in advance to represent information by assigning
different weights to these fingers.
So yeah, I'm seeing a whole bunch of 31s now fly across the screen.
And if that's not obvious to you-- that wasn't to me early on--
but consider that here's my fist closed, here's the number 0.
If I want to now count up the number 1, I'll raise my thumb,
and that's indeed the number 1.
If I want to now count to 2, I'm not just
going to put up a second finger like before.
I'm going to use a finger that's got a slightly different weight, my 2 finger.
And so I only have one finger up at this point.
If I want to represent the number 3, I can, of course, now put two fingers up,
because one's weight is 1, the other is 2, giving me 3.
If I now want to count as high as 4, I can somewhat offensively put up
my middle finger.
But then let's quickly count up to 5, which now uses my 4 and my 1 finger.
If I want to go to 6, it's now the 4 and the 2.
And then if I put up my thumb again, it's 1, 2, 4, which gives me 7.
And then it's a little painful on my hand,
but my ring finger would now allow me to count to 8.
And I'll stipulate that more nimble person could count all the way up
indeed to 31, because ultimately, that's how many permutations
you can actually have on your human hand if you
have five values available to you.
Five digits-- literally, no pun intended--
whereby each of those fingers can either be down or up.
And it turns out that this very simple idea on the human hand
maps exactly to what computers nowadays do.
You probably have a sense-- even if you're not a computer person,
have never studied CS or done any programming-- you've probably
at least heard that computers use the so-called binary system.
0s and 1s in some form.
Which is to say that they're really good at representing two values.
For instance, this could be the number 0 if the computer,
the digital equivalent, is sort of holding up no fingers.
And if a computer wants to represent a second value, 1,
the computer might do the equivalent of holding up a single human hand.
Either my finger is down or my finger is up.
And this is actually a very useful primitive.
Because at the end of the day, what's the only input
physically to your computer, your laptop, your desktop or your phone?
It's some form of electricity, right?
At the end of the day or throughout the day,
you presumably plug your device into a physical outlet
so that you get electricity, electrons, some kind of flow of electricity.
But that electricity-- even if you have no recollection or no studies in how
electricity works-- it's either there or it isn't.
Which is to say, in the physical world, just like a human hand--
if you have a way of representing at least two different states, two
different conditions, down or up or off or on,
you can actually now speak or represent what we would call binary.
Bi meaning two, binary just being distinct from decimal, for instance.
Dec meaning 10, which is the number 0 through 9
that you and I typically use in the world.
Computers indeed only use binary, 0s and 1s.
And what is inside each of our computers and phones these days,
essentially, is a whole bunch of tiny little light switches.
Or transistors if you will.
Millions of tiny little switches that can
be on or off that allow the computer to either remember that the finger is down
or the finger is up.
That the electricity is off or the electricity is on.
These little switches can be toggled up and down so that if it's off,
it might look like this.
If the switch is on, it might look like this.
But we don't really need pictures at this point,
we just need two different digits--
not even fingers or light bulbs--
here comes the so-called 0s and 1s the computer speak.
They don't need 2 through 9, they only need 0 and 1.
Because at the end of the day, they're representing information
by just toggling all of these little switches and little patterns.
Of course, this is problematic if you only have a single binary digit.
A single bit, if you will.
0 or 1.
Because of course, you can count as high as 1 only,
but how do you still count to 2 or 3 or 7 or 15 or 31 or even a million?
Well, it just seems that you need more bits, more 0s and 1s.
And here's where things actually get familiar.
And even this is something where the light bulb proverbially went off
for me years ago.
Let's consider something ordinary like this 123, on the screen here.
This is the decimal number 123.
This is not binary.
This is sort of middle school math, where we've got a number 123.
But why is it that value?
Technically, all I've got on the screen right now is three symbols.
Sort of a straight line, a curly one, and then a doubly curly one.
The 1, 2, and 3, respectively.
But you and I instinctively assign meaning to these symbols,
because we've sort of grown up with this methodology.
You know that the 3 is in the so-called ones place,
and the 2 is in the so-called tens place and the 1
is in the so-called one hundreds place.
So how do we get from this pattern of symbols of 1, 2, 3 to 123?
Well, you and I do a bit of quick, rapid, instant mental math.
It's the same thing as 100 times 1 plus 10 times
2 plus 1 times 3, which of course gives us 100 plus 20 plus 3,
or the number you and I know mathematically is 123.
Well, it turns out computers-- even if again, you're not really
a computer person and wouldn't otherwise grok
how they are working underneath the hood-- it's actually
the exact same way.
Let me generalize these digits as just the hash symbols for a moment
to make clear that in the world of decimal, in our human world,
we give these columns meaning.
One, tens place, hundreds place, thousands place, and so forth.
But the reason for that is because of a bit of simple math.
These are technically 10 to the 0 power, 10 to the first, 10 to the second,
and so forth.
In binary, where you only have two digits
at your disposal, 0 and 1 instead of 0 through 9,
the methodology is exactly the same.
But what's going on inside of a computer--
so as to represent not just 0 not just 1 but any number bigger than that--
is we actually use powers of 2 instead of 10.
So it's 2 to the 0, 2 the 1, 2 to the 2, otherwise known, of course, as ones
place, twos place, and fours place.
And that hopefully looks a bit familiar, because that's exactly what I
started writing on my fingers before.
The ones place, twos place, fours, eights, 16, and so forth.
So once you have that paradigm in place here, for instance,
is how a computer would represent the number you and I know as 0.
It happens to have three digits here, but of course,
in math when you write 0s to the left of a number it doesn't change the meaning.
But if a computer wanted to store the number 0 for any reason--
because it's in your phone number, because it's a mathematical part
of a formula--
a computer would just toggle three switches off, thereby
storing no electricity, essentially, in those three locations.
So the ones place, the twos place, the fours place
have 0 under them, so it's just the number we know as 0.
A computer, by contrast, if still using three digits or three bits
to represent the number you and I know as 1,
would just put up a single finger, so to speak.
Or represent it digitally as 001.
If we want to represent the number we know as 2, it's now 010,
which is exactly why I held up one finger before.
If you want to represent the number 3, it's now 011, or two fingers up,
like I did before.
And if we keep going, 4 would be 100, 5 would be 101, 6 would be 110,
and 7, ultimately, would be 111.
So that's in essence, what a computer does to represent information.
And if all of us agree on how to represent information in binary,
now, all of our computers can intercommunicate, and with them
can we solve problems.
And what was one of the first problems?
Well, not just to do math and perform calculations and the like,
but to actually represent information.
Letters of the alphabet, the English alphabet for instance.
If you were to receive a text message right now
or an the email with simply the message H-I in all caps from someone,
technically what you've received is some kind of binary message.
Some kind of pattern of 0s and 1s that if we really look underneath the hood,
would look like this.
In other words, if you receive a pattern of electricity, so to speak,
that represents off, on, off, off, on, off, off, off and so forth,
what you've just received is an H followed by the letter I.
This is true of these things nowadays, emojis,
that you are probably in the habit of sending and receiving quite a bit.
Even though those look like pictures, underneath the hood
they are represented with a pattern of 0s and 1s
that all of our Macs, PCs, iPhones, Android phones and other devices
nowadays are preprogrammed to understand.
And as soon as they see that recognized pattern,
they present that image for you on the screen.
So this is to say-- and we could keep going down this road,
and we do in CS50 itself--
how you represent not just numbers and letters,
but images and sounds and videos and all of the medium with which we're familiar
today.
But I think at this point, we can stipulate that we
have a way of representing information.
The so-called binary system, with 0s and 1s
that's just convenient for computers.
Because again, there's either electricity there or there isn't.
So there's one last piece of this puzzle when
it comes to coming up with this mental model for what
it means to study computer science.
And to ultimately solve problems, we need these things called algorithms.
Another term that you've perhaps heard or used even--
if you've not studied CS or programming itself--
but an algorithm is just step by step instructions for solving some problem.
And what might that problem be?
Well, nowadays, all of you have some form
of contacts on your iPhone or your Android device.
And you might have a few friends as favorites,
but sometimes you might use autocomplete and start typing someone's name.
And then boom, that person's name and number hopefully come up.
That process might take longer though if you've got lots of friends and family,
because the list is just much longer.
Now naively, your iPhone or Android phone
could just look for whoever it is you're searching for from top to bottom,
looking is this the person?
Is this the person?
But if not-- and if you find them, great.
You call them.
And if not, you say, no search results.
But I bet we can do even better than that.
And we can do this not by even considering
the digital world, but perhaps something a little more old
school and physical, like this thing here.
So on campus, I grabbed a phone book of the greater Boston area.
A phone book, if you've not had occasion to use it,
has a whole bunch of names and numbers alphabetically
from A to Z, and so that I can go ahead and look up people in this same phone
book.
And only because her video is on right now,
Talia Kahan-- if I'm saying that right-- can I
pretend here to search for your phone number in this phone book.
Probably not going to be there if you're not from Greater Boston,
but we'll pretend none the less.
TALIA KAHAN: Sure, go ahead.
DAVID MALAN: All right, so here we go.
So Talia, I'm going to start at the beginning on page 1 here.
And I don't see Kahan, if I'm saying that right.
TALIA KAHAN: Yeah, you got it.
DAVID MALAN: So I'm going to keep going to page 2, to page 3, to page 4,
to page 5, and I still don't see her.
But eventually, I think I'll find it.
Indeed, is this algorithm correct?
I am step by step going through the 8 one page at a time,
paying attention hopefully, looking for Talia's last name.
And if I find it, I'll go ahead and actually call her.
So maybe by a show of heads nodding or shaking,
is this algorithm correct would you say?
Feel free to say yes or no in the chat too.
Yeah, Nathan Lee in the chat proposes correct but slow.
All right, so let me do a little better, because Talia's name's going
to be a little further down, so let me do two pages at a time.
So let me go ahead and hold this up here and 2, 4, 6, 8, 10, 12, and so forth.
Talia, is this algorithm correct?
If you don't mind my calling on you yourself.
TALIA KAHAN: I think it is, as long as it's possible, once you get to a Ks,
for example, to then start going page by page.
DAVID MALAN: Yeah.
Because in a corner case, so to speak, in a bad situation,
I might get a little unlucky and Talia's last name is in the middle of two pages
that I'm flying by.
So I probably want to slow down preemptively, or at least,
if I maybe hit the L section after the K section,
I might want to double back at least a page, just to make sure
that I didn't miss her name.
But of course, this is not how we would likely search a phone book,
certainly in the general case.
And this is not how your phone probably does it either.
Odds are, your phone does the equivalent digitally
of maybe jumping to the middle, looking down at this page here,
and oh, I did go a little too far.
I'm in the M section now.
But what we can do here-- and I'll sort of step back so that you can see this
more--
I can now tear this problem in half, throw half of the problem away.
So if I started with 1,000 pages, now I'm down to just 500 pages.
And what can I do next?
Well, I could just start going page by page, but no.
I can be smarter again and again.
I'll go to the middle of the remaining half.
Now I went a little too far to the left, I'm in the G section,
so I'm going to go ahead and tear the problem in half
again, throw the left half away.
So now I'm from 1,000 to 500 to 250 pages.
And I bet I can repeat, repeat, repeat this process until finally hopefully
we're left with just one single page on which Talia Kahan's name is or is not,
at which point I can definitively call or not call her.
And so this is an example of indeed an algorithm.
Step by step instructions for solving some problem,
but progressively better and better and better.
In fact, that first algorithm would have taken me 1,000 steps in the worst case.
If Talia's name just happened to maybe start with a Z instead of a K,
it would have taken me forever to find her.
The second algorithm would have taken me half as much time,
but still a decent amount of time.
Because there's still 500 pairs of pages that I could flip through at a time.
But that third algorithm, does anyone want
to estimate in the chat how many steps maximally would
it have taken me to find Talia Kahan in a 1,000 page phone book
if I had kept dividing and conquering, dividing and conquering?
Yeah, I'm seeing a bunch of good estimates in there,
and even one more precise mathematically.
So it's a roughly 10, depending on how we round and solve
the problem in practice.
But only 10 steps out of 1,000 pages to actually find Talia or more generally,
anyone's number.
And so algorithms really are this key part of problem-solving.
And once we've got that, we've got some way of representing a problem,
whether it's with hands on the finger or light bulbs or 0s
and 1s or physical pieces of paper, we can take those things as input,
and ideally solve problems as output.
And what programming itself is all about, if unfamiliar--
and indeed I should note that within CS50 2/3
of students who take CS50 at Harvard have never taken a course before.
Which is to say you're in very good company whether you have or have not.
And indeed, within the course, do we have different tracks for students
with and without experience?
Those less comfortable and more comfortable.
Even if you've not programmed before, what programming
really is is something that looks a little something like this.
If I were to now translate my algorithm to code or pseudocode, so to speak--
in sort of this English-like syntax--
I might first formalize it as, pick up phone book.
Then step two, open to middle of phone book.
Step three, look at page Step four, if person--
Talia in this case-- is on page, then call that person
And I'm indenting it deliberately to the right
to make clear that I should only do line 5 if line 4 is applicable.
Then in step six, Else if the person Talia is earlier in the book,
I'm presumably going to want to open to the middle
of the left half of the book.
And then go back to line 3, thereby looking at the page
and then checking again and again, that same process.
But if the person is later in the book, I instead
want to open to the middle of the right half of the book.
Then go back to line 3 again, and just repeat this process
as I did in reality.
Lastly though, to consider one final case,
what if the person is not in there?
I should Else, just quit if the person cannot, in fact, be found.
And so while this is not C or C++ or Java or JavaScript or languages that
you might have generally heard of or maybe even used yourself,
it's code in the sense that it's a very methodical,
precise translation of what you're supposed to do when compelling
a computer to solve some problem for you.
And it's apropos that I actually looked back at my own notes.
When I took CS50 myself some 25 years ago,
sophomore year, I found this, which was my second sheet of notes in my binder.
That of all my classes, I still hung on to.
And if you'll zoom in on this, it looks like Professor [INAUDIBLE] at the time
taught me that an algorithm is a precise sequence of steps
for getting something done-- just another formulation of the same.
And what was apparently important to me that day was precision and correctness.
Correctness being, does it solve the problem right?
But precision itself is pretty key too.
Because you and I, every day-- when we talk to each other,
when we give instructions, when we request things by phone or in person--
we take certain liberties.
And we read between the lines.
And we know what you mean.
And if you're not precise, computers are not that smart.
They can only do what we tell them precisely to do.
They're fast, which means they might really quickly do something wrong
unless we are precise and correct when it comes to writing that code.
And in our final moments here today, formally, after which we'll officially
disjoin and invite folks to chat one on one if you would like to stick around,
thought we'd do one final example involving one of you.
And Talia, if you don't mind, only because I summoned you earlier, would
you like to be on the flip side here and take over the mic in a moment?
TALIA KAHAN: Sure.
DAVID MALAN: All right, so I'm going to go ahead and a directly message a URL
to Talia only.
And if everyone else, if you have access to a sheet of paper or a pen or pencil,
go ahead and grab that now.
Talia, what I'm going to do secretly here
is message you a URL to open up only on your computer.
No need to share your screen.
And what I've sent to Talia is a picture.
It's a picture of something that the rest of us
are ideally going to now draw on that sheet of paper.
This being an algorithm, whereby Talia is going to program all of us verbally,
so to speak, giving us step by step instructions for drawing what it is she
and only she is seeing on her screen.
And then after she's given us all of her instructions,
we'll all hold up to our cameras, if you're comfy, to show her, and then
turn me, what we've drawn.
So Talia, you can say anything you want, but you may not
gesture physically to help folks out.
TALIA KAHAN: OK, got it.
DAVID MALAN: Floor is yours.
TALIA KAHAN: So I guess step one is to draw a diamond that
has four sides of all equal length and 90 degree
angles between each of the sides.
And then-- OK, so then step two is for the bottom three corners per se,
draw a vertical line down.
And all those lines should also be the same length as the initial diamond.
And then-- how do I explain this?
The last step, you're going to draw two more lines,
and that's going to be connecting the bottom of the vertical lines.
So those two more lines that you draw should
be parallel to the two bottom lines of the initial diamond.
DAVID MALAN: All right.
Step by step done.
If you're comfy sharing on your camera your sheet of paper,
hold it still for a few seconds so your camera can focus.
Talia, we'll let you give some judgmental looks at whether or not--
TALIA KAHAN: Yes.
DAVID MALAN: Yeah, most of these are spot on.
Slightly different proportions, perhaps, but indeed,
Talia what was it, at a higher conceptual level,
were you asking people to draw?
TALIA KAHAN: A cube.
DAVID MALAN: Yeah, so a cube.
And this is actually where we would pick up
this fall if you choose to join us is this concept of what Talia just
did was to be very, very precise, but oh my God,
if you had to program everything at that low level, programming
itself just becomes mind-numbing.
And you get really stuck in the weeds, and you can't see
the forest for the trees, so to speak.
Talia could have just said, draw a cube.
But a cube is what we would call in computer science an abstraction.
Sort of a higher level simplification of what it is you want to draw.
But before you can draw a cube, you need to define it.
And when you write code, you write things
that are called functions, which are code incarnations of ideas like this.
But hereafter, now that all of you have been programmed to draw a cube,
if Talia now says, now, remember, that is how to draw a cube.
Any time she wants to program something else
or draw some other picture that involves cubes,
she can now use that as an abstraction.
And say, OK, everyone, draw a cube.
Maybe parameterizing it or customizing it only in the sense of maybe how tall
or how wide or how elongated it should perhaps be.
So Talia, thank you so much for that.
In our final moments together, going to play a 60 second video
that is all thanks to the Harvard-Radcliffe Orchestra.
The video clip you saw at the very beginning
if you joined us right on time was actually
music that was designed by an alum, and ultimately now performed
by the Harvard-Radcliffe Orchestra.
Who we would ideally too would have had in Sanders with us here today,
as well as in this fall to perform.
But wonderfully, everyone on the orchestra filmed themselves some months
ago on their cameras so as to stitch this following video together.
And after this, you're welcome to drop off.
But I'll stick around with our team for any one on one questions.
Andrew, go ahead if you could and hit Play.
SPEAKER: 1, 2, 3, 4.
[MUSIC PLAYING]