If you blog it they will come?

Saturday, February 21, 2009

Dynamic Programming

Dynamic programming is one of the more interesting Computer Science techniques I've learned in my time as an undergrad. And I can't believe I almost received my diploma without really knowing what it means.

An Algorithms course isn't required to graduate, and I didn't realize at first exposure to the term that dynamic programming has nothing to do with writing code or dynamic languages. It's an optimization technique to simplify problems which could otherwise blow up exponentially.

It applies to nearly ever other subject I've held interest in, such as computer vision (with convolutions) or graphics (culling) or optimization in game theory. Never mind that Algorithms has crucial implications for other topics such as Networks, Databases, AI...every computer science topic is some goal-oriented application of specific algorithms. But before I digress....

Formally learning dynamic programming and its technique of solving subproblems with memoization has only increased my interest in the technique:

Until now, we've focused on greedy and recurrent algorithms in this algorithms course. Although we began by defining an efficient algorithm as any that ran in polynomial time, until this point the aim was to achieve O(n) or O(n logn) at worst, and rarely O(n^2) solutions as acceptable.

With dynamic programming we are not nearly as optimistic. The problems have constraints or conditions which render prior techniques as overly simplistic and ineffective. We creatively combine both greedy and and recurrent techniques and use swaths of storage space in hopes of achieving polynomial runtime, meaning that O(n^3) or O(n^4) is not only acceptable--sometimes it's the best we can hope for.

Despite the pessimism, dynamic programming drastically reins in very difficult problems and occasionally leads to slick O(n) solutions for problems which may otherwise run as O(2^n). It's now one of the most sophisticated, versatile tools I have in my belt--I only wish I knew it before taking several other courses.

So back to ranting, on my disbelief that the algorithms course is not required to graduate from the department. I realize it's a difficult time-consuming proof-based (everyone hates proofs, although I hate them a little less finally) course that must compete with other "essential" courses in a limited schedule space. But the thought that I nearly graduated without taking this course is scary given how fundamental it is to everything other course and topic in computer science.

True, I may never prove anything about the runtime to an algorithm I invent in The Real World. But any amount of formal reasoning is far more valuable than being "pretty sure" the solution works. Not to mention using solved problems as templates for real world stuff, or just making positive impressions at job interviews. I'm glad I'm taking algorithms now, especially since I can't travel back in time and take it any sooner.

No comments: