I realized today that the process I go through to write a new piece of code isn’t always ideal. Today I needed to get a fast version of Dijkstra’s algorithm working in Matlab. I had already written a native Matlab version which was taking a very long time to run on a very large, but sparse graph. Yesterday I started developing a C++ version which I planned to call as a mex file. I stopped when it started getting dark out (I ride my bike to work) and had to spend the rest of the night thinking of an efficient data structure to use.
Today, I started implementing my ideas, but quickly decided that I don’t have a strong enough grasp on the C++ STL to really make the algorithm fly. So, like any good programmer would do, I went to the internet and quickly found an example to follow. Actually, the example I found worked great and only needed a minor modification to run in 64-bit Windows. If I had searched for the solution first, rather than trying to implement it myself, I would have saved a lot of time. Doing the whole thing from scratch is great for learning the algorithm, but sometimes it’s good to be able to make use of existing work. I have this problem a lot, always trying to do everything myself, rather than search for a library or package that has already been optimized for me.
Whelp, time to go learn about Fibonacci heaps…