In Gremlin3:
g.V(blah).out("knows").aggregate("friends").
out("knows").where(not(within("friends"))).
select().
by("name").
by(count("friends")).
order().by(valueDecr)