Tuesday, January 10, 2012

Interview Question: Pascal's Triangle

I found it interesting since I had been presented with this same problem during a technical interview. At the time, I solved it but not in a efficient way. Afterwards, I worked through it for myself and came up with a version similar to the dynamic approach on his blog.

On the blog, the code for the dynamic solution is incorrect. (N.B. I've changed the range from 20 to 300.)

This works for very small values like the 300 in the example. It will, however, not scale because it is so memory intensive. Look at the later entry on profiling where the sample is 10,000 rows.

I tried running your code on a machine with 8GB of memory with a value of 10,000 and in less than 1 minute all of the memory was committed. The swap space was quickly used up and the machine started thrashing to try to accommodate the size of the dictionary. I let it run for two hours and since it had not finished, I killed the process.

About Me

Principal in Sirguey-Hancock, Ltd., a software engineering consultancy. Co-manager of the New York City Google Developer's Group, co-organizer of New York City Python, member of the national Pycon organizing committee, and teacher of Google technologies for the Google Ventures / Startup Weekend joint venture.

At last count, I had learned 18 programming languages, but I have worked primarily in C, C++, Java, and Python. Nowadays, most of my work is in Python and C with Go making a strong case for itself.

Current interests: large scale concurrency/parallelism and big data. An obsession with performance and scaling.