CS50x Review: Part 1

Published on:
Feb. 10, 2017

Last fall, I took Harvardx’s CS50x for free through edx.org. CS50 is Harvard's “Introduction to Computer Science” course, and CS50x is a free online offering of the same material. Through edx I was able to watch every lecture, use CS50’s cloud-based code editor, and even complete, submit, and receive grades on all the same homework assignments as students in the actual classroom. For free.

Full Disclosure: I can pay $90 to receive a verified certificate of course completion. All I get for free is the knowledge.

This was a whopper of a course. In just a few months I went from getting a text window to say “Hello World” to making a database-driven fake stock exchange website that used real-time stock prices from Yahoo! finance. Needless to say, CS50 covered a lot of ground, so I’ll be splitting this review up into 3 parts.

CS50 is divided into 13 weeks. Each week’s material includes 2 lectures, several “shorts” and most weeks have a “problem set” or coding assignment. The lectures range from 45 minutes to an hour long, and the shorts average 10-15 minutes. In this post, I’ll be covering the material from weeks 0–3 (the course is 0 indexed, because computers).

Week 0: The Warm-up


Week 0 featured an introductory lecture that really set the tone for the rest of the course. The instructor, Dr. David Malan, is a very charismatic speaker and he made great use of demonstrations and visual aids to keep the lecture moving. This week covered topics including binary counting, boolean expressions, and basic programming concepts like conditional statements. To teach these concepts they used MIT’s Scratch, a graphical programming language made to introduce kids to programming concepts without scaring them away.

The real meat of week 0 (and the rest of the weeks, it turns out) was in the coding assignment. Problem set (or PSET) 0 was to make a Scratch program that allowed a user to interact with something on the screen. It wasn't graded, but I did have to submit a link to show I’d written something. Many people also submitted their Scratch programs to CS50’s Subreddit. I made a simple game where you control a wizard and have to fight a dragon.

PSET 0 had simple enough requirements, but Scratch is also deep enough that you can implement some things that are really interesting. My example uses multiple threading, loops, events, event listeners, and auto-incrementing. These are concepts I wouldn’t be able to implement in actual code for a while. In the case of multiple threading, I still can’t.

Weeks 1–2: Intro to Programming in C


Weeks 1 and 2 started to get into writing real code. The lectures covered using a Linux command line, compiling, variable typing, basic C syntax, and more. Having just completed an introductory Python book, the concepts here were familiar, but C looked like aliens decided to put some crop circles in between way too many curly braces. For example, here's “Hello World” in Python vs C.

Python:

print("Hello World")

C:

#include <stdio.h>
int main(void){
    printf("Hello World\n");
}

Obviously, there’s a lot more that goes into doing even the most simple things in C. Maybe one day I'll be the type of guy that writes tutorial blogs where I'd explain what all that stuff is, but that day is not today. Back to the review.

The PSET for week 1 involved writing four short programs. The first was “Hello World” seen above. The second, “Mario”, made use of nested loops to print a pyramid of user defined height to the terminal. The third and fourth (“Greedy” and “Water” respectively) called for user input and performed simple math that treating the user input as a variable. These were simple enough, but the concepts are important and would come back over and over.

Week 3: The Gauntlet Begins


This week the lectures, shorts, and PSET really focused on different things. Week 3 is where I started to realize just how much this course was going to cover, and how it was going to do it. The lectures went over some big computer science concepts that would come back over and over again throughout the course. Searching algorithms, sorting algorithms, and comparing algorithms for time complexity were all introduced this week.

As if searching, sorting, and time complexity weren’t enough, the shorts went in depth into different algorithms. Bubble sort, insertion sort, selection sort, and even merge sort (and by extension, recursion) were all covered. If this sounds like a lot of material to cover in one week, that’s because it was.

The PSET for week 3, and the code talk-through videos included, covered even more ground. The PSET focused to working with strings. Luckily, the concepts here were way easier to implement than the material covered in the lectures.

For the first program, “initials” I simply had to accept a name (first, middle, last) typed by the user and print their initials. In the second, “Caesar”, I had to implement Caesar's Cipher by getting a string from the user, and shifting each letter by a user-defined number of places through the alphabet. For example if the user typed in “apple 1” the output should be “bqqmf”, or each letter plus one. The third, “Vigenère”, was an implementation of Vigenère’s cipher, which is basically a slightly more complicated Caesar cipher.

Summary


The first few weeks of this class really gave me a false sense of security. I was cruising along, writing my nested loops and feeling smart, when sorting algorithms and time complexity came along and smacked me in the back of the head. It's been a while since I’d really pushed myself into new material that took this kind of work to understand. It felt pretty awesome. Each “A-Ha!” moment was really rewarding, and by Week 3 I was hooked. I couldn’t wait to see how far I could go and what kinds of problems I could solve. I’m sort of still doing that right now as I write this!

To find out where CS50 went next, check out Part 2.

To Be Continued...