So I was actually just
back in Connecticut
at my high school for the
first time in years recently,
and chatting with some of my successors
about where I made my way in life,
and what I really didn't do,
actually, in high school.
In fact, I gave a talk
about all of the studies
that I didn't discover when
I was back in high school.
Because I still remember
wandering around the hallways
when I was last there, looking
in on various classrooms
where I'd spent a lot of time,
that there was one in particular
that I spent no time in.
And that was the computer science lab.
I still vaguely remember peeking
through the glass of the window
when some of my friends were taking
their introductory computer science
classes, but I had no
interest in it, honestly.
I just assumed it was all about
programming, and like C++ or Java,
whatever those were.
But it just didn't seem
all that interesting to me.
And any time I did look in, all
my friends had their heads down,
typing away, doing whatever
it was they were doing.
And so I focused on
history, and English,
and constitutional law was my
favorite class in high school.
And so when I got to Harvard
some years later, I kind of just
stuck with where I was comfortable.
I felt like, well, I hadn't
studied CS in high school,
so all the other students who are
taking CS here surely have a leg up
and know way more than me.
So I figured, ah, I
thought of it too late.
And there was this core
CS50 my first year here.
And it had this alluring reputation.
There were a lot of students in it.
But it really didn't
seem like it was for me.
I wasn't really a computer
person in that way.
And I felt like I was behind.
I didn't want to hurt my GPA by
taking something so unfamiliar to me.
And so I stayed within my comfort zone,
and I took more history, and government
classes, and I declared my major to
be-- or concentration to be government.
And it wasn't until sophomore year when
I finally got up the nerve to shop,
so to speak--
Sit in on a class before you officially
register-- this class called CS50.
And I only got up the
nerve to register for it
officially because the professor at
the time let me sign up for pass-fail.
So no harm to the GPA.
I was really able to explore
really well beyond my comfort zone.
And honestly, within weeks, I realized
for the first time in like 18 years
that homework can actually be fun.
And if you find the field that's
of interest to you, whether it's
CS or anything else, by exploring things
that you're not familiar with right
now, you might have the same experience
I did of going home on a Friday night.
The problem set or homework
assignment had just
been released at like 7:00
PM every Friday night.
And I would spend the entire evening on
my laptop working on CS50's programming
assignments.
Because I finally realized what it was.
And programming itself is not
the ends of a course like this.
It really is just about problem-solving.
And so quickly did I realize, wow,
I can use these kinds of ideas
to go solve problems in other
courses, to be more efficient,
to be more creative in
my extracurriculars.
I realized, wow, I can
now build some application
to now make processes
more easily accessible
on campus, like the
intramural sports program.
I was able to overhaul just with
a little bit of computer science.
And if we distill today what
took me all too long to discover,
problem-solving really
is kind of a picture
like this, where you have
some inputs, and the goal
is to achieve some outputs.
And that, in some sense,
really is computer science.
And programming, and a
lot of the particulars
that you learn in the classroom,
are really just deeper
dives into this very simple idea.
But how do you get to that point
of actually solving problems?
Well, I eventually realized that
you needed to do two things.
One, you needed to represent
these inputs and these outputs.
That is, we just all have
to agree how to do it.
And then you actually have to
do something with those inputs
to get those outputs.
And therein lies the problem-solving.
And so how do you go about
representing information?
Well, I could represent information--
all I need is some kind of input.
And here's the power cord to my laptop.
And honestly, even if you have
no idea how your computer works,
odds are, you appreciate
that this is pretty integral,
having somehow electricity, some
physical input come into the computer.
And if you unplug it, it's off.
If you plug it in, it's on.
And batteries, of course,
can persist this here too.
But off and on maps really cleanly to
what you all probably generally know
to be true of computers, in that
they only speak what language?
AUDIENCE: Binary.
DAVID MALAN: Yeah, binary.
"Bi" meaning two, mapping to
this concept of off and on,
or as a computer scientist
would say, 0 or 1.
That's why we have 0s and
1s at the end of the day,
because the simplest
thing to do electrically
is to either turn the power
on or turn the power off.
1 or 0.
We could have called it A and
B, but we call it 1 and 0.
But if all you have in a computer is the
ability to turn it on or turn it off,
or to store some value-- kind of
like a light switch goes on or off--
how can you possibly do anything
interesting or solve problems?
Well, let's just consider
like a simple light bulb here.
This has some power.
It happens to have a battery.
And if this thing is off,
we'll just call it a 0.
And if this thing is
on, we'll call it a 1.
So now we have a single
switch, or what's
known in computing as a transistor.
In fact, inside of your computer are
lots and lots-- millions of transistors
that just turn things on and off.
Well, if I have just one of
these, I can only do 0 or 1.
That's not all that interesting.
That would seem to give us
two problems total to solve.
So how can we count
higher than just 0 or 1?
Well, I might take two of
these, or three of these,
and maybe start doing things
a little more methodically.
So I could do 1, 2, 3.
So now I can clearly
count as high as three.
But that would seem to be it as well.
But no.
Computers are a little
smarter than that,
and we can actually adopt
patterns of on and off.
So this now, I'll claim is 0.
All three of these light bulbs are off.
Let me turn on this one
on, thereby representing
what I'm going to call a 1.
But you know what?
Now I'm going to go ahead and claim that
that's how a computer would store a 2.
It would turn a different light
switch on, the second one.
And you know what?
If it turns the first one back on,
this is how a computer stores a 3.
And now just take a
guess, if I do this--
uncomfortably-- what is the
computer perhaps now storing?
AUDIENCE: 4.
DAVID MALAN: 4.
This happens to be 6.
This is now 7.
Why?
How did I choose those
particular patterns?
Well, it turns out this is
something that all of us
are probably really familiar with.
If you think about our grade school
understanding of numbers, if I draw
something on the screen quite simply--
like this pattern of symbols.
1, 2, 3.
This is, of course, 123.
But why?
Because all of us just
pretty instantaneously did
the mental arithmetic of this being
the ones place, this is the tens place,
this is the hundreds place.
And then what did you probably
do in that split second?
Well, you did 100 times 1 plus 10 times
2 plus 1 times 3, which of course gives
you 100 plus 20 plus 3, or 123.
Now, that's a bit of a circular argument
because that's kind of where I started,
but now these symbols--
these curves on the screen, 1, 2, 3--
actually have now meaning that we've all
agreed represents the human number 123.
So computers are actually
fundamentally the same thing.
And in some sense, they're even simpler
than us humans in the following way.
If you have the same number of
placeholders, and we write down--
with great difficulty--
if we write down, say,
three places, or three light bulbs, if
you will, but doing it now textually,
and I write down, for
instance, 0, 0, 0, you
can probably guess that
in the world of computers,
if you've got three switches that are
all off, this represents the number 0.
And if I turn one of these light bulbs
on, so to speak, this of course--
as before-- is going to be
the number that I called 1.
Well, if I now do not just change
this one, but change this to a 0--
and this is where maybe my light bulb
patterns got a little non-obvious--
why is this 2?
Well, it's the same mental arithmetic
but just with different places.
A computer doesn't use
powers of 10, so to speak--
10 to the 0, 10 to the 1, 10 to the 2--
but powers of 2.
So this is 2 to the
0, or the ones place.
This is 2 to the 1, or the twos place.
This is 2 to the 2, or the fours place.
And so you just need to turn
these light bulbs on and off
based on this kind of pattern
to get whatever number it
is you're interested in.
So this is 2 because it's 4 times
0 plus 2 times 1 plus 1 times 0.
Why is this three when I turned
two light bulbs on earlier?
The same reasoning.
And what's the highest I can count
with just three light bulbs, or three
0s and 1s?
7, just because you got a 4
plus a 2 plus a 1, and so forth.
And what would happen, then, if I wanted
to count as high as 8, would you think?
AUDIENCE: [INAUDIBLE]
DAVID MALAN: Yeah, you
need to add another place.
Or really, you need
more physical hardware.
And this is why your computer
can only count so high
or store so much information.
You need an additional light switch--
or another transistor, if you will--
to actually store
additional information.
So that, then, is binary.
If you've just known intuitively
computers only speak 0s and 1s, why?
Well, that's because they start with
electricity as their physical input.
We humans have just all
agreed to represent values
in this way using binary by just
having these patterns of 0s and 1s.
But that pretty much makes for
a very expensive calculator,
if all you have are numbers.
So how do you get from numbers
and from electricity to now,
letters, say of the alphabet?
What could we do?
How do we now enable spreadsheet
programs, and word processors,
and text messaging, and
email clients, and the like?
What can we all do if our only input
is electricity, or in turn, 0s and 1s?
AUDIENCE: [INAUDIBLE]
DAVID MALAN: Say again?
AUDIENCE: Assign number
values to letters?
DAVID MALAN: Yeah, we can just
assign number values to letters.
So you know what we
could go ahead and do,
and if we want to represent
letters of the alphabet,
as before, the only goal
at hand is to just agree
on how to represent that information.
So let's pick a few
letters of the alphabet.
A, B, C, D, E, F, G, H, I. We
could just say, you know what?
Let's just agree to represent
A as 1, and B as 2, and C as 3.
Doesn't really matter, so long
as we all agree to do that.
But it turns out, some
years ago, humans decided
that A is actually going
to be 65, and B is 66,
and C is 67, 68, 69, 70,
71, 72, 73, and so forth.
This is known as ASCII or Unicode.
It's just a system that
humans agreed decades ago
shall be used by computers to
represent letters of the alphabet
just by storing numbers,
and those numbers in turn
are just the result of
the computer turning
little switches known as transistors
on and off in these certain patterns.
And let me, with the wave
of a hand, assure sure
that we can represent
colors, and sounds,
and videos in very similar ways.
But we need to actually just
agree on how to do this.
So in fact, there's an
opportunity here perhaps
to write a message in exactly the
same way that a computer could.
If you could humor me,
maybe, with eight volunteers?
Could we get some eight
volunteers up on stage?
OK, 1, 2.
Let me look a little harder.
3, 4.
Can I go a little farther?
I see no hands in the back.
OK.
There we go.
5.
6 over there.
I see someone pointing at someone else.
Come on, 7.
And let's go 8, over here.
Come on down.
And I just need you to
go ahead, if you could,
and stand beneath these placeholders
here on the slide, which
I've gone ahead and rotated just
so that they fit a little more
visibly on the screen.
Come on over.
What's your name?
AUDIENCE: Matt.
DAVID MALAN: Matt.
Come on over and stand under the 128.
What's your name?
AUDIENCE: Mira.
DAVID MALAN: Mira.
David.
AUDIENCE: Hey.
DAVID MALAN: David.
Nice to meet you.
Hello.
David.
Nice to meet you.
AUDIENCE: Anesha.
DAVID MALAN: Anesha, David.
And Monica.
Nice to meet you.
And what was your name?
AUDIENCE: Chris.
DAVID MALAN: Chris.
Nice to meet you as well.
So each of these guys is going
to have to scooch a little closer
to each other.
And you know what?
If this isn't too much effort, could we
actually get eight more volunteers now
that you know what you're vol--
OK, now everyone's hand goes up.
OK.
1, 2, 3, 4, 5, 6, 7, 8, if you could.
Come on down.
We'll do this round more quickly.
And what you'll notice now that we
have a bytes' worth of volunteers here.
What is a byte?
A byte is just 8 bits.
It's a more useful unit of
measure than just a 0 or 1.
And notice the terminology here too.
A bit-- a 0 or 1-- is a binary digit.
There's the etymology of
just that simple phrase.
And a quick hello to AJ.
AUDIENCE: AJ.
DAVID MALAN: David.
Jay.
AUDIENCE: Hi.
DAVID MALAN: David.
Nice to meet you.
AUDIENCE: Bianca.
DAVID MALAN: David, and
nice to meet you as well.
Here we have our second byte of humans.
And--
AUDIENCE: [INAUDIBLE]
DAVID MALAN: What's that?
AUDIENCE: We have seven right here.
DAVID MALAN: We have a seven right here?
1, 2, 3, 4, 5, 6, 7.
1, 2, 3, 4, 5, 6, 7, 8.
We have a bug.
Here we go.
Come on up.
Thank you.
Thank you very much.
In computer science,
that's an off-by-one error.
What's your name?
AUDIENCE: Helen.
DAVID MALAN: Helen.
David.
Nice to meet you.
Go ahead and join, I guess, this group
right here in the middle, if you could.
So these folks here hopefully
do have cell phones on you.
Key detail I probably should
have mentioned earlier.
That's OK if you don't.
That's OK.
We're going to recover.
Whoever doesn't have a cell phone
is now going to get a flashlight.
OK.
Let's do this.
OK.
Key detail.
Sorry, you can go ahead
and turn that off.
Going to cross my fingers here
that we have enough light bulbs.
Hang on.
Let's go ahead now and turn on, if
you could, three light bulbs here.
So you don't have your phone?
Here is a nice iPhone XS.
OK.
[LAUGHTER]
1, 2, 3, 4.
Let's go ahead and turn yours on.
Can you swap phones for a moment?
So we have two light bulbs there,
and we don't need anyone else's phone
on just yet.
Could you turn your light bulb on?
And could you turn your light bulb on?
And we need just one light bulb
here, if you could turn that on.
So let me step out of the way.
And you'll see that we have someone
in the 64s place whose light is
on, in the 8s place, then again
in the 64s place and the 8s place,
and lastly, the 1.
So if a computer indeed had some 16
switches or transistors inside of it
and turned on those switches
in this particular order,
what message are these humans
here representing at the moment?
AUDIENCE: Hi.
DAVID MALAN: So it's indeed hi.
Why?
Because the mapping we arbitrarily chose
but globally decided on is that 72 is H
and 73 is I.
Well, let's try one more further.
At the moment, we're just using
two bytes of humans, if you will.
Two units of eight.
But suppose that we didn't just draw
an imaginary line in between them
and count only up to the ones
place through that 128s place.
But suppose that we
treated everyone as one
much bigger value so that
we could count much higher.
So now, these humans are taking
on the value of a 128s place,
but then the 256, 512, 1024.
All I'm doing is multiplying by 2.
I'm going to need one more volunteer,
and I'll take on this role over here.
If I were to be at the very end
here, I'd now have 17 bits on stage.
17 switches or transistors.
Let me go ahead and turn on
just some of these, if we could.
Most of them, we might have
to borrow a couple of phones.
Let's go ahead and give-- if
you could turn your phone on.
Here.
Your flashlight.
Let me-- that's technically yours.
Can we borrow your phone for a moment?
OK.
Your phone is going over
here to the 32,000s place.
We need to turn yours on.
OK, I'll turn mine on over there.
So we need 1, 2.
Can we give you 3, 4 on?
Can we borrow that?
3, 4.
Can we-- keep the phones coming.
[CHUCKLING]
3, 4.
So 1, 2, 3, 4.
And then we skip 1.
And then we need you two
to be on, if that's OK.
And then over here, thankfully,
we need just one light bulb on.
So now it's your chance.
If a computer were
using this many bits--
16 bits.
And if I stand in place now, 17
bits, where I represent 65,536,
and our volunteers all the way on
the end represents the number 1,
and you do this math, what
number are we all representing?
OK, no one's going to get this right.
It's 128,514.
What might that message say?
Well, there's not nearly enough clues
in mine, but it's actually this.
So if you've sent today or recently an
email or a text message with an emoji,
you might have sent this one--
Face with Tears of Joy.
So that's its official name.
But it's not an image per se.
It's actually a character.
And in fact, you might know that
you have so many emojis these days,
and that's because
computers and humans who
use them have started
using way more than 8 bits.
Way more than 16 or 17 bits.
Sometimes 24 or 32 bits, which gives
us so many darn possible permutations
of 0s and 1s, or switches being
turned on or off, that frankly, it's
just become kind of a
cultural thing that we
have so many darn possibilities,
let's start using some of them
for more silly reasons,
if you will, like emojis.
So if you ever receive today or
hereafter a face with tears of joy,
what your friends have really
sent to you is a pattern of 0s
and 1s somehow implemented with
electricity or wavelengths of light
that represents, rather
mundanely, 128,514.
So if we could, a round of applause
for our human volunteers here.
[APPLAUSE]
Let me borrow this.
Thank you.
If you'd like to step off stage, we
have a little something for each of you.
So we have just one
last question to answer.
Thank you all so much.
We have just one other
question to answer,
which is, if problem-solving
ultimately boils down
to representing inputs
and outputs, what is
the process that we pass those inputs
through in order to get those outputs?
What is it you learn, ultimately,
in a course on computer science?
Well, it's perhaps best
explained by way of a problem.
So here is an old-school
problem where you
have a whole bunch of names and numbers
alphabetically sorted from A through Z,
and you want to find someone.
And even though this
is pretty old-school,
it's honestly the same thing as the
address book or the contacts app
that you have in your
own iPhone or Android
phone, or any particular device.
If you scroll through
your contacts, odds
are they're A through Z, alphabetized
by first name or last name.
So this is just representative
of the same problem
that you and I solve any time
we look someone up in our phone.
Well, if I want to look up an old
friend-- someone like Mike Smith,
last name starting with S--
I could certainly just start
at the beginning of this book
and do 1, 2, 3, 4.
And that's a step-by-step process,
otherwise known as an algorithm.
And is that algorithm correct?
Will I find Mike Smith?
AUDIENCE: Yes.
DAVID MALAN: Yeah.
I mean, it's a little tedious, and it's
a little slow, but if Mike is in here,
I'll eventually find him.
But I'm not going to do that.
I know he's going to
be roughly at the end.
So maybe a little more
intelligently or efficiently,
I could do 2, 4, 6, 8,
10, 12, and so forth.
It's going to fly me through
the phone book twice as fast.
And is that algorithm or
step-by-step process correct?
AUDIENCE: [INAUDIBLE]
DAVID MALAN: A literal contention.
It's almost correct, except
if I get unlucky and might
get sandwiched between two pages
because I'm a little aggressively flying
through the phone book.
But no big deal.
If I maybe hit the T section, I could
maybe double back one or few pages
and fix that.
But none of us are going to do that.
What's a typical person going to do?
And really, what's a computer going
to do, be it in your phone or a laptop
these days?
AUDIENCE: [INAUDIBLE]
DAVID MALAN: Yeah.
It's going to go roughly maybe
to the middle, or a little biased
toward the right, because you know
S is a little alphabetically later
than most letters.
And I look down, for instance, here,
and I see, oh, I'm in the M section.
And so I know that Mike is not this way.
He's definitely this way.
So both metaphorically and literally,
can I tear a problem like this in half?
This is actually not
that hard vertically.
I can tear the problem
in half, and now I'm
left not with 1,000 pages with
which I began, but maybe 500.
And I can do it again, and whittle
myself down to like 250 pages.
And again, down to 125.
And again and again and again
until I'm left with, hopefully,
just one or so page.
But what's powerful about, honestly,
that intuition that odds are you
had when you walked in this door
is that, in just 10 or so steps,
can you find Mike Smith in a phone book?
In just 10 or so steps, can iOS or
Android find someone in your contacts
by dividing and conquering,
dividing and conquering?
Whereas the other
algorithms might have taken,
gosh, like 1,000 steps, 500 steps,
almost as many pages as there are.
And so that's an algorithm,
and that's what's
inside this proverbial black box.
It's the sort of secret sauce.
And the idea is that you learn
not just to learn along the way,
but learn to harness in
your own human intuition.
And so I wish I had discovered
that far earlier for myself,
knowing that computer science
is not about programming per se.
It really is about problem-solving,
and just formalizing, and cleaning up
your thought process, and
introducing you to ideas like this
that you can then apply
in so many different ways.
So that there, say, is just
a taste of computer science.
Allow me to conclude with a
taste of this one course, CS50,
by way of the point of view of
one of our very own students.
[VIDEO PLAYBACK]
[MUSIC - PORTUGAL.
THE MAN - "LIVE IN THE MOMENT"]
- (SINGING) My home is a girl
with eyes like wishing wells.
I'm not alone, but I'm
still lone-- lonely.
Those days are done,
but I'm still glowing.
Ooh, la, la, la, la, la,
let's live in the moment.
Come back Sunday morning.
Oh my, oh well.
When you're gone, goodbye,
so long, farewell.
Ooh, la, la, la, la, la,
let's live in the moment.
Come back Sunday morning.
Got soul to sell.
When you're gone, goodbye,
so long, farewell.
My home is a girl who can't
wait for time to tell.
God only knows we don't need history.
Your family swinging from
the branches of a tree.
God only knows we don't
need ghost stories.
Ooh, la, la, la, la, la,
let's live in the moment.
