I was very surprised to find that this question had been closed as "off topic":
It seems like a straightforward practical algorithms question, not the kind of thing that should be migrated to cstheory.stackexchange.com. Surely if a topic has a whole volume of The Art of Computer Programming devoted to it, then it's on-topic at Stack Overflow?
This isn't the first closure of a question about algorithms that I've seen recently. I wonder if there are Stack Overflow users who believe that algorithms are some kind of computer sciency thing that don't belong with practical programming problems?
The five users who closed this particular question are highly experienced (hence supposedly respected) members of the site, all with 10k+ reputation: John Saunders has 70k and mark_s 129k. So I don't think this is a mistake made by inexperienced members of the site.
I have no particular suggestion for how to solve this; I'm not sure whether this is a problem to be solved at all, or just a couple of poor closure decisions. I'm just giving a heads-up that users' ideas of what counts as on-topic for the site may be diverging. But maybe you have some ideas?
It's clear from the answers below that this is indeed a problem: there seem to be a number of users of this site who think it's inappropriate to ask questions about algorithms without reference to their implementation in a particular programming language. This seems wrong to me: for a practitioner skilled in the art, it's usually straightforward, once one has found an appropriate algorithm, to implement it in any particular language. So discussing the algorithm in a language-independent context helps to keep attention on the important algorithmic ideas, rather than the particular details of implementation.
Here's another algorithmic question that was closed, this time as "not a real question":
And here's a well-known and important programming problem closed as "off topic":