Algorithm for distinguishing polyphyly from paraphyly

For a project that involves large trees as produced by BOLD I've had to come up with a way to assess whether species are monophyletic, paraphyletic or polyphyletic. Or, perhaps more accurately, whether all species in the tree had undergone complete lineage sorting for the COI locus, and if not, what other species they are tangled up with. Monophyly is easy enough, you just walk the tree and check that for each set of tips that is somehow lumped together there is only one MRCA. I had a harder time distinguishing para and poly, perhaps because I think (probably wrongly) that they are kinda the same depending on how you trace the lineages over the tree. So here is what I came up with.