DEV Community

Ivy Chen
Ivy Chen

Posted on

CS50 Week 3 - Algorithms and runoff

I decided to come back to CS50 after taking a break from this core course last August (I started doing CS50's Web course instead). I remembered stopping because I got stuck on this problem set problem called runoff, which was pretty difficult at the time. Coming around in 2024, I decided to give this problem another try and familiarize myself with coding in C again.

In week 3's lecture, the professor used various demonstrations to show us the difference between a couple of algorithms, like merge sort (fast), selection sort (slow), and bubble sort. I still don't remember when you would use them but I did note down which ones are fast or slow. David also went over the concept of recursion, which I interpreted as reusing a small part of a problem that we know the answer to in other similar problems. It is an "elegant" way, but not necessarily "faster".

Then comes the pset problem runoff, which I remembered I had a hard time understanding the prompt the last time around so I could barely even get started. This time, there was an accompanying walkthrough video, which broke down the different functions we needed to finish writing for us. At a glance, a runoff election is a way of deciding who the election winner is by counting the votes of first-preference candidates while eliminating the candidate with the fewest votes. I struggled with the tabular function the most because I kept on entering an infinite loop. Then the other functions were pretty quick and self-explanatory. I finally got rid of the infinite loop with the Duck's help, among other bugs as well.

I finished the runoff problem in a little under 4 hours, which was a lot of time considering people could run a marathon with this amount of time.

If you're hesitating whether or not to take CS50, I'd say that it is a bit harder than most introductory programming courses but the quality of the lectures/problem sets is spectacular.

I'll be continuing this series and updating each week's reflection as it goes.

Top comments (0)