September 15, 2010

Do you know algorithms?

Not so innocent question

Not to long ago, I met a computer science professor with the hopes that he will accept me as a Master student. The meeting was informal and no agenda was set. To get a feel of what I offer, he asks me a simple question.
Do you know algorithms?
Sure I know algorithms, or did I? My mind was scrambling to find a suitable example. And that is when it occurred to me that I rarely used algorithms when I code. So I began my research in this matter. Where best to begin then by looking at the definition of algorithm
In mathematics, computer science, and related subjects, an algorithm is an effective method for solving a problem expressed as a finite sequence of instructions.

Not an isolated incident

It was not the first time my brain was picked on algorithms. I was interview a few months ago by Google. I had 2 interviews and both focused on algorithms. Stevey's interview preparation article describes very well the company hiring process emphasizes on analysis a problem and provide a data structure and algorithm for it. I have a background in C++ and when I explained my solution in terms of std::list and std::vector, the interviewer was not happy with the answer. He probed me on the inner working on the std components I was using.

What do you mean "know algorithms"?

So what is it to know algorithms as a software developer? Well, it depends. It is according to the work environment you work in. I see some similarities to The project management triangle The question to choose 2 of the 3 attributes cheap, good and fast apply to this question.

  • If the project environment is cheap and fast (most projects fall in this category) then you go with the tried and true standard libraries. The brute force is used most of the time.
  • If the project is cheap and good then you still rely on the standard libraries but a in depth understanding of the algorithms used under the hood. What algorithm does the std::sort use? Or is it better to use a std::set instead?
  • If the project is good and fast then you need to reinvent the wheel. In other word customize the solution according to your needs. And that is where you prove your worth.

So the next time you are asked Do you know algorithms?, you will able to provide a better to answer him/her then I did.

Happy coding.

2 comments:

litsf said...

Isn't any sequence of steps to do something an algorithm? :) What is the real question behind theirs.

peristeri said...

It is true. Yet the word 'algorithms' is used very liberally that people implicitly assume that you know the context. Worst yet, the word is used as a label to describe a subset of its true meaning.

Example:
a. Do you know algorithms?
b. I'm familiar with sorting techniques.
a. No, that is not what mean. Have you work on any dynamic algorithms or of that sort?

I guess what I wanted to say is algorithms different things to different peoples. I wanted to look at the implementation of algorithms in the context of C++ programming.