Graph sorting