Implemented sorting nodes by degeneracy