HarvardX CS50 - Week 3

CS50 is a first year university course offered by Harvard University and more recently, Yale University, which dives into the basics of computer science, exploring algorithmic thinking and teaching students how to code in a variety of languages including Scratch, C, and Python, amongst others. In the last few weeks of the course, it offers a choice of three tracks - game, web, or mobile development that students can explore and create their final project which is encouraged to be something which is useful beyond the course.

The online course which is known as CS50x offers a stripped down experience of the real course. The assignments, known as problem sets (or psets), are marked against certain criteria and a number of test cases by an automated program. All of your coursework is pushed into individual branches of your own CS50 GitHub repository. I've copied these branches into a single repository for ease of perusal, which can be found here.

Week 3

Week 3 took me a lot longer than a week to complete and I didn't complete all the problems this time because for the first time, I was completely lost on what it wanted me to do.

Problem set 3 tackled various kinds of voting system algorithms. For the first time the course provided the bulk of the code and I was required to write the functions to implement the logic of the program.

The first problem I was presented with was a basic Plurality voting system. Essentially, this system allowed each person one vote and the person with the most votes won. Given the simplicity of this voting system, it lacked the amount of complexity present in the later problems which I was unprepared for. That said, I did actually find this one fairly easy.

Plurality in Action (with two winners)

The second problem was a Runoff type election which was a simple preferential voting system. For simplicity, this Wikipedia article describes how Runoff voting works. Simply put, candidates are eliminated when they're at the bottom of the ballot. This problem was pretty hard as I didn't write the code that called the functions, so there were lots of idiosyncracies of how the CS50 creators had put this together. I also ran into this in the Plurality exercise, I particularly had issues correlating the indices of the arrays to the candidates and so forth.

Runoff in Action

I did not complete the More Comfortable problem this week (known as Tideman) as I couldn't wrap my head around the logic required. This is part of the reason this week took me longer than usual as well. That said, I'm glad I moved on because the week 4 lecture has helped me grasp things I hadn't previously understood. I am keen to try out the week 4 problems. Spoiler: They're related to image processing.