Nov 27, 2008


In my last post, I talked about Amazon's stupid policy regarding price guarantees. The "something" that I bought and am loving is the Ooma system. I thought I'd write a quick product review, especially since they are on a pretty good sale right now until December 3rd (wednesday) - which is why I wanted the price guarantee.

If you would like to buy one of these, you can visit this amazon link for the ooma. Full Disclosure - there is an affiliate code in that link which makes me some pocket change to fund my amazon habit, but if you don't want to do that, just remove the "gregable-20" from the end of the URL.

Ooma is a little device which gives you a landline phone with unlimited US long distance calling for a fixed monthly rate of free (the only cost is upfront in buying the thing). The only prerequisite is a high-speed internet connection (cable, dsl, etc).

You plug your ooma into your internet line, plug your computer (or router) into the ooma, and then plug in any standard land line phone into your ooma. The phone now works, dial tone, everything. You get a phone number in the area code you choose, or can transfer your current number to it. Incoming calls ring the phone, outgoing calls come from that phone number - nothing unusual. It is VOIP, but the quality is totally fine as far as I can tell.

I was paying about $25/month for a local-only land line in my apartment. I looked closely at the bill and realized there was an additional $15/month or so of fees and taxes on top of that. So just about $40/month total. Ooma is currently $200, so I'll break even at 5 months. I find myself using my cell phone a little less too if I'm home, so I might be able to drop that down to a lower price package. The only possible risk is that ooma is a startup and they could go under leaving me without phone service. They just raised 16 million dollars about a month ago, so it seems to me that the gamble of them lasting 5 months is pretty safe.

That's the basic description, but it isn't a barebones system. Ooma is pretty well designed IMHO. I've been looking around for something like this and did my research:

  • The hardware reminds me of something apple would make - it is cool looking, easy to use, and "just works".

  • Unlike Skype, it is 100% free to use after buying equipment.

  • Unlike Skype & MagicJack, it doesn't require a computer to be left on all the time (or a computer running a specific OS).

  • Ooma sits between my internet connection and the rest of my computer network, so it can throttle down downloads or whatever when I'm taking a call, it is able to manage packet priorities so the call is never degraded by computer use.

  • Even if you do not have a separate landline service, Ooma can plug into your landline jacks and comes with the Ooma scout which communicates to the base over your house's landline jacks so that you can plug in another phone anywhere else in your home that you have another landline jack. You can buy more scouts if you want.

  • If you plug in two different phones into the base unit and the scout, you literally get two separate "lines" that you can talk on simultaneously or you can easily join them.

  • Works with 911 when you register your address with them.

Anyway, worth a thought as a cost saver and cool gadget. I am biased though, the more people who buy them the more likely mine will work longer, and yeah if you buy through my Amazon link, I get a couple bucks.

Nov 14, 2008

PQ Tree Algorithm and Consecutive Ones Problem

In grad school I ran across an cool problem and an interesting algorithm to solve it. Your input is a grid of elements, lets say rows 1, 2, 3, 4, 5 and columns A, B, C, D, E. In addition, you are given a set of "rectangles" which each consist of a subset of the grid's rows and a subset of the grid's columns. Is there a way to arrange the grid by permuting it's rows and columns such that all the rectangles are present contiguously?

Imagine a rectangle consisting of rows 2 and 5 and columns A, C, and D. The grid must be arranged such that row (2, 5) are contiguous and columns (A, C, D) are contiguous. One rectangle is trivial, multiple rectangles is a challenge. Take a look at the figure which visualizes one of these grids with embedded rectangles.

I realized the 2D problem decomposes into two separate 1D problems. The rows can be arranged without caring about the columns and vice versa. Once you reduce the problem to 1D, it turns out that it is a problem known as the Consecutive Ones Problem. If all you want to do is find an valid ordering, there is even an algorithm to solve the problem. In my case, there was rarely a perfect ordering, so I had to extend the problem to find the best ordering for some definition of best (see this paper on the subject).

The PQ Tree Algorithm

That would be the end of the boring story, except I mentioned that there was a algorithm that solved the perfect ordering problem and it was well-studied. It turned out that despite it being well studied, it is poorly known and virtually unreferenced on the internet.

