DAVID MALIN: All right, my name is David Malan,
and I do teach a class called CS50, an Introduction to the Intellectual
Enterprises of Computer Science and the Art of Programming.
In 1995, I was a first year here in Matthews Hall,
in the corner of Harvard Yard.
This was the room that I myself lived in, and Matt Damon a few years prior.
But it was in this room that I came up with this really long, exhaustive,
precise list of, like, the 32 courses my first year
that I planned to take for the next four years.
And it was filled with ec and government, a bit of statistics,
and math.
And funny enough, some years later, most of what I ended up doing here
was not on that original list.
But rather, I gravitated, though, in that first month of school
where you meet with your RA or your proctor one-on-one
to talk about what classes you might be interested in
and what you want to do in life.
And I was so focused on things with which I was already familiar when
I came into Harvard.
I really liked history and constitutional law in high school.
And so I kind of gravitated toward the familiar,
and I filled my 32 courses preliminarily on this sheet of paper
with those courses that seemed already kind of in my orbit of comfort zone.
But fast forward a few years later, and then
even in grad school, like the most impactful-- some of my most
favorite classes that I took here, ultimately-- were Dramatic Arts 101,
Latin A, an Introduction to Archaeology, and a little class called CS50.
Only in my sophomore year did I finally get up the nerve to come into CS50.
I shopped it, so to speak, before even registering.
I wanted to get a sense of what it was like.
I probably followed some friends into the classroom.
And I was not really sure it was for me.
I definitely didn't think of myself as a computer person, per se.
From what I'd seen in high school, it just
didn't look that interesting typing away on a keyboard and programming
or whatnot.
At least, as far as I had seen friends doing so in high school.
So it really was, for me, this field-- this course to beware.
But curiosity got the best of me.
I only stayed in the class the next day because the professor
let me enroll in it pass/fail, fearful as I was of an actual letter grade.
But fast forward just a few months later,
I switched my concentration, or my major,
from government to computer science.
And that exploration, that curiosity, that experimentation academically
really changed my trajectory in life.
And what I didn't realize at the time was that computer science
wasn't programming.
It really was all about just information,
which of course is omnipresent.
And it was really about problem solving, this act
of taking inputs, trying to get outputs, like solutions to problems,
and somehow figuring out what's in that proverbial black box in the middle
to make all of that work.
But to do this, I realized pretty early on that
you need a system for representing these inputs and outputs.
No matter the human language you and I speak and communicate with,
we all have to speak some common language.
And as you probably know even if you're not
computer people yourselves, what is the language that computers actually
understand?
The so-called binary system, "bi" meaning two.
And you've probably generally heard that computer speak zeros and ones somehow.
Well, how can that possibly be?
Well, if they have zeros and ones as their only vocabulary,
how do we get bigger numbers than 0 and 1, like 2 or 3?
How do we get letters of an alphabet, be it English or something else?
Colors, or sounds, or video, or anything else.
Well, inside of a computer are these tiny little switches
known as transistors.
And of course, they've got a bit of memory where they can remember things,
as well.
And if you turn these switches on, that's
how a computer might remember a 1.
And if you turn the switch off, thereby making it devoid of electricity,
it's how a computer might represent the number 0.
So if you have just one of these switches, which--
if I can steal a light bulb here from Sanders-- if you have just one
switch like this light bulb has here, if it's off, it might represent a 0,
and if it's on, now it might represent a 1.
Well, how do I count higher than 1 in binary?
If I only have 0, off, or 1, on, well, I need another switch.
And in fact, maybe I'll grab just a couple more of these.
And to count even further, here's how I might therefore represent the number 1.
If I want to count up to the number 2 or 3, you might think in our human world
that you'd do this.
2, and then 3.
And now if I want to count to 4 or 5, I of course
need to go grab even more light bulbs.
But not if you're a little bit clever about this.
And in fact, computers don't need this many light bulbs
to count up to 3 or to 64.
We can count much more cleverly like this.
For instance, if this is still the number 1
here on the right most end of these light bulbs,
and I want to count to the number 2?
Well, let me be a little more clever and actually take into account
not just how many light bulbs are on, but which ones are on.
So let me propose that I turn this one off, but turn the middle one on.
And I claim now, this is the number 2.
This is how a computer represents 2, by turning two light bulbs or switches off
and just turning on the middle one.
If the computer wants to represent 3, we turn this one back on.
And so even though there's only two on, we're now representing 3.
And if we want to represent 4, we go ahead and turn these two off,
and we turn this one now on.
And this is how a computer would represent the number 4.
And I can keep doing this for 5, and 6, and 7,
and beyond that I might need another light bulb.
But there's just a pattern going on here.
And it turns out even if that was a little bit cryptic and seemingly
random, it's actually more familiar than you might think.
Here, for instance, is now digitally what I just did in analog form
with these actual lights.
So 000 is like, off-off-off.
This, if we do out the math, is how a computer would represent the number you
and I know as just 0.
If a computer wants to count to 1, it turns on one of those switches,
one of those light bulbs-- the one all the way on the right like I just did.
So this is how a computer would represent 1.
Here's how a computer would represent 2, 3, 4, 5, 6, 7--
and indeed, if I want to represent 8, what do I probably need to do?
Another 0 or 1.
Another light bulb to do this.
But now, this pattern may be perhaps non-obvious.
But let me propose that we consider what you and I take
for granted since grade school, just doing numbers more generally.
Here, of course, is the number 123.
But not really.
If we really go back to basics, this is just three symbols on the screen--
a sort of straight line, a curly line, and a doubly curly line
that you and I ascribe meaning to.
123.
But think about what your grade school teacher probably taught you.
The right-most column of numbers is the ones place, or the ones column.
Then you have the tens place, the hundreds place.
And so the fact that these symbols are, from left to right,
123 means you're doing some really quick mental math just natively
nowadays, whereby it's 100 times 1, plus 10 times
2, plus 1 times 3, which of course is 100 plus 20 plus 3.
Ergo, the number, you and I immediately know, is 123.
Well now let's take away the digits 2 through 9,
which you and I take for granted in our decimal world, the "dec" meaning 10,
and just consider that these placeholders could very well just mean
different things.
So generically, if we've got three digits in our decimal world,
they're the ones place, tens place, hundreds, thousands, ten-thousands,
and so forth.
And that's because we're using powers of 10 in our human world.
10 to the 0 is 1, 10 to the 1 is 10, 10 to the 2 is 100, and so forth.
So let's just change what that base is.
And if we take away the digits 2 through 9, leaving us with just zeros and ones,
that's OK.
We can still count as high as we want because now we
have the ones place, 2 to the 0, the twos place, 2 to the 1,
the fours place, 2 to the 2.
And so why is this number here the number you and I know in decimal as 0?
Well, it's 4 times 0, plus 2 times 0, plus 1 times 0,
which is obviously 0 itself.
Why is 001 the number you and I know as 1?
4 times 2, plus 4 times 0, plus 2 times 0, plus 1 times 1, gives us 1.
And if we fast forward to whereby we might have, say, 010, 011,
or let's go all the way to the end, 111.
This is not one-hundred eleven in this context of binary.
This, of course, is the number 7, because it's
4 times 1, plus 2 times 1, plus 1 times 1.
So there.
Even if you're not a computer person, never
thought you would study or know much, if anything, about computer science,
we all now know binary.
We have this common language with which we
can begin to solve problems by representing those inputs
and representing those outputs.
But numbers, of course, only take us so far.
Like, what if we wanted to use not just three, but eight bits.
And eight is a more common unit of measure in the computing world
because it's just more useful to have more switches.
This is a byte, byte implying eight bits.
And a bit is just a binary digit, a 0 or 1.
So here's the typical unit of measure-- bytes,
and from that we get kilobytes, megabytes, terabytes nowadays,
gigabytes, and more.
Well this pattern here, if we actually did out
the math, that's like the 64s column, that's the ones column.
So this is the decimal number 65.
That's how a computer would represent 65.
And it turns out, in the right context, that's
how a computer represents the capital letter A.
So we humans just need to decide, as our ancestors did some decades ago,
what patterns of zeros and ones we're going
to use to represent letters of the alphabet, as well.
There's this whole system called Unicode that
standardizes not just English, but so many other human languages, as well.
And here's just an excerpt of like 128 possible mappings
of just numbers in decimal in one column,
to the corresponding letters in the other.
So let me highlight just the middle portion here.
A is 65, B is 66, C is 67, dot, dot, dot, H is 72, I is 73.
And there's an association between numbers and letters
for every other symbol in English, and now other human languages, as well.
So if you were to get a text message today, or an email,
or anything digital, that had these three bytes underneath the hood somehow
sent wirelessly to your device, this pattern from left to right,
if we do out the same math as before with the ones place,
twos place, and so forth-- it's the number 72, 73, 33.
If you just do out the math three times.
Anyone have good recall and want to tell us what this says on the board?
So it says "HI!"
Why?
Well, 72 was H and 73 was I, and a little off to the side
was 33, which was just an exclamation point.
So this is how you would type in all caps "HI!"
to a friend in an email or a text message or the like.
So let me just stipulate that there's so many other things we can represent.
Certainly, whole words.
And in fact, wouldn't it be funny if this whole time there
were these 64 light bulbs on the stage representing something in Unicode,
from left to right, in units of eight?
Perhaps it might spell a little message.
Feel free to take a picture if you'd like to do that homework later.
But indeed, we can represent more than just numbers and letters.
We can do a similar mapping between the zeros and ones and things
like colors, as well.
Things like music.
And from there we can get images, and we can get videos.
We all just have to agree on some convention
for maintaining those associations there.
So even these things, too, which we're all too fond, perhaps,
of sending nowadays in texts or emails.
Even these emoji, too.
This and hundreds of others are just patterns of zeros and ones
that Google, Apple, Microsoft, and all of us
have sort of agreed in just using computers today
to use the same pattern of zeros and ones on one device and on another.
But that, of course, is just the left and the right of this picture.
How we might represent inputs and outputs?
We all just use binary, and we maintain those kinds of mappings
between letters and numbers and more.
Let's take a look inside this black box and consider
what it means to actually solve a problem in computing without even
touching a keyboard or code.
These things known as algorithms-- step-by-step instructions
for solving some problem.
Now, nowadays we're all in the habit of using things
like your contacts on your iPhone or android device.
Those contacts are typically sorted alphabetically
by first name or last name.
This isn't all that different, honestly, from the technology
we used in 1995 in Matthew's Hall.
When we wanted to call someone, we used the old-school incarnation
of this-- a phone book.
Same idea.
Lots of names, lots of numbers, alphabetized from A through Z.
So how might a computer go about searching,
via auto-complete or something like that, or how might a human back
in the day go about searching the same technology,
if you're looking for someone like Ron in the phone book,
assuming we're searching by just first names?
Well, we could go to the first page here and just
start looking one page at a time from left to right.
Is this Ron?
Is this algorithm, step-by-step, correct?
Will I find Ron if he's in this phone book starting at the beginning going,
yeah, one page at a time.
It's kind of stupidly slow because he's obviously
going to be farther down in the phone book, but I'll find him eventually.
Well, what about a different algorithm?
Two pages at a time.
So 2, 4, 6-- a little harder to do on the fly,
but 2, 4, 6, 8, 10, 12, 14, 16, 18, and so forth.
Is that algorithm correct, looking for Ron two pages at a time?
I'm seeing no.
Why?
Yeah, I might skip Ron because he sort of accidentally
gets sandwiched between two of those pages.
Now, I don't have to throw out the whole algorithm.
I can still fly through the phone book twice as fast,
and maybe I should just double back one if I go a little too far in the phone
book.
So it's recoverable.
But generally, what I would do back in the day,
and what your iPhone and Android phone and Mac and PC are doing,
is they're generally just going roughly to the middle of that long list
of names, or this many pages.
And you might look down and see, oh, I'm in the M section,
so that's far too early in the phone book.
So Ron's got to be this way.
And the problem can then be divided and conquered, so to speak.
And we can do this all too dramatically here,
taking the phone book the easy way, down this way--
taking the phone book, tearing it in half,
and leaving us with a problem that's not like 1,000 pages
now, but maybe 500 instead.
And now I go here.
I went to the T section, so I went a little too far.
So I can again divide the problem in half, throw half of it
away, leaving me with, what?
Like 250 pages, then 125, then 67, give or take.
And there's some rounding issues that, to be fair, we'll have to sort out.
But so long as we handle rounding, eventually we'll
find ourselves with Ron on or just not on this page at all.
Now of course, we can only do this once.
But that's what's known as binary search, "bi" again meaning two.
And dividing and conquering more familiarly,
whereby we're just dividing the problem in half and half and half,
and solving it so much more quickly.
How quickly?
Well, if it was 1,000 pages to begin with,
that first algorithm might have taken me like 1,000 steps.
Slow to find Ron, or Zacharias way at the end of the phone book.
Second algorithm, maybe 500 steps because I'm going two at a time.
But the third algorithm?
How many times can you tear a phone book in half if it's roughly 1,000 pages?
Some quick math?
So it's roughly 10 times.
Only 10 times.
And that's down from 500 in just that second case.
And so what you learn to leverage in computer science is ideas like this.
If we plot this very simply--
vertical axis here is the amount of time to solve a problem.
Horizontal axis here is the size of the problem.
So, few pages there, many pages there.
The first algorithm is a straight line because there's
a one-to-one relationship between how many times you turn the page.
Second algorithm is still a straight line.
But its slope, if there's n pages, would be n divided by 2 instead,
because you can do two pages at a time instead of one.
But the third algorithm, and where we spend
our time in our course on computer science, is how do you write code?
How do you solve problems such that the curve looks like this?
Logarithmic, if you recall the phrase.
But it's a fundamentally different shape.
And it means that the time involved to solve your problem
grows so much more slowly than those other algorithms instead.
Now besides these ideas, which we then in a class like CS50,
and computer science more generally, use to start
solving real world problems and data by writing code and other mechanisms--
CS50 itself is very much a community with traditions,
whereby we start the semester with CS50 Puzzle Day, an opportunity
to get together without needing any CS background
and solve some interesting puzzles collaboratively with friends.
Lunches every Friday to make a big class otherwise feel small.
A CS50 Hackathon from 7:00 PM to 7:00 AM,
in healthy times at the end of the semester-- an opportunity to create
your very own final project.
And then a CS50 Fair, campus-wide exhibition
of all students' final projects.
And these are all traditions that unfortunately
have been on hold for quite some time.
But we thought we would paint a picture here in closing of a two-minute video
that the team put together that first, tells the tale of what times were
like just in Fall 2020 not too long ago on Zoom, to Fall 2021,
whereby we were all here together, but masked
and not quite gathering in the same frequency as we might otherwise do.
But now, ultimately this year do we hope we'll
see a much more normal, much more traditional fall, to which you are all
cordially invited.
So this, then, was just a taste of the Intellectual Enterprises of Computer
Science and the Art of Programming.
And this is CS50.
[APPLAUSE]
[INSPIRATIONAL MUSIC]
[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 glow-owing.
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 turn.
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.
Come back Sunday morning.