Sunday, July 8, 2007

Math Important for CS Majors?

Karl Fant, CEO of Theseus Research, has written a book that seeks to show that knowledge of math is not important to understanding computer science. Yikes! Many colleges have already started offering a water downed version of Computer Science (CS) called Computer Information Science (CIS) that takes it easy on the math and science and favors learning the syntax of today's popular languages. The idea is that for a wide range of business applications you dont really need an in depth knowledge of math, algorithms, compiler design, etc. That for the most part you need to know just enough VB to fake it. Is there some truth to that? Yes.

Many useful applications require little understanding of how the computer works. I was contracted to write an application that would calculate the insurance premium for a house. It was very simple. The user would enter some characteristics about the house, the program would run a calculation (the calculation was provided by the insurance company) and then it would spit out an answer. The application required no understanding of math or computer science. Or did it?

The application used a small amount of RAM, was it by accident? Knowledge of math helps to understand how much RAM each variable will take up and what the overall program foot print will be. Is that not important? Knowing a little math is crucial to efficiency. In part of the application I need to sort a list of data, the list contains about a 100000 data points. This list will grow over time as the company does more and more business. Can a sort be written without a good understanding of math, sure. Here is perhaps the simplest example of a sort
procedure bubbleSort( A : list of sortable items ) defined as:
for each i in 1 to length(A) do:
for each j in length(A) downto i + 1 do:
if A[ j ] <>then
swap( A[ j ], A[ j - 1 ] )
end if
end for
end for
end procedure
The worst case time for this to execute is O(n^2), meaning worst case this could take n^2 iterations. Thats bad. On the other hand one of the fastest sort algorithms executes in O(n * log n) worst case. This is incredible faster. To illustrate the difference lets say that is takes the computer 1/100 of a second to perform on cycle. In the case of the bubble sort then we would first calculate the number of cycles: 100,000^2 = 10,000,000,000. Divide that by 100 to get seconds: 100,000,000. Then lets divide that by 3600 (the number of seconds in a hour): 27,778. So the bubble sort would take 27, 778 hours, yikes! What does this look like for the faster routine of O( n * log n). Well lets do the log firs: log 100,000 = 5 (its going to be a long day for the bubble sort). So multiply it by n and the divide by 100 for seconds: (100,000 * 5 ) / 100 = 5,000. So to get the answer in hours divide by 3600: 5,000/3,600 = 1.39 hours.

Do you thinks it more reasonable for a user to wait 1.39 hours or 27,778 hours (which is over three years)? So what is my point? You can get away without understanding the math, but there is a price to pay. Industry does seem to be leaning in the direction of CIS majors who can code but lack real analytical skills, they are banking on the ever increase in computing power. The theory is that with a powerful enough computer it doesn't matter how inefficient the code is. Remember that the next time your using an application that seems to frequently crash. The next time you surf a web page that takes minutes to display.

There is in IDE for C++ called Code Warrior, certainly appeals to us geeky coder types. I think the metaphor has taking on a new meaning. We seem to view coding staff as grunts in an army. Most IT firms try to get as many grunts on the battlefield as possible, thats how you win a war right? Gather up some warm bodies and had them a rifle ... er ... key board. Interestingly enough there is a real parallel hear. When a well trained army meets an untrained army of greater numbers the well trained army is favored.

My feeling on education for Programmers, and I give this advice to everyone who asks, is that should take as little programming as possible. Take Philosophy (esp logic), Math, Literature, Physics, Chemistry, Military History. Spend your time becoming a good analyst, some one who can take a problem a part. Learning a programming language is by far the easiest part of a good education in Computer Science. You will find that writing code is the easiest part of being a programmer. The hard part is understanding and solving the right problem. The questions is do you want to be a Code Warrior or a Code Ninja?

1 comment:

Anonymous said...

You may be dying breed, code ninja. We salute you.