The paper that explained it, Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms, came out in 1976. The paper doesn't exist anywhere on the internet, not even for purchase. No full description or implementation of the algorithm exists on the internet either.  None of this has changed in the 5 years since I looked into this algorithm - still barely any references on the web. I intend to change that today.

The algorithm is called the "PQ-Tree Algorithm". I picked up a copy of the paper in book-form from my local library. Surprisingly, the problem can be solved in linear time. It is quite an intricate algorithm. I think I recall spending 2 weeks doing nothing but implementing this algorithm.

Lets make sure that you know what the problem is first. I'll state it simpler than my above 2D problem:

Consecutive Ones Problem

Imagine that you are having a dinner party and are planning the seating arrangement. To simplify the problem, imagine your seating as a one-dimensional ordering of your guests: Sue > Fred > Tom > Rudy > Bob > ... You are trying to choose a seating arrangement that makes the most sense for your guests, and you have a number of constraints that apply to the problem. Each constraint is represented by a subset of your guests which you want to seat together (consecutively). So, if one constraint is that Sue, Fred, and Bob sit together, then there are certain permutations that are invalid and certain permutations that are valid:

Valid: Rudy > Sue > Fred > Bob > Tom
Valid: Tom > Rudy > Bob > Sue > Fred
Invalid: Tom > Bob > Rudy > Fred > Sue

Furthermore, there may be many of these types of constraints, so perhaps you have (Sue, Fred, Bob) as one constraint and another might be (Sue, Bob, Tom). One possible solution would be given as:

Tom > Sue > Bob > Fred > Rudy

This is the crux of consecutive ones problem, although the consecutive ones problem is formulated a little differently: Given a binary matrix containing only ones and zeros, reorder the columns such that the ones in every row are consecutive. The image below illustrates the point:

The matrix (a) can be transformed to the matrix (b) be rearranging only the columns in (a). The matrix (b) has the consecutive ones property (COP) in that the 1 values in each row are consecutive when read in order. The consecutive ones problem is: Given a matrix (a), determine if it can be converted into a matrix (b) by rearranging columns such that (b) has the consecutive ones property, and if so represent all valid orderings of the columns.
To see that this is the same as the guest seating problem, assign each guest to a column in matrix A. Each row represents one of the constraints we want to apply to our seating - the columns in that row containing 1's are the guests that we want to seat together.
Not all matrices can be transformed into a COP matrix. Similarly, some matrices can have many possible orderings.

My Contributions

I implemented this algorithm in grad school. My implementation then was functional but not high quality, and it was embedded in a larger library. I've spent considerable spare time here and there over the last couple months rewriting a large part of that code.

I've created a project up at github which tracks the code: PQ Tree Algorithm Implementation.The code (just a library) should be decent, bug-free, and GPL. The first internet implementation out there.

A full description of the PQ Tree algorithm can be found on knol: PQ Trees and the Consecutive Ones Property. I'd recommend checking out the algorithm knol even if just to get a high-level flavor of this interesting algorithm.

If you stumble across this page while trying desperately to do some research for your graduate program, I hope this is useful to you. I ask one small thing of you though. I spent a good bit of time putting all of this together. Drop me a comment or email letting me know how you are using it. That way I'll know it was worth the effort.

Birds of a Feather

If you are one of the handful of people interested in PQ-Trees and advanced software algorithms like this, you are the type of person I'd like to see working with me at Google.  If you send me your resume (, I can make sure it gets in front of the right recruiters and watch to make sure that it doesn't get lost in the pile that we get every day.  Update: Despite the fact that this post was published in 2008, this offer still stands today.

Nov 11, 2008

Feed Reader Recommendations: Boston Big Picture

I don't normally recommend blogs for people to check out or subscribe to. When scanning my own feed reader, most of the blogs I subscribe to are not really fit for a general audience. That said, there is one blog that I ran across that seems to be a relatively little known gem and probably matches a wide audience of interests. That blog is the Boston Globe's Big Picture Blog. Every few days they post a series of photographs on one particular "story". These are always global public interest stories, not local boston news or anything. The thing that sets it apart is the fantastic photography like this one from yesterday's post about Antartica: