Why I Love Computer Science;Too Many Reasons to Count.
Here’s to many more long hours of coding through the night, and sometimes beyond. Cheers!
By Bonnie Pan, Brown University
I’ve given you a list of 10 random names, and I’ve asked you to put them in alphabetical order. You take about a minute to rearrange them, and return the new list to me. “Good work,” I might say. “Now do it with a thousand more names.”
Does this seem a daunting task? Not for a computer science major! With the help of a few lines of code, this normally tiresome work becomes as simple as a click of your mouse. How is this possible? I’m going to assume that you, as a reader, have not had any exposure to the magic that is computer science, and attempt to explain one of the possible algorithms you might learn in an introductory course.
Bubble Sorting: An Example
Here is a group of numbers that I want to sort:
I’m going to look at pairs of numbers in this set. So first, I look at the first pair: 24. I check to see if 2 is smaller than 4—it is. Thus, it stays in place, and my set is unchanged.
Now, I move on to the next pair: 43. 3 is smaller than 4, so we switch these elements to get the next group:
We go on to the next index and look at 41. 1 is smaller than 4, so we switch these elements as well to get:
4 is smaller than 5, so no change occurs. Now that we have reached the end of the line, we do it again, starting from the first two digits.
2 is smaller than 3, no switch occurs.
3 is bigger than 1, switch it out.
This is the correct order—no change.
This is the correct order—no change. We start over from the beginning because we have reached the end of the line.
1 is smaller than 2, switch it out.
Going through the rest of the group, we see that no switches will be made, and thus, our set has been sorted!
What we have just done is called bubble sort. It is one of many methods of sorting a set of objects. What I find amazing and fun about computer science is that finishing a task, maybe as simple as sorting a list of numbers, can be encapsulated in a simple set of instructions—go through the list and switch out numbers that are in an incorrect order. This is a lot of what computer science is about—finding patterns, or algorithms, that can be repeated to manipulate a set of data. And this is only one of the many possible ways to do a task like this! There’s also merge sort, and quicksort, insertion sort, selection sort…etc. Each has its pros and cons, and it’s up to the programmer to determine which method he should use in a given situation.
(I apologize if this isn’t explained clearly enough, it’s somewhat difficult to convey computer science topics to the average layperson and I am not sure I captured the concept entirely.)
Not only is computer science flexible and rewarding to learn, it is immensely practical.
Say, for instance, you want to store a vast amount of data efficiently, with ease of accessibility and minimal clutter. You’re a medical professional, and you need to save your patients’ information with certainty and integrity. Or maybe you are an insurance company, keeping track of all your clients’ assets and rates. Or, instead, you could be a large bank, with thousands of accounts opened daily, their balances changing constantly. How do you go about this? A filing system may be messy and unreliable—papers can get lost or damaged.
Here’s another problem—once you have stored this theoretically vast amount of data, how can you manipulate it? Take, for instance, a microbiologist looking at a strand of DNA. We now have the technology to sequence nearly the entire human genome, but doing so will merely give us billions of base pairs and tens of thousands of distinct genes.
In our present time, we have access to nearly unlimited information via the amazing system of networks we call the Internet. How can we sort through and select data relevant to the topics we are interested in? In the billions of hits Google may generate for a given query, how does it determine which ones you, as its user, would find most helpful?
The way to deal with all of these questions is with computer science. It would take much, much more time and more space to write about how CS can accomplish such tasks but nothing other than a computer could possibly work out these complicated mental maneuvers efficiently enough to be worth anything.
Of course, there is a dark side to computer science—it involves a lot of frustration and many, many long, caffeinated nights. Given that, I could still go on and on about how amazing—and important—computer science is. So here’s to many more long hours of coding through the night, and sometimes beyond. Cheers!