An efficient algorithm for computing the generalized null space decomposition