Warning: Outdated Content
This lab is from a previous version of CS 125. Click here to access the latest version.
Algorithms and MP0
This lab starts by introducing you to computer algorithms—how computers solve problems. We’ll have a lot to say about computer algorithms in the coming months. They’re the conceptual heart of computer science. And in the second half of the lab we’ll follow concept with craft and get your development environment finalized and you off and running on MP0.
1. Algorithm Concepts (50 Minutes)
Work together in groups to solve the following problems. Feel free to use a whiteboard to prepare your solution, and be ready to present it to the course staff or other groups.
1.1. Parallelism
One of the best things about computers is that there are so many of them! Google is estimated to have 2.5 million computers in its data centers around the world. So while today’s individual computers are themselves insanely fast, they can accomplish even more when you can get them to work together.
Consider the following problem that uses computers in the historical sense of the word—humans performing computation, hence computers. You have a room full of people. Each knows their own age, but can’t or won’t perform any addition. Your goal is to compute the sum of all of the ages of everyone in the room—and to do so as fast as possible.
Assume that it takes one second to ask a question 1 and get a response 2. Also make the optimistic assumption that it takes no time to add two numbers together. Then it would take you 32 seconds to compute the entire sum yourself.
But now let’s say that you have help. How long would it take:
-
a group of two people?
-
a group of four people?
-
a group of eight people?
Keep in mind that a good solution should keep all of your helpers busy, and also requires communication between your team that you need to account for.
It’s common for computer scientists to solve a smaller version of a problem and then generalize it to a larger version. (For example, I’ll build a small college-only social networking website and then expand it later.) Let’s try that here. Compute how long it would take a group of 8 people to sum 1,024 ages. Do you see a pattern emerging?
1.2. Debugging
Now return to the case where you are summing the ages of 32 people using a team of four, including yourself. Just to be safe, after computing the sum once, you rerun the calculation again—but get a different result! There must be a bug somewhere 3!
The first step in locating a bug is to always think carefully about what could be causing the problem. Come up with at least five different sources of error that may be affecting the result of your calculation.
Next, develop a foolproof procedure for identifying the cause of the problem. You want to be just as methodical in approaching how you identify the problem as you were in developing your original solution. Debugging is always frustrating. Something is going wrong and you don’t know why! But if you approach the debugging problem like a computer scientist, you can usually come up with a good debugging algorithm. And then get back to the problem you were actually trying to solve.
1.3. Testing
Fresh of the experience of debugging your system, you decide to be more proactive in the future. Debugging is reactively waiting for problems to emerge and then trying to fix them. Testing is proactively testing things to make sure they work properly. When you test the things that you build as you go, it is much less likely that you will experience complex and difficult to find problems.
Return to the sources of error that you identified above. For each, develop a testing procedure that will ensure that you can identify the problem before it happens.
Note that while it may be tempting to try to test your system by ensuring that it can correctly compute sums for all possible inputs, this is unlikely to be feasible. Even if all 32 people are children and ten years old or younger, the space of possible inputs grows extremely quickly.
2. MP0 (60 Minutes)
Now let’s walk through the process of obtaining, developing, and submitting MP0. It’s due in less than a weeks, so we want you to get comfortable with this process right away. We won’t always devote this much lab time to an MP, but it seems appropriate for MP0.
To complete this part of lab, read through and follow the MP0 instructions. Don’t leave your lab section until you have successfully submitted MP0 and earned a few points. There are a few simple things to change that can boost your score quickly and help you get practice with the MP development workflow. If you finish early, find someone who hasn’t finished and help them out.
3. Before You Leave
Don’t leave lab until:
-
You’ve completed the algorithm-based activities above
-
You have gone through our Git and GitHub tutorial
-
You have obtained a copy of MP0…
-
…and made your first submission
-
…and earned a few points
-
… and so has everyone else in your lab section!