Between CS.SE, P.SE, and SO the scope of each overlaps and depends significantly on what type of answer the person asking wants get.
First off as a starter, read:
I'll also point to a recent example - Searching integer sequences - this question would be perfectly suitable on either (or both?) P.SE and CS.SE.
Judging by the words in the question, it is a very non-trivial problem. A question that asks about an algorithm could show up on any of the sites and be appropriate. A slight tweak to the question ('i am having a doubt about the c i wrote') and it would rapidly get pushed to Stack Overflow.
Furthermore, realize that the scope of a site, while it has inertia to it also does have some variability over time. The scope of a site may get more strict (to the point where TCS is) or it may loosen up over time (do you accept homework problems?) This is very evident when looking at the history of questions on P.SE to see what was acceptable a year or two ago and what it is now.
Furthermore, judging by the migration stats and the failure - most times, it is asked on the right site or isn't appropriate anywhere. For example, 2 posts from CS where migrated to P.SE in the last and one of them was rejected. 7 posts were migrated from P.SE to CS.SE and one of them was rejected.
If humans can't get get it right, do you think a program could?
If you really want to take a crack at it - go grab the Stack Exchange data dump http://data.stackexchange.com/help and see if you can identify questions that would get migrated (or closed). The 'or closed' bit was the topic of a machine learning contest - though I don't think it was accurate enough to merit inclusion... or something. Are there any robot moderators on SO?
From Automatic/Central Question Sorting on MSO which asked
I've noticed the Stack Exchange has grown immensely since its inception as Stack Overflow. As a result, I find asking questions in the right place here unnecessarily challenging. I'm wondering if you have thought about implementing a feature on the Stack Exchange central site where people ask the question there and either the scripts or staff/community members would sort the question to the right place.
Not sure if this would be too challenging or costly to implement. Just a thought to save your time while making users' lives easier.
If you're not willing to invest the small amount of time it takes to figure out where to ask your question -- the odds of your question being a good one are .. small.