top of page

Harvard's CS50x Week 0: A Journey into Computational Thinking

When I enrolled in Harvard’s CS50x, I expected to learn computer programming.


Surely, I thought, this would be just another run-of-the-mill coding course – a quick one-and-done on Python or HTML.




The truth of the matter is, CS50x offers a great deal more, and, as far as I’m concerned, is deserving of all of the accolades it receives.


Harvard’s “introduction to the intellectual enterprises of computer science” places an emphasis on problem-solving and computational thinking that can be applied beyond the narrow sphere of computer science and into the real world.


This guide will be split into two parts: my personal, simplified notes and observations on the course content (which I hope to revisit in the future), and my experiences with the introductory problem set.


Lecture Notes:


If you’re new to programming, the title “Week 0” may have struck you as odd – but in the realm of programming, starting with 0 is actually the convention.


It is these subtleties, coupled with Professor Malan’s lecturing capabilities, that make CS50 so enthralling.


Let’s break down Week 0.


Computational Thinking & Number Systems


Computer programming revolves around the idea of taking input, processing it through the enigmatic black box, and creating some output.




Computer systems represent input and output in ways similar to that which we humans do – number systems.


While we use the decimal system, one digit to one finger, computers use the binary system. Their figurative “fingers”, or bits, are electrical signals: 0 represents false without an electrical signal, and 1 represents true with an electrical signal.


Binary provides an elegant way of representing large amounts of information.


  • Unary representation of 1 through 3: 1, 11, 111.

  • Binary representation of 1 through 3: 01, 10, 11.


Where unary takes three “slots”, binary requires only two to display the same information.


The number of possible combinations in binary is 2^n, where n is the number of “slots”. We can “decrypt” binary into decimal by adding the product of the values in each “slot” and 2^n.


For instance, 11001 can be rewritten as 1*2^0 + 0*2^1 + 0*2^2 + 1*2^3 + 1*2^4 = 25.

ASCII, RGB, & Unicode


Now that we’ve established how computers represent numbers, a question arises: how can we represent letters and images?


Professor Malan explains that through codification, bits (0’s and 1’s) can be arranged to represent numbers, letters, images, and audio.


Some humans, many years ago, collectively agreed on the three chief codification systems viewed as standard today: ASCII, RGB, and Unicode.


ASCII maps every letter and character to a specific binary value, ranging from 0 to 127 (in decimal).


For instance, “H I !” can be mapped to 72, 73, and 33, respectively.


Unicode in the Realm of Computer Representation: Bridging the Gap


Unicode is like the expanded form of ASCII, representing letters and characters along with emojis.


So why not add new values to ASCII? Why create an entirely separate system?


When ASCII was conceived, its creators did not anticipate any new characters.


The sheer number of combinations using 8 binary bits, the amount ASCII uses, was simply not enough to represent all of these new characters.


Thus, Unicode adopted a 16-bit encoding form.


RGB and the Context of Color Representation: A Threefold Combination


RGB, or red, green, blue, is a combination of three numbers that generates a respective color.


Wait a minute – the ASCII sequence representing “H I !” is also composed of three numbers.


So how does the computer differentiate between the two?


It boils down to context. The computer reads and interprets ASCII, Unicode, and RGB values differently depending on how they are implemented in your code.


Now let’s increase the scale: think of images as a dense collection of RGB pixels, and videos as sequences of these images.


Algorithms: Decoding the 'How' in Computer Science


As of yet, we’ve covered the what, or “input” and “output”, leaving us with the 'how' of computer science.


That’s where the “black box” – or more technically, algorithms – comes in. Think of algorithms as step-by-step instructions for solving a problem.


Professor Malan visualizes this concept with… a phonebook? The “problem” in question is finding the name “John Harvard” buried within the pages of the book.


Of course, you could always start at page one and continue flipping until you find the name, but as the length of the book increases, so does the number of steps.


Okay, so maybe we can improve efficiency by flipping two pages at once and doubling back if we’ve gone too far, but even this method is flawed when the phonebook grows too large.


How about cutting this bigger problem into smaller ones – that is to say, we rip the phonebook through the middle and determine where the name appears alphabetically, continuing this process until just one page remains.


Now the problem at hand is exponentially simpler – instead of relying on a linear model of steps, cutting the problem in half each time has resulted in a logarithmic one.


While some approaches proved more efficient than others in locating the desired name, each of them can be called algorithms.


Computer scientists measure the speed, or time complexity, of algorithms using what is called Big-O-Notation.




Understanding Big-O Notation and Pseudocode: The Key to Algorithmic Efficiency


Note that Big-O Notation truly describes the upper bound of an algorithm’s runtime, signifying the amount of time as the size of the problem tends to infinity.


Thus, we can regard both n and n/2 as O(n) (read as big-O of n), as they will take relatively similar amounts of time to execute when the problem grows infinitely large.


Pseudocode: Bridging Ideas to Code with Clarity


With a basic conceptual understanding of a problem’s inner workings – input, output, and algorithms – how can we begin to carry out these ideas?


Pseudocode is the stepping stone that bridges ideas and actual code, or in other words, a simple visual representation of an algorithm.


It is written in a human-readable form (English for most), eliminating all cryptic syntax, and can be applied to any programming language.


Pseudocode allows you to think through the logic of your algorithm before carrying out the formal code. Let’s write pseudocode for our phonebook scenario:


1  Pick up phone book

2  Open to the middle of the phone book

3  Look at the page

4  If the person is on the page

5  Call the person

6  Else if the person is earlier in the book

7  Open to the middle of the left half of the book

8  Go back to line 3

9  Else if the person is later in the book

10  Open to the middle of the right half of the book

11 Go back to line 3

12  Else

13  Quit


It’s worth noting that:


  • Lines that begin with verbs are called functions

  • Lines containing “if” and “else” statements are called conditionals

  • Lines containing expressions that can evaluate to true or false are called boolean expressions

  • Lines that result in repeating previous lines are called loops


Problem Set 0: Scratch


This week’s problem set was fairly straightforward: design a game or animation of your choosing within Scratch.


What struck me, though, was the vagueness of the assignment – where was I to start? What if my project was not up to standard?


However, once I got to work and creativity took the mental wheel, I never once gave it a second thought.


In retrospect, this open-endedness was what really gave me the opportunity to explore all of Scratch’s features, building up strong foundations in the basics of programming that would aid me in the coming weeks.


My Wizarding-World-inspired Scratch game took nearly 7 hours to complete.


At first, I was hoping to create something fairly simple but ended up with a much more elaborate product than I had envisioned.


The game itself includes audio features, various characters and costumes, and many, many blocks of code.



If you’re interested in playing, click here!

Final Thoughts: Igniting the Spark for Computer Science


Malan’s captivating teaching style, combined with Week 0’s information-rich lecture, rekindled my passion for computer science, leaving me yearning for more.


If you’re new to programming or eager to embark on this journey, give CS50x a chance – like most things, learning computer science gets easier with time.


For now, this concludes Week 0!


See you soon! Meanwhile, stay tuned for updates by following my blog and LinkedIn page.


Note: this article has images and code belonging to CS50. You are free to you remix, transform, or build upon materials obtained from this article. For further information, please check CS50x’s license.

Comments


bottom of page